Skip to content

Commit 06efc09

Browse files
committed
WIP: Cleanup test for easier logic
Signed-off-by: Jacinta Ferrant <[email protected]>
1 parent 42fd891 commit 06efc09

File tree

1 file changed

+23
-28
lines changed
  • testnet/stacks-node/src/tests/signer

1 file changed

+23
-28
lines changed

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

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1915,7 +1915,10 @@ fn end_of_tenure() {
19151915
let http_origin = format!("http://{}", &signer_test.running_nodes.conf.node.rpc_bind);
19161916
let long_timeout = Duration::from_secs(200);
19171917
let short_timeout = Duration::from_secs(20);
1918-
1918+
let blocks_before = signer_test
1919+
.running_nodes
1920+
.nakamoto_blocks_mined
1921+
.load(Ordering::SeqCst);
19191922
signer_test.boot_to_epoch_3();
19201923
let curr_reward_cycle = signer_test.get_current_reward_cycle();
19211924
// Advance to one before the next reward cycle to ensure we are on the reward cycle boundary
@@ -1928,15 +1931,26 @@ fn end_of_tenure() {
19281931
- 2;
19291932

19301933
// give the system a chance to mine a Nakamoto block
1931-
sleep_ms(30_000);
1934+
// But it doesn't have to mine one for this test to succeed?
1935+
let start = Instant::now();
1936+
while start.elapsed() <= short_timeout {
1937+
let mined_blocks = signer_test
1938+
.running_nodes
1939+
.nakamoto_blocks_mined
1940+
.load(Ordering::SeqCst);
1941+
if mined_blocks > blocks_before {
1942+
break;
1943+
}
1944+
sleep_ms(100);
1945+
}
19321946

19331947
info!("------------------------- Test Mine to Next Reward Cycle Boundary -------------------------");
19341948
signer_test.run_until_burnchain_height_nakamoto(
19351949
long_timeout,
19361950
final_reward_cycle_height_boundary,
19371951
num_signers,
19381952
);
1939-
println!("Advanced to nexct reward cycle boundary: {final_reward_cycle_height_boundary}");
1953+
println!("Advanced to next reward cycle boundary: {final_reward_cycle_height_boundary}");
19401954
assert_eq!(
19411955
signer_test.get_current_reward_cycle(),
19421956
final_reward_cycle - 1
@@ -1977,39 +1991,20 @@ fn end_of_tenure() {
19771991
std::thread::sleep(Duration::from_millis(100));
19781992
}
19791993

1980-
info!("Triggering a new block to be mined");
1981-
1982-
// Mine a block into the next reward cycle
1983-
let commits_before = signer_test
1984-
.running_nodes
1985-
.commits_submitted
1986-
.load(Ordering::SeqCst);
1987-
next_block_and(
1988-
&mut signer_test.running_nodes.btc_regtest_controller,
1989-
10,
1990-
|| {
1991-
let commits_count = signer_test
1992-
.running_nodes
1993-
.commits_submitted
1994-
.load(Ordering::SeqCst);
1995-
Ok(commits_count > commits_before)
1996-
},
1997-
)
1998-
.unwrap();
1999-
2000-
// Mine a few blocks so we are well into the next reward cycle
2001-
for _ in 0..2 {
1994+
while signer_test.get_current_reward_cycle() != final_reward_cycle {
20021995
next_block_and(
20031996
&mut signer_test.running_nodes.btc_regtest_controller,
20041997
10,
20051998
|| Ok(true),
20061999
)
20072000
.unwrap();
2001+
assert!(
2002+
start_time.elapsed() <= short_timeout,
2003+
"Timed out waiting to enter the next reward cycle"
2004+
);
2005+
std::thread::sleep(Duration::from_millis(100));
20082006
}
20092007

2010-
sleep_ms(10_000);
2011-
assert_eq!(signer_test.get_current_reward_cycle(), final_reward_cycle);
2012-
20132008
while test_observer::get_burn_blocks()
20142009
.last()
20152010
.unwrap()

0 commit comments

Comments
 (0)