Skip to content

Commit 550cd52

Browse files
committed
test: resolve issues with bitcoin_reorg_flap_with_follower
1 parent 19d36e2 commit 550cd52

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

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

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12398,6 +12398,10 @@ fn bitcoin_reorg_flap() {
1239812398
channel.stop_chains_coordinator();
1239912399
}
1240012400

12401+
/// Advance the bitcoin chain and wait for the miner and any followers to
12402+
/// process the next block.
12403+
/// NOTE: This only works if the followers are mock-mining, or else the counter
12404+
/// will not be updated.
1240112405
fn next_block_and_wait_all(
1240212406
btc_controller: &mut BitcoinRegtestController,
1240312407
miner_blocks_processed: &Arc<AtomicU64>,
@@ -12447,7 +12451,7 @@ fn bitcoin_reorg_flap_with_follower() {
1244712451
}
1244812452

1244912453
let (conf, _miner_account) = neon_integration_test_conf();
12450-
let timeout = None;
12454+
let timeout = Some(Duration::from_secs(60));
1245112455

1245212456
let mut btcd_controller = BitcoinCoreController::new(conf.clone());
1245312457
btcd_controller
@@ -12461,10 +12465,12 @@ fn bitcoin_reorg_flap_with_follower() {
1246112465
eprintln!("Chain bootstrapped...");
1246212466

1246312467
let mut miner_run_loop = neon::RunLoop::new(conf.clone());
12468+
let run_loop_stopper = miner_run_loop.get_termination_switch();
1246412469
let miner_blocks_processed = miner_run_loop.get_blocks_processed_arc();
1246512470
let miner_channel = miner_run_loop.get_coordinator_channel().unwrap();
1246612471

1246712472
let mut follower_conf = conf.clone();
12473+
follower_conf.node.mock_mining = true;
1246812474
follower_conf.events_observers.clear();
1246912475
follower_conf.node.working_dir = format!("{}-follower", &conf.node.working_dir);
1247012476
follower_conf.node.seed = vec![0x01; 32];
@@ -12483,7 +12489,7 @@ fn bitcoin_reorg_flap_with_follower() {
1248312489
follower_conf.node.data_url = format!("http://{}:{}", &localhost, rpc_port);
1248412490
follower_conf.node.p2p_address = format!("{}:{}", &localhost, p2p_port);
1248512491

12486-
thread::spawn(move || miner_run_loop.start(None, 0));
12492+
let run_loop_thread = thread::spawn(move || miner_run_loop.start(None, 0));
1248712493
wait_for_runloop(&miner_blocks_processed);
1248812494

1248912495
// figure out the started node's port
@@ -12499,23 +12505,20 @@ fn bitcoin_reorg_flap_with_follower() {
1249912505
);
1250012506

1250112507
let mut follower_run_loop = neon::RunLoop::new(follower_conf.clone());
12508+
let follower_run_loop_stopper = follower_run_loop.get_termination_switch();
1250212509
let follower_blocks_processed = follower_run_loop.get_blocks_processed_arc();
1250312510
let follower_channel = follower_run_loop.get_coordinator_channel().unwrap();
1250412511

12505-
thread::spawn(move || follower_run_loop.start(None, 0));
12512+
let follower_thread = thread::spawn(move || follower_run_loop.start(None, 0));
1250612513
wait_for_runloop(&follower_blocks_processed);
1250712514

1250812515
eprintln!("Follower bootup complete!");
1250912516

1251012517
// first block wakes up the run loop
12511-
next_block_and_wait_all(
12512-
&mut btc_regtest_controller,
12513-
&miner_blocks_processed,
12514-
&[],
12515-
timeout,
12516-
);
12518+
next_block_and_wait_with_timeout(&mut btc_regtest_controller, &miner_blocks_processed, 60);
1251712519

12518-
// first block will hold our VRF registration
12520+
// next block will hold our VRF registration
12521+
// Note that the follower will not see its block processed counter bumped here
1251912522
next_block_and_wait_all(
1252012523
&mut btc_regtest_controller,
1252112524
&miner_blocks_processed,
@@ -12609,9 +12612,11 @@ fn bitcoin_reorg_flap_with_follower() {
1260912612
assert_eq!(miner_channel.get_sortitions_processed(), 225);
1261012613
assert_eq!(follower_channel.get_sortitions_processed(), 225);
1261112614

12612-
btcd_controller.stop_bitcoind().unwrap();
12613-
miner_channel.stop_chains_coordinator();
12614-
follower_channel.stop_chains_coordinator();
12615+
run_loop_stopper.store(false, Ordering::SeqCst);
12616+
follower_run_loop_stopper.store(false, Ordering::SeqCst);
12617+
12618+
run_loop_thread.join().unwrap();
12619+
follower_thread.join().unwrap();
1261512620
}
1261612621

1261712622
/// Tests the following:

0 commit comments

Comments
 (0)