diff --git a/tests/common/dispute.rs b/tests/common/dispute.rs index 185a5644..37734927 100644 --- a/tests/common/dispute.rs +++ b/tests/common/dispute.rs @@ -39,7 +39,7 @@ use protocol_builder::types::{OutputType, Utxo}; use tracing::{error, info}; use uuid::Uuid; -use crate::common::{mine_and_wait_blocks, mine_and_wait_with_dispatcher}; +use crate::common::{mine_and_wait_blocks, mine_and_wait_with_dispatcher, CI_SLEEP_MS, LOCAL_SLEEP_MS}; use super::{mine_and_wait, send_all, wait_message_from_channel}; @@ -424,7 +424,12 @@ pub fn process_dispatcher( return Ok(()); } } - std::thread::sleep(std::time::Duration::from_millis(200)); + let sleep_ms = if std::env::var("GITHUB_ACTIONS").is_ok() { + CI_SLEEP_MS + } else { + LOCAL_SLEEP_MS + }; + std::thread::sleep(std::time::Duration::from_millis(sleep_ms)); } } diff --git a/tests/common/helper.rs b/tests/common/helper.rs index 6f8c034a..044e4d67 100644 --- a/tests/common/helper.rs +++ b/tests/common/helper.rs @@ -107,20 +107,27 @@ impl TestHelper { clear_db(&wallet_config.key_storage.path); Wallet::clear_db(&wallet_config.wallet)?; - let bitcoind_instance = Bitcoind::new( - BitcoindConfig::default(), - wallet_config.bitcoin.clone(), - Some(BitcoindFlags { - min_relay_tx_fee: 0.00001, - block_min_tx_fee: 0.00001 * MIN_TX_FEE, - debug: 1, - fallback_fee: 0.0002, - maxmempool: None, - }), - ); - - bitcoind_instance.start()?; - Some(bitcoind_instance) + // In CI, bitcoind is provided by docker-compose on the same port. + // Spawning another container would collide on 0.0.0.0:18443. + if std::env::var("GITHUB_ACTIONS").is_ok() { + info!("Running in CI - using external bitcoind from docker-compose"); + None + } else { + let bitcoind_instance = Bitcoind::new( + BitcoindConfig::default(), + wallet_config.bitcoin.clone(), + Some(BitcoindFlags { + min_relay_tx_fee: 0.00001, + block_min_tx_fee: 0.00001 * MIN_TX_FEE, + debug: 1, + fallback_fee: 0.0002, + maxmempool: None, + }), + ); + + bitcoind_instance.start()?; + Some(bitcoind_instance) + } }; let mut wallet = @@ -132,7 +139,11 @@ impl TestHelper { &wallet_config.bitcoin.password, )?; let address = bitcoin_client.init_wallet(&wallet_config.bitcoin.wallet)?; - bitcoin_client.mine_blocks_to_address(INITIAL_BLOCK_COUNT, &address)?; + if std::env::var("GITHUB_ACTIONS").is_err() { + // Locally we control bitcoind; in CI the shared bitcoind is already + // funded by the test harness, so skip the extra mining. + bitcoin_client.mine_blocks_to_address(INITIAL_BLOCK_COUNT, &address)?; + } bitcoin_client.fund_address(&wallet.receive_address()?, Amount::from_int_btc(10))?; wallet.sync_wallet()?; } @@ -605,6 +616,13 @@ fn run_auto_mine( let address = bitcoin_client.init_wallet("test_wallet"); let address = address.unwrap(); + // Track how many blocks *this* auto_mine has produced, not the absolute + // chain height. The chain may already be tall when tests run sequentially + // in CI (previous test binaries share the same bitcoind), so comparing + // against absolute height would abort immediately. + let start_height = bitcoin_client.get_blockchain_info()?.blocks; + let mut mined: u64 = 0; + // Main processing loop loop { if rx.try_recv().is_ok() { @@ -612,11 +630,14 @@ fn run_auto_mine( break; } bitcoin_client.mine_blocks_to_address(1, &address)?; + mined += 1; tx.send(())?; if let Some(limit) = max_mined_blocks { - let current = bitcoin_client.get_blockchain_info()?.blocks; - if current >= limit { - error!("Max mined blocks reached!"); + if mined >= limit { + error!( + "Max mined blocks reached! (mined {} since start_height {})", + mined, start_height + ); std::process::abort(); } } diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 0701fe99..120456f2 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -71,7 +71,9 @@ impl Drop for BitcoindGuard { pub const LOCAL_SLEEP_MS: u64 = 100; -pub const CI_SLEEP_MS: u64 = 1000; +// Slightly higher in CI to absorb shared-runner variability. Kept as a +// separate constant so the CI value can be tuned independently. +pub const CI_SLEEP_MS: u64 = 150; pub fn clear_db(path: &str) { // Only try to remove if the path exists