Skip to content

Commit 420f861

Browse files
committed
use Counters instead of global test vars
1 parent 0e7461c commit 420f861

File tree

4 files changed

+86
-23
lines changed

4 files changed

+86
-23
lines changed

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

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
use std::collections::{BTreeMap, HashMap};
1717
use std::ops::Bound::Included;
1818
use std::sync::atomic::AtomicBool;
19-
#[cfg(test)]
20-
use std::sync::LazyLock;
2119
use std::sync::{Arc, Mutex};
2220
use std::thread::JoinHandle;
2321
use std::time::{Duration, Instant};
@@ -38,8 +36,6 @@ use stacks::types::chainstate::{StacksBlockId, StacksPrivateKey};
3836
use stacks::util::hash::Sha512Trunc256Sum;
3937
use stacks::util::secp256k1::MessageSignature;
4038
use stacks::util_lib::boot::boot_code_id;
41-
#[cfg(test)]
42-
use stacks_common::util::tests::TestFlag;
4339

4440
use super::stackerdb_listener::StackerDBListenerComms;
4541
use super::Error as NakamotoNodeError;
@@ -50,11 +46,6 @@ use crate::nakamoto_node::stackerdb_listener::{
5046
use crate::neon::Counters;
5147
use crate::Config;
5248

53-
#[cfg(test)]
54-
/// Test-only value for storing the current rejection based timeout
55-
pub static BLOCK_REJECTIONS_CURRENT_TIMEOUT: LazyLock<TestFlag<Duration>> =
56-
LazyLock::new(TestFlag::default);
57-
5849
/// The state of the signer database listener, used by the miner thread to
5950
/// interact with the signer listener.
6051
pub struct SignerCoordinator {
@@ -410,7 +401,13 @@ impl SignerCoordinator {
410401
rejections_timer = Instant::now();
411402

412403
#[cfg(test)]
413-
BLOCK_REJECTIONS_CURRENT_TIMEOUT.set(*rejections_timeout);
404+
{
405+
Counters::set(
406+
&counters.naka_miner_current_rejections_timeout_secs,
407+
rejections_timeout.as_secs(),
408+
);
409+
Counters::set(&counters.naka_miner_current_rejections, rejections);
410+
}
414411
}
415412

416413
if block_status

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ pub struct Counters {
115115
pub naka_signer_pushed_blocks: RunLoopCounter,
116116
pub naka_miner_directives: RunLoopCounter,
117117

118+
#[cfg(test)]
119+
pub naka_miner_current_rejections: RunLoopCounter,
120+
#[cfg(test)]
121+
pub naka_miner_current_rejections_timeout_secs: RunLoopCounter,
122+
118123
#[cfg(test)]
119124
pub naka_skip_commit_op: TestFlag<bool>,
120125
}
@@ -133,7 +138,7 @@ impl Counters {
133138
fn inc(_ctr: &RunLoopCounter) {}
134139

135140
#[cfg(test)]
136-
fn set(ctr: &RunLoopCounter, value: u64) {
141+
pub fn set(ctr: &RunLoopCounter, value: u64) {
137142
ctr.0.store(value, Ordering::SeqCst);
138143
}
139144

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ pub struct RunningNodes {
9898
pub nakamoto_test_skip_commit_op: TestFlag<bool>,
9999
pub coord_channel: Arc<Mutex<CoordinatorChannels>>,
100100
pub conf: NeonConfig,
101+
pub counters: Counters,
101102
}
102103

103104
/// A test harness for running a v0 or v1 signer integration test
@@ -943,6 +944,9 @@ fn setup_stx_btc_node<G: FnMut(&mut NeonConfig)>(
943944
} = run_loop.counters();
944945

945946
let coord_channel = run_loop.coordinator_channels();
947+
948+
let run_loop_counters = run_loop.counters();
949+
946950
let run_loop_thread = thread::spawn(move || run_loop.start(None, 0));
947951

948952
// Give the run loop some time to start up!
@@ -978,5 +982,6 @@ fn setup_stx_btc_node<G: FnMut(&mut NeonConfig)>(
978982
nakamoto_miner_directives: naka_miner_directives.0,
979983
coord_channel,
980984
conf: naka_conf,
985+
counters: run_loop_counters,
981986
}
982987
}

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

Lines changed: 68 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ use crate::event_dispatcher::{MinedNakamotoBlockEvent, TEST_SKIP_BLOCK_ANNOUNCEM
7676
use crate::nakamoto_node::miner::{
7777
TEST_BLOCK_ANNOUNCE_STALL, TEST_BROADCAST_STALL, TEST_MINE_STALL,
7878
};
79-
use crate::nakamoto_node::signer_coordinator::BLOCK_REJECTIONS_CURRENT_TIMEOUT;
8079
use crate::nakamoto_node::stackerdb_listener::TEST_IGNORE_SIGNERS;
8180
use crate::neon::Counters;
8281
use crate::run_loop::boot_nakamoto;
@@ -7877,9 +7876,23 @@ fn block_validation_check_rejection_timeout_heuristic() {
78777876
.wait_for_block_rejections(timeout.as_secs(), &[all_signers[19]])
78787877
.unwrap();
78797878

7880-
thread::sleep(Duration::from_secs(3));
7881-
7882-
assert_eq!(BLOCK_REJECTIONS_CURRENT_TIMEOUT.get().as_secs(), 123);
7879+
wait_for(60, || {
7880+
Ok(signer_test
7881+
.running_nodes
7882+
.counters
7883+
.naka_miner_current_rejections
7884+
.get()
7885+
>= 1)
7886+
})
7887+
.unwrap();
7888+
assert_eq!(
7889+
signer_test
7890+
.running_nodes
7891+
.counters
7892+
.naka_miner_current_rejections_timeout_secs
7893+
.get(),
7894+
123
7895+
);
78837896

78847897
info!("------------------------- Check Rejections-based timeout with 2 rejections -------------------------");
78857898

@@ -7899,9 +7912,23 @@ fn block_validation_check_rejection_timeout_heuristic() {
78997912
.wait_for_block_rejections(timeout.as_secs(), &[all_signers[18], all_signers[19]])
79007913
.unwrap();
79017914

7902-
thread::sleep(Duration::from_secs(3));
7903-
7904-
assert_eq!(BLOCK_REJECTIONS_CURRENT_TIMEOUT.get().as_secs(), 20);
7915+
wait_for(60, || {
7916+
Ok(signer_test
7917+
.running_nodes
7918+
.counters
7919+
.naka_miner_current_rejections
7920+
.get()
7921+
>= 2)
7922+
})
7923+
.unwrap();
7924+
assert_eq!(
7925+
signer_test
7926+
.running_nodes
7927+
.counters
7928+
.naka_miner_current_rejections_timeout_secs
7929+
.get(),
7930+
20
7931+
);
79057932

79067933
info!("------------------------- Check Rejections-based timeout with 3 rejections -------------------------");
79077934

@@ -7924,9 +7951,24 @@ fn block_validation_check_rejection_timeout_heuristic() {
79247951
)
79257952
.unwrap();
79267953

7927-
thread::sleep(Duration::from_secs(3));
7954+
wait_for(60, || {
7955+
Ok(signer_test
7956+
.running_nodes
7957+
.counters
7958+
.naka_miner_current_rejections
7959+
.get()
7960+
>= 3)
7961+
})
7962+
.unwrap();
79287963

7929-
assert_eq!(BLOCK_REJECTIONS_CURRENT_TIMEOUT.get().as_secs(), 10);
7964+
assert_eq!(
7965+
signer_test
7966+
.running_nodes
7967+
.counters
7968+
.naka_miner_current_rejections_timeout_secs
7969+
.get(),
7970+
10
7971+
);
79307972

79317973
info!("------------------------- Check Rejections-based timeout with 4 rejections -------------------------");
79327974

@@ -7959,9 +8001,23 @@ fn block_validation_check_rejection_timeout_heuristic() {
79598001
)
79608002
.unwrap();
79618003

7962-
thread::sleep(Duration::from_secs(3));
7963-
7964-
assert_eq!(BLOCK_REJECTIONS_CURRENT_TIMEOUT.get().as_secs(), 99);
8004+
wait_for(60, || {
8005+
Ok(signer_test
8006+
.running_nodes
8007+
.counters
8008+
.naka_miner_current_rejections
8009+
.get()
8010+
>= 4)
8011+
})
8012+
.unwrap();
8013+
assert_eq!(
8014+
signer_test
8015+
.running_nodes
8016+
.counters
8017+
.naka_miner_current_rejections_timeout_secs
8018+
.get(),
8019+
99
8020+
);
79658021

79668022
// reset reject/ignore
79678023
TEST_REJECT_ALL_BLOCK_PROPOSAL.set(vec![]);

0 commit comments

Comments
 (0)