Skip to content

Commit 559b1d6

Browse files
committed
dx: add set/get helper to TestFlag
1 parent a335dcd commit 559b1d6

File tree

4 files changed

+26
-31
lines changed

4 files changed

+26
-31
lines changed

testnet/stacks-node/src/nakamoto_node/relayer.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,13 +1003,7 @@ impl RelayerThread {
10031003

10041004
#[cfg(test)]
10051005
fn fault_injection_skip_block_commit(&self) -> bool {
1006-
self.globals
1007-
.counters
1008-
.naka_skip_commit_op
1009-
.0
1010-
.lock()
1011-
.unwrap()
1012-
.unwrap_or(false)
1006+
self.globals.counters.naka_skip_commit_op.get()
10131007
}
10141008

10151009
#[cfg(not(test))]

testnet/stacks-node/src/run_loop/neon.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,19 @@ impl Default for TestFlag {
9393
}
9494
}
9595

96+
#[cfg(test)]
97+
impl TestFlag {
98+
/// Set the test flag to the given value
99+
pub fn set(&self, value: bool) {
100+
*self.0.lock().unwrap() = Some(value);
101+
}
102+
103+
/// Get the test flag value. Defaults to false if the flag is not set.
104+
pub fn get(&self) -> bool {
105+
self.0.lock().unwrap().unwrap_or(false)
106+
}
107+
}
108+
96109
#[derive(Clone, Default)]
97110
pub struct Counters {
98111
pub blocks_processed: RunLoopCounter,
@@ -1034,7 +1047,7 @@ impl RunLoop {
10341047
/// This function will block by looping infinitely.
10351048
/// It will start the burnchain (separate thread), set-up a channel in
10361049
/// charge of coordinating the new blocks coming from the burnchain and
1037-
/// the nodes, taking turns on tenures.
1050+
/// the nodes, taking turns on tenures.
10381051
///
10391052
/// Returns `Option<NeonGlobals>` so that data can be passed to `NakamotoNode`
10401053
pub fn start(

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5051,7 +5051,7 @@ fn forked_tenure_is_ignored() {
50515051

50525052
// Unpause the broadcast of Tenure B's block, do not submit commits, and do not allow blocks to
50535053
// be processed
5054-
test_skip_commit_op.0.lock().unwrap().replace(true);
5054+
test_skip_commit_op.set(true);
50555055
TEST_BROADCAST_STALL.lock().unwrap().replace(false);
50565056

50575057
// Wait for a stacks block to be broadcasted.
@@ -5104,7 +5104,7 @@ fn forked_tenure_is_ignored() {
51045104
.expect("Mutex poisoned")
51055105
.get_stacks_blocks_processed();
51065106
next_block_and(&mut btc_regtest_controller, 60, || {
5107-
test_skip_commit_op.0.lock().unwrap().replace(false);
5107+
test_skip_commit_op.set(false);
51085108
TEST_BLOCK_ANNOUNCE_STALL.lock().unwrap().replace(false);
51095109
let commits_count = commits_submitted.load(Ordering::SeqCst);
51105110
let blocks_count = mined_blocks.load(Ordering::SeqCst);
@@ -7054,7 +7054,7 @@ fn continue_tenure_extend() {
70547054
.get_stacks_blocks_processed();
70557055

70567056
info!("Pausing commit ops to trigger a tenure extend.");
7057-
test_skip_commit_op.0.lock().unwrap().replace(true);
7057+
test_skip_commit_op.set(true);
70587058

70597059
next_block_and(&mut btc_regtest_controller, 60, || Ok(true)).unwrap();
70607060

@@ -7153,7 +7153,7 @@ fn continue_tenure_extend() {
71537153
}
71547154

71557155
info!("Resuming commit ops to mine regular tenures.");
7156-
test_skip_commit_op.0.lock().unwrap().replace(false);
7156+
test_skip_commit_op.set(false);
71577157

71587158
// Mine 15 more regular nakamoto tenures
71597159
for _i in 0..15 {

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

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,10 +1003,7 @@ fn forked_tenure_testing(
10031003
signer_test
10041004
.running_nodes
10051005
.nakamoto_test_skip_commit_op
1006-
.0
1007-
.lock()
1008-
.unwrap()
1009-
.replace(true);
1006+
.set(true);
10101007
TEST_BROADCAST_STALL.lock().unwrap().replace(false);
10111008

10121009
// Wait for a stacks block to be broadcasted
@@ -1083,10 +1080,7 @@ fn forked_tenure_testing(
10831080
signer_test
10841081
.running_nodes
10851082
.nakamoto_test_skip_commit_op
1086-
.0
1087-
.lock()
1088-
.unwrap()
1089-
.replace(false);
1083+
.set(false);
10901084

10911085
let commits_count = commits_submitted.load(Ordering::SeqCst);
10921086
if commits_count > commits_before {
@@ -1850,7 +1844,7 @@ fn miner_forking() {
18501844

18511845
let pre_nakamoto_peer_1_height = get_chain_info(&conf).stacks_tip_height;
18521846

1853-
naka_skip_commit_op.0.lock().unwrap().replace(false);
1847+
naka_skip_commit_op.set(true);
18541848
info!("------------------------- Reached Epoch 3.0 -------------------------");
18551849

18561850
let mut sortitions_seen = Vec::new();
@@ -1868,7 +1862,7 @@ fn miner_forking() {
18681862
.running_nodes
18691863
.btc_regtest_controller
18701864
.build_next_block(1);
1871-
naka_skip_commit_op.0.lock().unwrap().replace(false);
1865+
naka_skip_commit_op.set(false);
18721866

18731867
// wait until a commit is submitted by run_loop_2
18741868
wait_for(60, || {
@@ -1892,7 +1886,7 @@ fn miner_forking() {
18921886

18931887
// block commits from RL2 -- this will block until the start of the next iteration
18941888
// in this loop.
1895-
naka_skip_commit_op.0.lock().unwrap().replace(true);
1889+
naka_skip_commit_op.set(true);
18961890
// ensure RL1 performs an RBF after unblock block broadcast
18971891
let rl1_commits_before = signer_test
18981892
.running_nodes
@@ -2499,10 +2493,7 @@ fn empty_sortition() {
24992493
signer_test
25002494
.running_nodes
25012495
.nakamoto_test_skip_commit_op
2502-
.0
2503-
.lock()
2504-
.unwrap()
2505-
.replace(true);
2496+
.set(true);
25062497

25072498
let blocks_after = signer_test
25082499
.running_nodes
@@ -5120,10 +5111,7 @@ fn continue_after_tenure_extend() {
51205111
signer_test
51215112
.running_nodes
51225113
.nakamoto_test_skip_commit_op
5123-
.0
5124-
.lock()
5125-
.unwrap()
5126-
.replace(true);
5114+
.set(true);
51275115

51285116
// It's possible that we have a pending block commit already.
51295117
// Mine two BTC blocks to "flush" this commit.

0 commit comments

Comments
 (0)