Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions tests/common/dispute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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));
}
}

Expand Down
57 changes: 39 additions & 18 deletions tests/common/helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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()?;
}
Expand Down Expand Up @@ -605,18 +616,28 @@ 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() {
info!("Signal received, shutting down...");
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();
}
}
Expand Down
4 changes: 3 additions & 1 deletion tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading