@@ -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 } ;
@@ -1785,4 +1785,37 @@ mod tests {
1785
1785
} else { panic ! ( "Unexpected event" ) ; }
1786
1786
if let Event :: PaymentFailed { .. } = events[ 1 ] . 0 { } else { panic ! ( "Unexpected event" ) ; }
1787
1787
}
1788
+
1789
+ #[ test]
1790
+ fn removes_stale_awaiting_invoice ( ) {
1791
+ let pending_events = Mutex :: new ( VecDeque :: new ( ) ) ;
1792
+ let outbound_payments = OutboundPayments :: new ( ) ;
1793
+ let payment_id = PaymentId ( [ 0 ; 32 ] ) ;
1794
+
1795
+ assert ! ( !outbound_payments. has_pending_payments( ) ) ;
1796
+ assert ! ( outbound_payments. add_new_awaiting_invoice( payment_id) . is_ok( ) ) ;
1797
+ assert ! ( outbound_payments. has_pending_payments( ) ) ;
1798
+
1799
+ for _ in 0 ..INVOICE_REQUEST_TIMEOUT_TICKS {
1800
+ outbound_payments. remove_stale_payments ( & pending_events) ;
1801
+ assert ! ( outbound_payments. has_pending_payments( ) ) ;
1802
+ assert ! ( pending_events. lock( ) . unwrap( ) . is_empty( ) ) ;
1803
+ }
1804
+
1805
+ outbound_payments. remove_stale_payments ( & pending_events) ;
1806
+ assert ! ( !outbound_payments. has_pending_payments( ) ) ;
1807
+ assert ! ( !pending_events. lock( ) . unwrap( ) . is_empty( ) ) ;
1808
+ assert ! (
1809
+ matches!(
1810
+ pending_events. lock( ) . unwrap( ) . pop_front( ) ,
1811
+ Some ( ( Event :: InvoiceRequestFailed { payment_id } , None ) ) if payment_id == PaymentId ( [ 0 ; 32 ] ) ,
1812
+ )
1813
+ ) ;
1814
+ assert ! ( pending_events. lock( ) . unwrap( ) . is_empty( ) ) ;
1815
+
1816
+ assert ! ( outbound_payments. add_new_awaiting_invoice( payment_id) . is_ok( ) ) ;
1817
+ assert ! ( outbound_payments. has_pending_payments( ) ) ;
1818
+
1819
+ assert ! ( outbound_payments. add_new_awaiting_invoice( payment_id) . is_err( ) ) ;
1820
+ }
1788
1821
}
0 commit comments