@@ -1592,7 +1592,7 @@ async fn track_payment_result(
15921592
15931593#[ cfg( test) ]
15941594mod tests {
1595- use crate :: clock:: SystemClock ;
1595+ use crate :: clock:: { Clock , SimulationClock , SystemClock } ;
15961596 use crate :: test_utils:: { MockLightningNode , TestNodesResult } ;
15971597 use crate :: {
15981598 get_payment_delay, test_utils, test_utils:: LightningTestNodeBuilder , LightningError ,
@@ -2031,20 +2031,20 @@ mod tests {
20312031 let ( shutdown_trigger, shutdown_listener) = triggered:: trigger ( ) ;
20322032
20332033 // Create simulation without a timeout.
2034+ let clock = Arc :: new ( SimulationClock :: new ( 10 ) . unwrap ( ) ) ;
2035+ let start = clock. now ( ) ;
20342036 let simulation = Simulation :: new (
20352037 SimulationCfg :: new ( None , 100 , 2.0 , None , None ) ,
20362038 network. get_client_hashmap ( ) ,
20372039 TaskTracker :: new ( ) ,
2038- Arc :: new ( SystemClock { } ) ,
2040+ clock . clone ( ) ,
20392041 shutdown_trigger,
20402042 shutdown_listener,
20412043 ) ;
20422044
20432045 // Run the simulation
2044- let start = std:: time:: Instant :: now ( ) ;
20452046 let _ = simulation. run ( & vec ! [ activity_1, activity_2] ) . await ;
2046- let elapsed = start. elapsed ( ) ;
2047-
2047+ let elapsed = clock. now ( ) . duration_since ( start) . unwrap ( ) ;
20482048 let expected_payment_list = vec ! [
20492049 network. nodes[ 1 ] . pubkey,
20502050 network. nodes[ 3 ] . pubkey,
@@ -2058,13 +2058,14 @@ mod tests {
20582058 network. nodes[ 3 ] . pubkey,
20592059 ] ;
20602060
2061- // Check that simulation ran 20ish seconds because
2062- // from activity_1 there are 5 payments with a wait_time of 2s -> 10s
2063- // from activity_2 there are 5 payments with a wait_time of 4s -> 20s
2064- // but the wait time is interleave between the payments.
2061+ // Check that simulation ran 20ish seconds because:
2062+ // - from activity_1 there are 5 payments with a wait_time of 2s -> 10s
2063+ // - from activity_2 there are 5 payments with a wait_time of 4s -> 20s
2064+ // - but the wait time is interleave between the payments.
2065+ // Since we're running with a sped up clock, we allow a little more leeway.
20652066 assert ! (
2066- elapsed <= Duration :: from_secs( 21 ) ,
2067- "Simulation should have run no more than 21 , took {:?}" ,
2067+ elapsed <= Duration :: from_secs( 30 ) ,
2068+ "Simulation should have run no more than 30 , took {:?}" ,
20682069 elapsed
20692070 ) ;
20702071
0 commit comments