@@ -45,11 +45,14 @@ where
4545 } ;
4646 let start = tokio:: time:: Instant :: now ( ) ;
4747 let mut delay = Duration :: from_millis ( 50 ) ;
48+ log:: info!( "waiting for condition: {condition_name}" ) ;
4849 loop {
4950 if condition ( ) . await {
51+ log:: info!( "condition met: {condition_name} after {:?}" , start. elapsed( ) ) ;
5052 return ;
5153 }
5254 if start. elapsed ( ) >= timeout {
55+ log:: warn!( "condition timed out: {condition_name} after {:?}" , start. elapsed( ) ) ;
5356 panic ! ( "Timeout waiting for condition: {condition_name}" ) ;
5457 }
5558 tokio:: time:: sleep ( delay) . await ;
@@ -312,14 +315,63 @@ pub(crate) async fn stop_ldk_node(name: &'static str, node: Arc<Node>) {
312315/// Runs a test with automatically managed TestParams lifecycle.
313316/// The test closure receives TestParams and must return it when done.
314317/// Cleanup happens automatically after the test completes.
315- pub async fn run_test < F , Fut > ( test : F )
318+ #[ track_caller]
319+ pub fn run_test < F , Fut > ( test : F ) -> impl Future < Output = ( ) >
316320where
317321 F : FnOnce ( TestParams ) -> Fut + Send + ' static ,
318322 Fut : Future < Output = ( ) > + Send + ' static ,
319323{
324+ let caller = std:: panic:: Location :: caller ( ) ;
325+ let test_name = format ! ( "{}:{}" , caller. file( ) , caller. line( ) ) ;
326+
327+ async move { run_test_with_name ( test_name, test) . await }
328+ }
329+
330+ async fn run_test_with_name < F , Fut > ( test_name : String , test : F )
331+ where
332+ F : FnOnce ( TestParams ) -> Fut + Send + ' static ,
333+ Fut : Future < Output = ( ) > + Send + ' static ,
334+ {
335+ let lifecycle_timeout = if std:: env:: var ( "CI" ) . is_ok ( ) {
336+ Duration :: from_secs ( 20 * 60 )
337+ } else {
338+ Duration :: from_secs ( 10 * 60 )
339+ } ;
340+
341+ log:: info!( "spawning test lifecycle for {test_name}" ) ;
342+
343+ let ( sender, receiver) = tokio:: sync:: oneshot:: channel ( ) ;
344+ let lifecycle_name = test_name. clone ( ) ;
345+ std:: thread:: spawn ( move || {
346+ let result = std:: panic:: catch_unwind ( std:: panic:: AssertUnwindSafe ( || {
347+ let runtime = tokio:: runtime:: Builder :: new_multi_thread ( )
348+ . enable_all ( )
349+ . build ( )
350+ . expect ( "failed to create test runtime" ) ;
351+ runtime. block_on ( run_test_inner ( lifecycle_name, test) ) ;
352+ } ) ) ;
353+ let _ = sender. send ( result) ;
354+ } ) ;
355+
356+ match tokio:: time:: timeout ( lifecycle_timeout, receiver) . await {
357+ Ok ( Ok ( Ok ( ( ) ) ) ) => { } ,
358+ Ok ( Ok ( Err ( panic) ) ) => std:: panic:: resume_unwind ( panic) ,
359+ Ok ( Err ( _) ) => panic ! ( "test lifecycle thread exited without a result" ) ,
360+ Err ( _) => panic ! ( "test lifecycle timed out after {lifecycle_timeout:?} for {test_name}" ) ,
361+ }
362+ }
363+
364+ async fn run_test_inner < F , Fut > ( test_name : String , test : F )
365+ where
366+ F : FnOnce ( TestParams ) -> Fut + Send + ' static ,
367+ Fut : Future < Output = ( ) > + Send + ' static ,
368+ {
369+ log:: info!( "test lifecycle started for {test_name}" ) ;
370+ log:: info!( "building test nodes for {test_name}" ) ;
320371 let params = build_test_nodes ( ) . await ;
321372
322- println ! ( "=== test start ===" ) ;
373+ log:: info!( "test body starting for {test_name}" ) ;
374+ println ! ( "=== test start: {test_name} ===" ) ;
323375
324376 let test_timeout = if std:: env:: var ( "CI" ) . is_ok ( ) {
325377 Duration :: from_secs ( 15 * 60 )
@@ -334,6 +386,7 @@ where
334386 let test_result = tokio:: select! {
335387 res = & mut test_task => Ok ( res) ,
336388 _ = tokio:: time:: sleep( test_timeout) => {
389+ log:: warn!( "test body timed out for {test_name} after {test_timeout:?}" ) ;
337390 test_task. abort( ) ;
338391 let _ = tokio:: time:: timeout( Duration :: from_secs( 5 ) , & mut test_task) . await ;
339392 Err ( ( ) )
@@ -342,9 +395,12 @@ where
342395
343396 // Always clean up
344397 let timeout = Duration :: from_secs ( 45 ) ;
398+ log:: info!( "test cleanup starting for {test_name}" ) ;
345399 if tokio:: time:: timeout ( timeout, params. stop ( ) ) . await . is_err ( ) {
400+ log:: warn!( "test cleanup timed out for {test_name} after {timeout:?}" ) ;
346401 eprintln ! ( "Warning: params stop timed out after {timeout:?}" ) ;
347402 }
403+ log:: info!( "test cleanup finished for {test_name}" ) ;
348404
349405 match test_result {
350406 Ok ( Ok ( ( ) ) ) => { } ,
@@ -356,11 +412,14 @@ where
356412
357413async fn build_test_nodes ( ) -> TestParams {
358414 let test_id = Uuid :: now_v7 ( ) ;
415+ log:: info!( "creating bitcoind and electrsd for {test_id}" ) ;
359416 let ( bitcoind, electrsd) = create_bitcoind ( test_id) . await ;
360417
418+ log:: info!( "creating LSP and third-party nodes for {test_id}" ) ;
361419 let lsp = create_lsp ( test_id, & bitcoind) ;
362420 let third_party = create_third_party ( test_id, & bitcoind) ;
363421 let start_bal = third_party. list_balances ( ) . total_onchain_balance_sats ;
422+ log:: info!( "funding LSP and third-party nodes for {test_id}" ) ;
364423 fund_two_nodes ( & lsp, & third_party, & bitcoind, & electrsd) . await ;
365424
366425 // wait for node to sync (needs blocking wait as we are not in async context here)
@@ -374,6 +433,7 @@ async fn build_test_nodes() -> TestParams {
374433 let lsp_listen = lsp. listening_addresses ( ) . unwrap ( ) . first ( ) . unwrap ( ) . clone ( ) ;
375434
376435 // open a channel from payer to LSP
436+ log:: info!( "opening third-party channel to LSP for {test_id}" ) ;
377437 third_party. open_channel ( lsp. node_id ( ) , lsp_listen. clone ( ) , 10_000_000 , None , None ) . unwrap ( ) ;
378438 wait_for_tx_broadcast ( & bitcoind) . await ;
379439 generate_blocks ( & bitcoind, & electrsd, 6 ) . await ;
@@ -395,6 +455,7 @@ async fn build_test_nodes() -> TestParams {
395455
396456 #[ cfg( not( feature = "_cashu-tests" ) ) ]
397457 let wallet = {
458+ log:: info!( "creating dummy trusted wallet for {test_id}" ) ;
398459 let dummy_wallet_config = DummyTrustedWalletExtraConfig {
399460 uuid : test_id,
400461 lsp : Arc :: clone ( & lsp) ,
@@ -427,6 +488,7 @@ async fn build_test_nodes() -> TestParams {
427488 #[ cfg( feature = "_cashu-tests" ) ]
428489 {
429490 let tmp = temp_dir ( ) . join ( format ! ( "orange-test-{test_id}/cashu-ldk-node" ) ) ;
491+ log:: info!( "creating Cashu trusted wallet fixtures for {test_id}" ) ;
430492 let cookie = bitcoind. params . get_cookie_values ( ) . unwrap ( ) . unwrap ( ) ;
431493 let bitcoind_port = bitcoind. params . rpc_socket . port ( ) ;
432494 let cdk_port = {
@@ -569,11 +631,15 @@ async fn build_test_nodes() -> TestParams {
569631 } ;
570632 let wallet = Arc :: new ( Wallet :: new ( wallet_config) . await . unwrap ( ) ) ;
571633
634+ log:: info!( "finished building test nodes for {test_id}" ) ;
572635 return TestParams { wallet, lsp, third_party, bitcoind, electrsd, _mint : mint } ;
573636 } ;
574637
575638 #[ cfg( not( feature = "_cashu-tests" ) ) ]
576- TestParams { wallet, lsp, third_party, bitcoind, electrsd }
639+ {
640+ log:: info!( "finished building test nodes for {test_id}" ) ;
641+ TestParams { wallet, lsp, third_party, bitcoind, electrsd }
642+ }
577643}
578644
579645pub async fn open_channel_from_lsp ( wallet : & orange_sdk:: Wallet , payer : Arc < Node > ) -> Amount {
@@ -626,12 +692,15 @@ async fn wait_for_tx_broadcast(bitcoind: &Bitcoind) {
626692 } ;
627693 let start = tokio:: time:: Instant :: now ( ) ;
628694 let mut delay = Duration :: from_millis ( 50 ) ;
695+ log:: info!( "waiting for tx broadcast" ) ;
629696 loop {
630697 let num_txs = bitcoind. client . get_mempool_info ( ) . unwrap ( ) . size ;
631698 if num_txs > 0 {
699+ log:: info!( "tx broadcast observed after {:?}" , start. elapsed( ) ) ;
632700 break ;
633701 }
634702 if start. elapsed ( ) >= timeout {
703+ log:: warn!( "tx broadcast timed out after {:?}" , start. elapsed( ) ) ;
635704 panic ! ( "Timeout waiting for tx broadcast" ) ;
636705 }
637706 tokio:: time:: sleep ( delay) . await ;
0 commit comments