Skip to content

Commit 68a93bf

Browse files
committed
tests: adjust more BFT tests
Signed-off-by: ljedrz <[email protected]>
1 parent bcce307 commit 68a93bf

File tree

4 files changed

+174
-96
lines changed

4 files changed

+174
-96
lines changed

node/bft/src/sync/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,7 @@ mod tests {
10441044
// Create a genesis block with a seeded RNG to reproduce the same genesis private keys.
10451045
let seed: u64 = rng.r#gen();
10461046
let vm = VM::from(store).unwrap();
1047-
let genesis_pk = account.private_key().clone();
1047+
let genesis_pk = *account.private_key();
10481048
let genesis = spawn_blocking!(vm.genesis_beacon(&genesis_pk, &mut TestRng::from_seed(seed))).unwrap();
10491049

10501050
// Extract the private keys from the genesis committee by using the same RNG to sample private keys.
@@ -1287,7 +1287,7 @@ mod tests {
12871287
// Create a genesis block with a seeded RNG to reproduce the same genesis private keys.
12881288
let seed: u64 = rng.r#gen();
12891289
let vm = VM::from(store).unwrap();
1290-
let genesis_pk = account.private_key().clone();
1290+
let genesis_pk = *account.private_key();
12911291
let genesis = spawn_blocking!(vm.genesis_beacon(&genesis_pk, &mut TestRng::from_seed(seed))).unwrap();
12921292

12931293
// Extract the private keys from the genesis committee by using the same RNG to sample private keys.

node/bft/tests/bft_e2e.rs

Lines changed: 92 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -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")]
149166
async 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.

node/bft/tests/components/worker.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@ async fn test_resend_transmission_request() {
3636
// Initialize the accounts and the committee.
3737
let (accounts, committee) = new_test_committee(num_nodes, &mut rng);
3838
// Sample a ledger.
39-
let ledger = sample_ledger(&accounts, &committee, &mut rng);
39+
let accounts_ = accounts.clone();
40+
let committee_ = committee.clone();
41+
let ledger = tokio::task::spawn_blocking(move || {
42+
sample_ledger(&accounts_, &committee_, &mut rng)
43+
}).await.unwrap();
4044
// Sample a worker.
4145
let worker = sample_worker(0, accounts[0].clone(), ledger.clone());
4246

@@ -106,6 +110,8 @@ async fn test_resend_transmission_request() {
106110
// Ensure the number of sent requests is correct.
107111
assert_eq!(pending.num_sent_requests(transmission_id), (1 + i).min(max_redundancy), "Incorrect number of sent requests for transmission");
108112
}
113+
114+
tokio::task::spawn_blocking(move || { drop(ledger); });
109115
}
110116

111117
#[tokio::test]
@@ -118,7 +124,11 @@ async fn test_flood_transmission_requests() {
118124
// Initialize the accounts and the committee.
119125
let (accounts, committee) = new_test_committee(num_nodes, &mut rng);
120126
// Sample a ledger.
121-
let ledger = sample_ledger(&accounts, &committee, &mut rng);
127+
let accounts_ = accounts.clone();
128+
let committee_ = committee.clone();
129+
let ledger = tokio::task::spawn_blocking(move || {
130+
sample_ledger(&accounts_, &committee_, &mut rng)
131+
}).await.unwrap();
122132
// Sample a worker.
123133
let worker = sample_worker(0, accounts[0].clone(), ledger.clone());
124134

@@ -193,4 +203,6 @@ async fn test_flood_transmission_requests() {
193203
// Ensure the number of sent requests is correct.
194204
assert_eq!(pending.num_sent_requests(transmission_id), max_redundancy, "Incorrect number of sent requests for transmission");
195205
}
206+
207+
tokio::task::spawn_blocking(move || { drop(ledger); });
196208
}

0 commit comments

Comments
 (0)