@@ -1870,7 +1870,7 @@ mod tests {
18701870 // Set up test nodes
18711871 let ( ( node_1, node_2) , clients) = setup_test_nodes ( ) ;
18721872
1873- // Define an activity that would make many payments (but we will shut down early)
1873+ // Define an activity that would make payments (but we will shut down early)
18741874 let activity_definition = crate :: ActivityDefinition {
18751875 source : node_1,
18761876 destination : node_2,
@@ -1924,11 +1924,88 @@ mod tests {
19241924 elapsed
19251925 ) ;
19261926
1927- // We expect fewer than the total 100 payments to be attempted
1927+ // We expect fewer than the total 10 payments to be attempted
19281928 let total_payments = simulation. get_total_payments ( ) . await ;
19291929 assert ! (
19301930 total_payments > 0 && total_payments < 10 ,
1931- "Expected between 1 and 99 payments to be attempted, got {}" ,
1931+ "Expected between 1 and 9 payments to be attempted, got {}" ,
1932+ total_payments
1933+ ) ;
1934+ }
1935+
1936+ #[ tokio:: test]
1937+ async fn test_shutdown_on_error ( ) {
1938+ // Set up test nodes with one that will produce a permanent error
1939+ let ( ( node_1, node_2) , mut clients) = setup_test_nodes ( ) ;
1940+ let mut mock_node_1 = MockLightningNode :: new ( ) ;
1941+
1942+ // Set up node 1 expectations
1943+ let node_1_clone = node_1. clone ( ) ;
1944+ mock_node_1. expect_get_info ( ) . return_const ( node_1. clone ( ) ) ;
1945+ mock_node_1
1946+ . expect_get_network ( )
1947+ . returning ( || Ok ( Network :: Regtest ) ) ;
1948+ mock_node_1
1949+ . expect_list_channels ( )
1950+ . returning ( || Ok ( vec ! [ 100_000 ] ) ) ;
1951+ mock_node_1
1952+ . expect_get_node_info ( )
1953+ . returning ( move |_| Ok ( node_1_clone. clone ( ) ) ) ;
1954+ mock_node_1. expect_track_payment ( ) . returning ( |_, _| {
1955+ Ok ( crate :: PaymentResult {
1956+ htlc_count : 1 ,
1957+ payment_outcome : crate :: PaymentOutcome :: Success ,
1958+ } )
1959+ } ) ;
1960+ mock_node_1. expect_send_payment ( ) . returning ( |_, _| {
1961+ Err ( LightningError :: PermanentError (
1962+ "Simulated permanent error" . to_string ( ) ,
1963+ ) )
1964+ } ) ;
1965+
1966+ clients. insert ( node_1. pubkey , Arc :: new ( Mutex :: new ( mock_node_1) ) ) ;
1967+
1968+ // Define an activity that attempts to send a payment from node_1 to node_2
1969+ let activity_definition = crate :: ActivityDefinition {
1970+ source : node_1,
1971+ destination : node_2,
1972+ start_secs : None , // Start immediately
1973+ count : Some ( 5 ) , // Would try multiple payments if no error occurred
1974+ interval_secs : crate :: ValueOrRange :: Value ( 1 ) , // 1 second interval
1975+ amount_msat : crate :: ValueOrRange :: Value ( 2000 ) , // 2000 msats
1976+ } ;
1977+
1978+ // Create simulation with a long timeout that we don't expect to be reached
1979+ let simulation = Simulation :: new (
1980+ SimulationCfg :: new (
1981+ Some ( 30 ) , // 30 second timeout (shouldn't matter)
1982+ 1000 , // Expected payment size
1983+ 0.1 , // Activity multiplier
1984+ None , // No result writing
1985+ Some ( 42 ) , // Seed for determinism
1986+ ) ,
1987+ clients,
1988+ vec ! [ activity_definition] ,
1989+ TaskTracker :: new ( ) ,
1990+ ) ;
1991+
1992+ // Run the simulation (should be interrupted by the error)
1993+ let start = std:: time:: Instant :: now ( ) ;
1994+ let _ = simulation. run ( ) . await ;
1995+ let elapsed = start. elapsed ( ) ;
1996+
1997+ // Check that simulation ran for a short time (less than our expected 5 seconds)
1998+ assert ! (
1999+ elapsed < Duration :: from_secs( 5 ) ,
2000+ "Simulation should have shut down quickly after encountering the error, took {:?}" ,
2001+ elapsed
2002+ ) ;
2003+
2004+ // We expect no successful payments to be recorded
2005+ let total_payments = simulation. get_total_payments ( ) . await ;
2006+ assert_eq ! (
2007+ total_payments, 0 ,
2008+ "Expected no payments to be recorded, got {}" ,
19322009 total_payments
19332010 ) ;
19342011 }
0 commit comments