@@ -31,15 +31,19 @@ async fn test_state_coherence() {
3131 const N : u16 = 4 ;
3232 const TRANSMISSION_INTERVAL_MS : u64 = 10 ;
3333
34- let mut network = TestNetwork :: new ( TestNetworkConfig {
35- num_nodes : N ,
36- bft : true ,
37- connect_all : true ,
38- fire_transmissions : Some ( TRANSMISSION_INTERVAL_MS ) ,
39- // Set this to Some(0..=4) to see the logs.
40- log_level : Some ( 0 ) ,
41- log_connections : true ,
42- } ) ;
34+ let mut network = tokio:: task:: spawn_blocking ( || {
35+ TestNetwork :: new ( TestNetworkConfig {
36+ num_nodes : N ,
37+ bft : true ,
38+ connect_all : true ,
39+ fire_transmissions : Some ( TRANSMISSION_INTERVAL_MS ) ,
40+ // Set this to Some(0..=4) to see the logs.
41+ log_level : Some ( 0 ) ,
42+ log_connections : true ,
43+ } )
44+ } )
45+ . await
46+ . unwrap ( ) ;
4347
4448 network. start ( ) . await ;
4549
@@ -52,15 +56,19 @@ async fn test_resync() {
5256 // Start N nodes, connect them and start the cannons for each.
5357 const N : u16 = 4 ;
5458 const TRANSMISSION_INTERVAL_MS : u64 = 10 ;
55- let mut network = TestNetwork :: new ( TestNetworkConfig {
56- num_nodes : N ,
57- bft : true ,
58- connect_all : true ,
59- fire_transmissions : Some ( TRANSMISSION_INTERVAL_MS ) ,
60- // Set this to Some(0..=4) to see the logs.
61- log_level : Some ( 0 ) ,
62- log_connections : false ,
63- } ) ;
59+ let mut network = tokio:: task:: spawn_blocking ( || {
60+ TestNetwork :: new ( TestNetworkConfig {
61+ num_nodes : N ,
62+ bft : true ,
63+ connect_all : true ,
64+ fire_transmissions : Some ( TRANSMISSION_INTERVAL_MS ) ,
65+ // Set this to Some(0..=4) to see the logs.
66+ log_level : Some ( 0 ) ,
67+ log_connections : false ,
68+ } )
69+ } )
70+ . await
71+ . unwrap ( ) ;
6472 network. start ( ) . await ;
6573
6674 // Let the nodes advance through the rounds.
@@ -98,15 +106,19 @@ async fn test_quorum_threshold() {
98106 const N : u16 = 4 ;
99107 const TRANSMISSION_INTERVAL_MS : u64 = 10 ;
100108
101- let mut network = TestNetwork :: new ( TestNetworkConfig {
102- num_nodes : N ,
103- bft : true ,
104- connect_all : false ,
105- fire_transmissions : None ,
106- // Set this to Some(0..=4) to see the logs.
107- log_level : None ,
108- log_connections : true ,
109- } ) ;
109+ let mut network = tokio:: task:: spawn_blocking ( || {
110+ TestNetwork :: new ( TestNetworkConfig {
111+ num_nodes : N ,
112+ bft : true ,
113+ connect_all : false ,
114+ fire_transmissions : None ,
115+ // Set this to Some(0..=4) to see the logs.
116+ log_level : None ,
117+ log_connections : true ,
118+ } )
119+ } )
120+ . await
121+ . unwrap ( ) ;
110122 network. start ( ) . await ;
111123
112124 // Check each node is at round 1 (0 is genesis).
@@ -142,23 +154,32 @@ async fn test_quorum_threshold() {
142154
143155 // Check the nodes reach quorum and advance through the rounds.
144156 const TARGET_ROUND : u64 = 4 ;
145- deadline ! ( Duration :: from_secs( 20 ) , move || { network. is_round_reached( TARGET_ROUND ) } ) ;
157+ let net = network. clone ( ) ;
158+ deadline ! ( Duration :: from_secs( 20 ) , move || { net. is_round_reached( TARGET_ROUND ) } ) ;
159+
160+ tokio:: task:: spawn_blocking ( move || {
161+ drop ( network) ;
162+ } ) ;
146163}
147164
148165#[ tokio:: test( flavor = "multi_thread" ) ]
149166async fn test_quorum_break ( ) {
150167 // Start N nodes, connect them and start the cannons for each.
151168 const N : u16 = 4 ;
152169 const TRANSMISSION_INTERVAL_MS : u64 = 10 ;
153- let mut network = TestNetwork :: new ( TestNetworkConfig {
154- num_nodes : N ,
155- bft : true ,
156- connect_all : true ,
157- fire_transmissions : Some ( TRANSMISSION_INTERVAL_MS ) ,
158- // Set this to Some(0..=4) to see the logs.
159- log_level : None ,
160- log_connections : true ,
161- } ) ;
170+ let mut network = tokio:: task:: spawn_blocking ( || {
171+ TestNetwork :: new ( TestNetworkConfig {
172+ num_nodes : N ,
173+ bft : true ,
174+ connect_all : true ,
175+ fire_transmissions : Some ( TRANSMISSION_INTERVAL_MS ) ,
176+ // Set this to Some(0..=4) to see the logs.
177+ log_level : None ,
178+ log_connections : true ,
179+ } )
180+ } )
181+ . await
182+ . unwrap ( ) ;
162183 network. start ( ) . await ;
163184
164185 // Check the nodes have started advancing through the rounds.
@@ -173,6 +194,10 @@ async fn test_quorum_break() {
173194
174195 // Check the nodes have stopped advancing through the rounds.
175196 assert ! ( network. is_halted( ) . await ) ;
197+
198+ tokio:: task:: spawn_blocking ( move || {
199+ drop ( network) ;
200+ } ) ;
176201}
177202
178203#[ tokio:: test( flavor = "multi_thread" ) ]
@@ -186,15 +211,19 @@ async fn test_leader_election_consistency() {
186211 // Start N nodes, connect them and start the cannons for each.
187212 const N : u16 = 4 ;
188213 const CANNON_INTERVAL_MS : u64 = 10 ;
189- let mut network = TestNetwork :: new ( TestNetworkConfig {
190- num_nodes : N ,
191- bft : true ,
192- connect_all : true ,
193- fire_transmissions : Some ( CANNON_INTERVAL_MS ) ,
194- // Set this to Some(0..=4) to see the logs.
195- log_level : None ,
196- log_connections : true ,
197- } ) ;
214+ let mut network = tokio:: task:: spawn_blocking ( || {
215+ TestNetwork :: new ( TestNetworkConfig {
216+ num_nodes : N ,
217+ bft : true ,
218+ connect_all : true ,
219+ fire_transmissions : Some ( CANNON_INTERVAL_MS ) ,
220+ // Set this to Some(0..=4) to see the logs.
221+ log_level : None ,
222+ log_connections : true ,
223+ } )
224+ } )
225+ . await
226+ . unwrap ( ) ;
198227 network. start ( ) . await ;
199228
200229 // Wait for starting round to be reached
@@ -230,6 +259,10 @@ async fn test_leader_election_consistency() {
230259 // Assert that all leaders are equal
231260 assert ! ( leaders. iter( ) . all_equal( ) ) ;
232261 }
262+
263+ tokio:: task:: spawn_blocking ( move || {
264+ drop ( network) ;
265+ } ) ;
233266}
234267
235268#[ tokio:: test( flavor = "multi_thread" ) ]
@@ -238,15 +271,19 @@ async fn test_transient_break() {
238271 // Start N nodes, connect them and start the cannons for each.
239272 const N : u16 = 4 ;
240273 const TRANSMISSION_INTERVAL_MS : u64 = 10 ;
241- let mut network = TestNetwork :: new ( TestNetworkConfig {
242- num_nodes : N ,
243- bft : true ,
244- connect_all : true ,
245- fire_transmissions : Some ( TRANSMISSION_INTERVAL_MS ) ,
246- // Set this to Some(0..=4) to see the logs.
247- log_level : Some ( 6 ) ,
248- log_connections : false ,
249- } ) ;
274+ let mut network = tokio:: task:: spawn_blocking ( || {
275+ TestNetwork :: new ( TestNetworkConfig {
276+ num_nodes : N ,
277+ bft : true ,
278+ connect_all : true ,
279+ fire_transmissions : Some ( TRANSMISSION_INTERVAL_MS ) ,
280+ // Set this to Some(0..=4) to see the logs.
281+ log_level : Some ( 6 ) ,
282+ log_connections : false ,
283+ } )
284+ } )
285+ . await
286+ . unwrap ( ) ;
250287 network. start ( ) . await ;
251288
252289 // Check the nodes have started advancing through the rounds.
0 commit comments