@@ -72,6 +72,7 @@ use sp_transaction_pool::runtime_api::TaggedTransactionQueue;
72
72
use sp_weights:: Weight ;
73
73
use std:: assert_matches:: assert_matches;
74
74
use std:: collections:: { BTreeMap , VecDeque } ;
75
+ use std:: future:: IntoFuture ;
75
76
use std:: sync:: Arc ;
76
77
use std:: time:: Duration ;
77
78
use subspace_core_primitives:: pot:: PotOutput ;
@@ -83,8 +84,23 @@ use subspace_test_service::{
83
84
use tempfile:: TempDir ;
84
85
use tracing:: error;
85
86
87
+ /// The general timeout for test operations that could hang.
86
88
const TIMEOUT : Duration = Duration :: from_mins ( 2 ) ;
87
89
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
+
88
104
fn number_of ( consensus_node : & MockConsensusNode , block_hash : Hash ) -> u32 {
89
105
consensus_node
90
106
. client
@@ -1600,44 +1616,34 @@ async fn collected_receipts_should_be_on_the_same_branch_with_current_best_block
1600
1616
) ;
1601
1617
}
1602
1618
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.
1603
1621
#[ 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 ?;
1627
1624
1628
1625
// Run Bob (a evm domain full node)
1629
1626
let mut bob = domain_test_service:: DomainNodeBuilder :: new (
1630
- tokio_handle ,
1627
+ tokio :: runtime :: Handle :: current ( ) ,
1631
1628
BasePath :: new ( directory. path ( ) . join ( "bob" ) ) ,
1632
1629
)
1633
1630
. connect_to_domain_node ( alice. addr . clone ( ) )
1634
1631
. 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 ( ) ;
1636
1639
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
+ }
1640
1644
}
1645
+ . timeout ( )
1646
+ . await ?;
1641
1647
1642
1648
let pre_bob_free_balance = alice. free_balance ( bob. key . to_account_id ( ) ) ;
1643
1649
// 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() {
1646
1652
dest : Alice . to_account_id ( ) ,
1647
1653
value : 123 ,
1648
1654
} )
1649
- . await
1655
+ . timeout ( )
1656
+ . await ?
1650
1657
. expect ( "Failed to send extrinsic" ) ;
1651
1658
1652
1659
produce_blocks_until ! (
@@ -1659,8 +1666,11 @@ async fn test_domain_tx_propagate() {
1659
1666
} ,
1660
1667
bob
1661
1668
)
1662
- . await
1669
+ . timeout ( )
1670
+ . await ?
1663
1671
. unwrap ( ) ;
1672
+
1673
+ Ok ( ( ) )
1664
1674
}
1665
1675
1666
1676
#[ tokio:: test( flavor = "multi_thread" ) ]
0 commit comments