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