@@ -72,6 +72,7 @@ use sp_transaction_pool::runtime_api::TaggedTransactionQueue;
7272use sp_weights:: Weight ;
7373use std:: assert_matches:: assert_matches;
7474use std:: collections:: { BTreeMap , VecDeque } ;
75+ use std:: future:: IntoFuture ;
7576use std:: sync:: Arc ;
7677use std:: time:: Duration ;
7778use subspace_core_primitives:: pot:: PotOutput ;
@@ -83,8 +84,23 @@ use subspace_test_service::{
8384use tempfile:: TempDir ;
8485use tracing:: error;
8586
87+ /// The general timeout for test operations that could hang.
8688const TIMEOUT : Duration = Duration :: from_mins ( 2 ) ;
8789
90+ /// A trait that makes it easier to add a timeout to any future: `future.timeout().await?`.
91+ trait TestTimeout : IntoFuture {
92+ fn timeout ( self ) -> tokio:: time:: Timeout < Self :: IntoFuture > ;
93+ }
94+
95+ impl < F > TestTimeout for F
96+ where
97+ F : IntoFuture ,
98+ {
99+ fn timeout ( self ) -> tokio:: time:: Timeout < Self :: IntoFuture > {
100+ tokio:: time:: timeout ( TIMEOUT , self )
101+ }
102+ }
103+
88104fn number_of ( consensus_node : & MockConsensusNode , block_hash : Hash ) -> u32 {
89105 consensus_node
90106 . client
@@ -1600,44 +1616,34 @@ async fn collected_receipts_should_be_on_the_same_branch_with_current_best_block
16001616 ) ;
16011617}
16021618
1619+ // This test hangs occasionally, but we don't know which step hangs.
1620+ // TODO: when the test is fixed, decide if we want to remove the timeouts.
16031621#[ tokio:: test( flavor = "multi_thread" ) ]
1604- async fn test_domain_tx_propagate ( ) {
1605- let directory = TempDir :: new ( ) . expect ( "Must be able to create temporary directory" ) ;
1606-
1607- let mut builder = sc_cli:: LoggerBuilder :: new ( "" ) ;
1608- builder. with_colors ( false ) ;
1609- let _ = builder. init ( ) ;
1610-
1611- let tokio_handle = tokio:: runtime:: Handle :: current ( ) ;
1612-
1613- // Start Ferdie
1614- let mut ferdie = MockConsensusNode :: run (
1615- tokio_handle. clone ( ) ,
1616- Ferdie ,
1617- BasePath :: new ( directory. path ( ) . join ( "ferdie" ) ) ,
1618- ) ;
1619-
1620- // Run Alice (a evm domain authority node)
1621- let alice = domain_test_service:: DomainNodeBuilder :: new (
1622- tokio_handle. clone ( ) ,
1623- BasePath :: new ( directory. path ( ) . join ( "alice" ) ) ,
1624- )
1625- . build_evm_node ( Role :: Authority , Alice , & mut ferdie)
1626- . await ;
1622+ async fn test_domain_tx_propagate ( ) -> Result < ( ) , tokio:: time:: error:: Elapsed > {
1623+ let ( directory, mut ferdie, alice) = setup_evm_test_nodes ( Ferdie ) . timeout ( ) . await ?;
16271624
16281625 // Run Bob (a evm domain full node)
16291626 let mut bob = domain_test_service:: DomainNodeBuilder :: new (
1630- tokio_handle ,
1627+ tokio :: runtime :: Handle :: current ( ) ,
16311628 BasePath :: new ( directory. path ( ) . join ( "bob" ) ) ,
16321629 )
16331630 . connect_to_domain_node ( alice. addr . clone ( ) )
16341631 . build_evm_node ( Role :: Full , Bob , & mut ferdie)
1635- . await ;
1632+ . timeout ( )
1633+ . await ?;
1634+
1635+ produce_blocks ! ( ferdie, alice, 5 , bob)
1636+ . timeout ( )
1637+ . await ?
1638+ . unwrap ( ) ;
16361639
1637- produce_blocks ! ( ferdie, alice, 5 , bob) . await . unwrap ( ) ;
1638- while alice. sync_service . is_major_syncing ( ) || bob. sync_service . is_major_syncing ( ) {
1639- tokio:: time:: sleep ( std:: time:: Duration :: from_millis ( 100 ) ) . await ;
1640+ async {
1641+ while alice. sync_service . is_major_syncing ( ) || bob. sync_service . is_major_syncing ( ) {
1642+ tokio:: time:: sleep ( std:: time:: Duration :: from_millis ( 100 ) ) . await ;
1643+ }
16401644 }
1645+ . timeout ( )
1646+ . await ?;
16411647
16421648 let pre_bob_free_balance = alice. free_balance ( bob. key . to_account_id ( ) ) ;
16431649 // Construct and send an extrinsic to bob, as bob is not a authority node, the extrinsic has
@@ -1646,7 +1652,8 @@ async fn test_domain_tx_propagate() {
16461652 dest : Alice . to_account_id ( ) ,
16471653 value : 123 ,
16481654 } )
1649- . await
1655+ . timeout ( )
1656+ . await ?
16501657 . expect ( "Failed to send extrinsic" ) ;
16511658
16521659 produce_blocks_until ! (
@@ -1659,8 +1666,11 @@ async fn test_domain_tx_propagate() {
16591666 } ,
16601667 bob
16611668 )
1662- . await
1669+ . timeout ( )
1670+ . await ?
16631671 . unwrap ( ) ;
1672+
1673+ Ok ( ( ) )
16641674}
16651675
16661676#[ tokio:: test( flavor = "multi_thread" ) ]
0 commit comments