@@ -1579,7 +1579,7 @@ mod tests {
1579
1579
use crate :: ln:: channelmanager:: { PaymentId , RecipientOnionFields } ;
1580
1580
use crate :: ln:: features:: { ChannelFeatures , NodeFeatures } ;
1581
1581
use crate :: ln:: msgs:: { ErrorAction , LightningError } ;
1582
- use crate :: ln:: outbound_payment:: { OutboundPayments , Retry , RetryableSendFailure } ;
1582
+ use crate :: ln:: outbound_payment:: { INVOICE_REQUEST_TIMEOUT_TICKS , OutboundPayments , Retry , RetryableSendFailure } ;
1583
1583
use crate :: routing:: gossip:: NetworkGraph ;
1584
1584
use crate :: routing:: router:: { InFlightHtlcs , Path , PaymentParameters , Route , RouteHop , RouteParameters } ;
1585
1585
use crate :: sync:: { Arc , Mutex , RwLock } ;
@@ -1776,4 +1776,35 @@ mod tests {
1776
1776
} else { panic ! ( "Unexpected event" ) ; }
1777
1777
if let Event :: PaymentFailed { .. } = events[ 1 ] . 0 { } else { panic ! ( "Unexpected event" ) ; }
1778
1778
}
1779
+
1780
+ #[ test]
1781
+ fn removes_stale_awaiting_invoice ( ) {
1782
+ let pending_events = Mutex :: new ( VecDeque :: new ( ) ) ;
1783
+ let outbound_payments = OutboundPayments :: new ( ) ;
1784
+ let payment_id = PaymentId ( [ 0 ; 32 ] ) ;
1785
+
1786
+ assert ! ( !outbound_payments. has_pending_payments( ) ) ;
1787
+ assert ! ( outbound_payments. add_new_awaiting_invoice( payment_id) . is_ok( ) ) ;
1788
+ assert ! ( outbound_payments. has_pending_payments( ) ) ;
1789
+
1790
+ for _ in 0 ..INVOICE_REQUEST_TIMEOUT_TICKS {
1791
+ outbound_payments. remove_stale_payments ( & pending_events) ;
1792
+ assert ! ( outbound_payments. has_pending_payments( ) ) ;
1793
+ assert ! ( pending_events. lock( ) . unwrap( ) . is_empty( ) ) ;
1794
+ }
1795
+
1796
+ outbound_payments. remove_stale_payments ( & pending_events) ;
1797
+ assert ! ( !outbound_payments. has_pending_payments( ) ) ;
1798
+ assert ! ( !pending_events. lock( ) . unwrap( ) . is_empty( ) ) ;
1799
+ assert_eq ! (
1800
+ pending_events. lock( ) . unwrap( ) . pop_front( ) ,
1801
+ Some ( ( Event :: InvoiceRequestFailed { payment_id } , None ) ) ,
1802
+ ) ;
1803
+ assert ! ( pending_events. lock( ) . unwrap( ) . is_empty( ) ) ;
1804
+
1805
+ assert ! ( outbound_payments. add_new_awaiting_invoice( payment_id) . is_ok( ) ) ;
1806
+ assert ! ( outbound_payments. has_pending_payments( ) ) ;
1807
+
1808
+ assert ! ( outbound_payments. add_new_awaiting_invoice( payment_id) . is_err( ) ) ;
1809
+ }
1779
1810
}
0 commit comments