Skip to content

Commit 2b3b0d0

Browse files
committed
chore: fix two flaky tests
Fixes: * signer::v0::locally_rejected_blocks_overriden_by_global_acceptance * signer::v0::reorg_locally_accepted_blocks_across_tenures_succeeds These tests used to depend on the `blocks_mined` counter and then immediately check a `v2/info` assertion -- this is a race condition: the stacks-node may not have processed the mined block yet. This caused test flake in CI (but usually not in local runs where machines are fast enough to never experience this condition).
1 parent f8907be commit 2b3b0d0

File tree

1 file changed

+45
-53
lines changed
  • testnet/stacks-node/src/tests/signer

1 file changed

+45
-53
lines changed

testnet/stacks-node/src/tests/signer/v0.rs

Lines changed: 45 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -4128,25 +4128,24 @@ fn locally_rejected_blocks_overriden_by_global_acceptance() {
41284128
signer_test.boot_to_epoch_3();
41294129
info!("------------------------- Test Mine Nakamoto Block N -------------------------");
41304130
let mined_blocks = signer_test.running_nodes.nakamoto_blocks_mined.clone();
4131-
let blocks_before = mined_blocks.load(Ordering::SeqCst);
41324131
let info_before = signer_test
41334132
.stacks_client
41344133
.get_peer_info()
41354134
.expect("Failed to get peer info");
4136-
let start_time = Instant::now();
41374135
// submit a tx so that the miner will mine a stacks block
41384136
let mut sender_nonce = 0;
41394137
let transfer_tx =
41404138
make_stacks_transfer(&sender_sk, sender_nonce, send_fee, &recipient, send_amt);
41414139
let tx = submit_tx(&http_origin, &transfer_tx);
41424140
info!("Submitted tx {tx} in to mine block N");
4143-
while mined_blocks.load(Ordering::SeqCst) <= blocks_before {
4144-
assert!(
4145-
start_time.elapsed() < short_timeout,
4146-
"FAIL: Test timed out while waiting for block production",
4147-
);
4148-
thread::sleep(Duration::from_secs(1));
4149-
}
4141+
wait_for(short_timeout.as_secs(), || {
4142+
let info_after = signer_test
4143+
.stacks_client
4144+
.get_peer_info()
4145+
.expect("Failed to get peer info");
4146+
Ok(info_after.stacks_tip_height > info_before.stacks_tip_height)
4147+
})
4148+
.expect("Timed out waiting for block to be mined and processed");
41504149

41514150
sender_nonce += 1;
41524151
let info_after = signer_test
@@ -4196,13 +4195,14 @@ fn locally_rejected_blocks_overriden_by_global_acceptance() {
41964195
.stacks_client
41974196
.get_peer_info()
41984197
.expect("Failed to get peer info");
4199-
while mined_blocks.load(Ordering::SeqCst) <= blocks_before {
4200-
assert!(
4201-
start_time.elapsed() < short_timeout,
4202-
"FAIL: Test timed out while waiting for block production",
4203-
);
4204-
thread::sleep(Duration::from_secs(1));
4205-
}
4198+
wait_for(short_timeout.as_secs(), || {
4199+
let info_after = signer_test
4200+
.stacks_client
4201+
.get_peer_info()
4202+
.expect("Failed to get peer info");
4203+
Ok(info_after.stacks_tip_height > info_before.stacks_tip_height)
4204+
})
4205+
.expect("Timed out waiting for block to be mined and processed");
42064206
loop {
42074207
let stackerdb_events = test_observer::get_stackerdb_chunks();
42084208
let block_rejections = stackerdb_events
@@ -4274,13 +4274,14 @@ fn locally_rejected_blocks_overriden_by_global_acceptance() {
42744274
make_stacks_transfer(&sender_sk, sender_nonce, send_fee, &recipient, send_amt);
42754275
let tx = submit_tx(&http_origin, &transfer_tx);
42764276
info!("Submitted tx {tx} in to mine block N+2");
4277-
while mined_blocks.load(Ordering::SeqCst) <= blocks_before {
4278-
assert!(
4279-
start_time.elapsed() < short_timeout,
4280-
"FAIL: Test timed out while waiting for block production",
4281-
);
4282-
thread::sleep(Duration::from_secs(1));
4283-
}
4277+
wait_for(short_timeout.as_secs(), || {
4278+
let info_after = signer_test
4279+
.stacks_client
4280+
.get_peer_info()
4281+
.expect("Failed to get peer info");
4282+
Ok(info_after.stacks_tip_height > info_before.stacks_tip_height)
4283+
})
4284+
.expect("Timed out waiting for block to be mined and processed");
42844285
let blocks_after = mined_blocks.load(Ordering::SeqCst);
42854286
assert_eq!(blocks_after, blocks_before + 1);
42864287

@@ -4348,31 +4349,31 @@ fn reorg_locally_accepted_blocks_across_tenures_succeeds() {
43484349
info!("------------------------- Starting Tenure A -------------------------");
43494350
info!("------------------------- Test Mine Nakamoto Block N -------------------------");
43504351
let mined_blocks = signer_test.running_nodes.nakamoto_blocks_mined.clone();
4351-
let blocks_before = mined_blocks.load(Ordering::SeqCst);
43524352
let info_before = signer_test
43534353
.stacks_client
43544354
.get_peer_info()
43554355
.expect("Failed to get peer info");
4356-
let start_time = Instant::now();
43574356
// submit a tx so that the miner will mine a stacks block
43584357
let mut sender_nonce = 0;
43594358
let transfer_tx =
43604359
make_stacks_transfer(&sender_sk, sender_nonce, send_fee, &recipient, send_amt);
43614360
let tx = submit_tx(&http_origin, &transfer_tx);
43624361
info!("Submitted tx {tx} in to mine block N");
4363-
while mined_blocks.load(Ordering::SeqCst) <= blocks_before {
4364-
assert!(
4365-
start_time.elapsed() < short_timeout,
4366-
"FAIL: Test timed out while waiting for block production",
4367-
);
4368-
thread::sleep(Duration::from_secs(1));
4369-
}
4362+
wait_for(short_timeout.as_secs(), || {
4363+
let info_after = signer_test
4364+
.stacks_client
4365+
.get_peer_info()
4366+
.expect("Failed to get peer info");
4367+
Ok(info_after.stacks_tip_height > info_before.stacks_tip_height)
4368+
})
4369+
.expect("Timed out waiting for block to be mined and processed");
43704370

43714371
sender_nonce += 1;
43724372
let info_after = signer_test
43734373
.stacks_client
43744374
.get_peer_info()
43754375
.expect("Failed to get peer info");
4376+
43764377
assert_eq!(
43774378
info_before.stacks_tip_height + 1,
43784379
info_after.stacks_tip_height
@@ -4400,13 +4401,12 @@ fn reorg_locally_accepted_blocks_across_tenures_succeeds() {
44004401
make_stacks_transfer(&sender_sk, sender_nonce, send_fee, &recipient, send_amt);
44014402
let tx = submit_tx(&http_origin, &transfer_tx);
44024403
info!("Submitted tx {tx} in to attempt to mine block N+1");
4403-
let start_time = Instant::now();
44044404
let blocks_before = mined_blocks.load(Ordering::SeqCst);
44054405
let info_before = signer_test
44064406
.stacks_client
44074407
.get_peer_info()
44084408
.expect("Failed to get peer info");
4409-
loop {
4409+
wait_for(short_timeout.as_secs(), || {
44104410
let ignored_signers = test_observer::get_stackerdb_chunks()
44114411
.into_iter()
44124412
.flat_map(|chunk| chunk.modified_slots)
@@ -4423,15 +4423,9 @@ fn reorg_locally_accepted_blocks_across_tenures_succeeds() {
44234423
}
44244424
})
44254425
.collect::<Vec<_>>();
4426-
if ignored_signers.len() + ignoring_signers.len() == num_signers {
4427-
break;
4428-
}
4429-
assert!(
4430-
start_time.elapsed() < short_timeout,
4431-
"FAIL: Test timed out while waiting for block proposal acceptance",
4432-
);
4433-
sleep_ms(1000);
4434-
}
4426+
Ok(ignored_signers.len() + ignoring_signers.len() == num_signers)
4427+
})
4428+
.expect("FAIL: Timed out waiting for block proposal acceptance");
44354429
let blocks_after = mined_blocks.load(Ordering::SeqCst);
44364430
let info_after = signer_test
44374431
.stacks_client
@@ -4464,25 +4458,23 @@ fn reorg_locally_accepted_blocks_across_tenures_succeeds() {
44644458
.lock()
44654459
.unwrap()
44664460
.replace(Vec::new());
4467-
let mined_blocks = signer_test.running_nodes.nakamoto_blocks_mined.clone();
4468-
let blocks_before = mined_blocks.load(Ordering::SeqCst);
44694461
let info_before = signer_test
44704462
.stacks_client
44714463
.get_peer_info()
44724464
.expect("Failed to get peer info");
4473-
let start_time = Instant::now();
44744465
// submit a tx so that the miner will mine a stacks block
44754466
let transfer_tx =
44764467
make_stacks_transfer(&sender_sk, sender_nonce, send_fee, &recipient, send_amt);
44774468
let tx = submit_tx(&http_origin, &transfer_tx);
44784469
info!("Submitted tx {tx} in to mine block N");
4479-
while mined_blocks.load(Ordering::SeqCst) <= blocks_before {
4480-
assert!(
4481-
start_time.elapsed() < short_timeout,
4482-
"FAIL: Test timed out while waiting for block production",
4483-
);
4484-
thread::sleep(Duration::from_secs(1));
4485-
}
4470+
wait_for(short_timeout.as_secs(), || {
4471+
let info_after = signer_test
4472+
.stacks_client
4473+
.get_peer_info()
4474+
.expect("Failed to get peer info");
4475+
Ok(info_after.stacks_tip_height > info_before.stacks_tip_height)
4476+
})
4477+
.expect("Timed out waiting for block to be mined and processed");
44864478

44874479
let info_after = signer_test
44884480
.stacks_client

0 commit comments

Comments
 (0)