Skip to content

Commit eb8e944

Browse files
committed
test: fix flake in test_tenure_extend_from_flashblocks, bump default test retry sleep from 100ms to 500ms (less log spam in tests)
1 parent fb2a707 commit eb8e944

File tree

1 file changed

+16
-67
lines changed

1 file changed

+16
-67
lines changed

testnet/stacks-node/src/tests/nakamoto_integrations.rs

Lines changed: 16 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ where
693693
error!("Timed out waiting for check to process");
694694
return Err("Timed out".into());
695695
}
696-
thread::sleep(Duration::from_millis(100));
696+
thread::sleep(Duration::from_millis(500));
697697
}
698698
Ok(())
699699
}
@@ -10764,8 +10764,6 @@ fn test_tenure_extend_from_flashblocks() {
1076410764
let http_origin = format!("http://{}", &naka_conf.node.rpc_bind);
1076510765
let btc_regtest_controller = &mut signer_test.running_nodes.btc_regtest_controller;
1076610766
let coord_channel = signer_test.running_nodes.coord_channel.clone();
10767-
let commits_submitted = signer_test.running_nodes.commits_submitted.clone();
10768-
let sortitions_processed = signer_test.running_nodes.sortitions_processed.clone();
1076910767
let counters = signer_test.running_nodes.counters.clone();
1077010768
let nakamoto_test_skip_commit_op = signer_test
1077110769
.running_nodes
@@ -10818,57 +10816,33 @@ fn test_tenure_extend_from_flashblocks() {
1081810816
);
1081910817
submit_tx(&http_origin, &contract_tx);
1082010818

10821-
let blocks_processed_before = coord_channel
10822-
.lock()
10823-
.expect("Mutex poisoned")
10824-
.get_stacks_blocks_processed();
10825-
1082610819
wait_for(120, || {
10827-
let blocks_processed = coord_channel
10828-
.lock()
10829-
.expect("Mutex poisoned")
10830-
.get_stacks_blocks_processed();
10831-
Ok(blocks_processed > blocks_processed_before)
10820+
let sender_nonce = get_account(&naka_conf.node.data_url, &deployer_addr).nonce;
10821+
Ok(sender_nonce > 0)
1083210822
})
1083310823
.expect("Timed out waiting for interim blocks to be mined");
1083410824

1083510825
next_block_and_mine_commit(btc_regtest_controller, 60, &naka_conf, &counters).unwrap();
1083610826

1083710827
// stall miner and relayer
1083810828

10839-
// make tenure but don't wait for a stacks block
10840-
next_block_and_commits_only(btc_regtest_controller, 60, &naka_conf, &counters).unwrap();
10829+
// make tenure
10830+
next_block_and_mine_commit(btc_regtest_controller, 60, &naka_conf, &counters).unwrap();
1084110831

10842-
// prevent the mienr from sending another block-commit
10832+
// prevent the miner from sending another block-commit
1084310833
nakamoto_test_skip_commit_op.set(true);
1084410834

10845-
// make sure we get a block-found tenure change
10846-
let blocks_processed_before = coord_channel
10847-
.lock()
10848-
.expect("Mutex poisoned")
10849-
.get_stacks_blocks_processed();
10850-
10851-
// make sure the relayer processes both sortitions
10852-
let sortitions_processed_before = sortitions_processed.load(Ordering::SeqCst);
10835+
let info_before = get_chain_info(&naka_conf);
1085310836

1085410837
// mine another Bitcoin block right away, since it will contain a block-commit
1085510838
btc_regtest_controller.bootstrap_chain(1);
1085610839

10857-
wait_for(60, || {
10858-
sleep_ms(100);
10859-
let sortitions_cnt = sortitions_processed.load(Ordering::SeqCst);
10860-
Ok(sortitions_cnt > sortitions_processed_before)
10861-
})
10862-
.unwrap();
10863-
1086410840
wait_for(120, || {
10865-
let blocks_processed = coord_channel
10866-
.lock()
10867-
.expect("Mutex poisoned")
10868-
.get_stacks_blocks_processed();
10869-
Ok(blocks_processed > blocks_processed_before)
10841+
let info = get_chain_info(&naka_conf);
10842+
Ok(info.burn_block_height > info_before.burn_block_height
10843+
&& info.stacks_tip_height > info_before.stacks_tip_height)
1087010844
})
10871-
.expect("Timed out waiting for interim blocks to be mined");
10845+
.unwrap();
1087210846

1087310847
let (canonical_stacks_tip_ch, _) =
1087410848
SortitionDB::get_canonical_stacks_chain_tip_hash(sortdb.conn()).unwrap();
@@ -10895,11 +10869,9 @@ fn test_tenure_extend_from_flashblocks() {
1089510869
// Given the above, this will be an `Extend` tenure.
1089610870
TEST_MINER_THREAD_STALL.set(false);
1089710871

10898-
let sortitions_processed_before = sortitions_processed.load(Ordering::SeqCst);
1089910872
wait_for(60, || {
10900-
sleep_ms(100);
10901-
let sortitions_cnt = sortitions_processed.load(Ordering::SeqCst);
10902-
Ok(sortitions_cnt > sortitions_processed_before)
10873+
let cur_sort_tip = SortitionDB::get_canonical_burn_chain_tip(sortdb.conn()).unwrap();
10874+
Ok(cur_sort_tip.block_height > sort_tip.block_height)
1090310875
})
1090410876
.unwrap();
1090510877

@@ -10977,15 +10949,14 @@ fn test_tenure_extend_from_flashblocks() {
1097710949

1097810950
// wait for the miner directive to be processed
1097910951
wait_for(60, || {
10980-
sleep_ms(30_000);
1098110952
let directives_cnt = nakamoto_miner_directives.load(Ordering::SeqCst);
1098210953
Ok(directives_cnt > miner_directives_before)
1098310954
})
1098410955
.unwrap();
1098510956

1098610957
// wait for all of the aforementioned transactions to get mined
1098710958
wait_for(120, || {
10988-
// fill mempool with transactions that depend on the burn view
10959+
// check account nonces from the sent transactions
1098910960
for (sender_sk, account_before) in account_keys.iter().zip(accounts_before.iter()) {
1099010961
let sender_addr = tests::to_addr(sender_sk);
1099110962
let account = loop {
@@ -11042,28 +11013,7 @@ fn test_tenure_extend_from_flashblocks() {
1104211013
}
1104311014

1104411015
// mine one additional tenure, to verify that we're on track
11045-
let commits_before = commits_submitted.load(Ordering::SeqCst);
11046-
let node_info_before = get_chain_info_opt(&naka_conf).unwrap();
11047-
11048-
btc_regtest_controller.bootstrap_chain(1);
11049-
11050-
wait_for(20, || {
11051-
Ok(commits_submitted.load(Ordering::SeqCst) > commits_before)
11052-
})
11053-
.unwrap();
11054-
11055-
// there was a sortition winner
11056-
let sort_tip = SortitionDB::get_canonical_burn_chain_tip(sortdb.conn()).unwrap();
11057-
assert!(sort_tip.sortition);
11058-
11059-
wait_for(20, || {
11060-
let node_info = get_chain_info_opt(&naka_conf).unwrap();
11061-
Ok(
11062-
node_info.burn_block_height > node_info_before.burn_block_height
11063-
&& node_info.stacks_tip_height > node_info_before.stacks_tip_height,
11064-
)
11065-
})
11066-
.unwrap();
11016+
next_block_and_mine_commit(btc_regtest_controller, 60, &naka_conf, &counters).unwrap();
1106711017

1106811018
// boot a follower. it should reach the chain tip
1106911019
info!("----- BEGIN FOLLOWR BOOTUP ------");
@@ -11118,9 +11068,8 @@ fn test_tenure_extend_from_flashblocks() {
1111811068

1111911069
debug!("Booted follower-thread");
1112011070

11121-
let miner_info = get_chain_info_result(&naka_conf).unwrap();
11122-
1112311071
wait_for(300, || {
11072+
let miner_info = get_chain_info_result(&naka_conf).unwrap();
1112411073
let Ok(info) = get_chain_info_result(&follower_conf) else {
1112511074
sleep_ms(1000);
1112611075
return Ok(false);

0 commit comments

Comments
 (0)