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