Skip to content

Commit 33927c3

Browse files
committed
test: Add diagnostic logging for electrs process failures
Enable electrs stderr output in CI and log connection details at startup. Log errors that were previously silently discarded: the first block_headers_subscribe failure, generate_to_address failures, and ping errors across all polling helpers. This will help diagnose intermittent CI failures where electrs appears to crash or become unreachable mid-test. AI tools were used in preparing this commit.
1 parent 4c6dfec commit 33927c3

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

tests/common/mod.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,12 @@ pub(crate) fn setup_bitcoind_and_electrsd() -> (BitcoinD, ElectrsD) {
232232
let mut electrsd_conf = electrsd::Conf::default();
233233
electrsd_conf.http_enabled = true;
234234
electrsd_conf.network = "regtest";
235+
electrsd_conf.view_stderr = true;
235236
let electrsd = ElectrsD::with_conf(electrs_exe, &bitcoind, &electrsd_conf).unwrap();
237+
println!(
238+
"Electrs started with electrum_url={}, esplora_url={:?}",
239+
electrsd.electrum_url, electrsd.esplora_url
240+
);
236241
(bitcoind, electrsd)
237242
}
238243

@@ -510,6 +515,9 @@ pub(crate) async fn generate_blocks_and_wait<E: ElectrumApi>(
510515
let address = bitcoind.new_address().expect("failed to get new address");
511516
// TODO: expect this Result once the WouldBlock issue is resolved upstream.
512517
let _block_hashes_res = bitcoind.generate_to_address(num, &address);
518+
if let Err(ref e) = _block_hashes_res {
519+
eprintln!("generate_to_address({}) failed: {:?}", num, e);
520+
}
513521
wait_for_block(electrs, cur_height as usize + num).await;
514522
print!(" Done!");
515523
println!("\n");
@@ -533,10 +541,14 @@ pub(crate) fn invalidate_blocks(bitcoind: &BitcoindClient, num_blocks: usize) {
533541
pub(crate) async fn wait_for_block<E: ElectrumApi>(electrs: &E, min_height: usize) {
534542
let mut header = match electrs.block_headers_subscribe() {
535543
Ok(header) => header,
536-
Err(_) => {
544+
Err(e) => {
537545
// While subscribing should succeed the first time around, we ran into some cases where
538546
// it didn't. Since we can't proceed without subscribing, we try again after a delay
539547
// and panic if it still fails.
548+
eprintln!("block_headers_subscribe failed (will retry in 3s): {:?}", e);
549+
if let Err(ping_err) = electrs.ping() {
550+
eprintln!("electrs ping also failed: {:?}", ping_err);
551+
}
540552
tokio::time::sleep(Duration::from_secs(3)).await;
541553
electrs.block_headers_subscribe().expect("failed to subscribe to block headers")
542554
},
@@ -546,8 +558,10 @@ pub(crate) async fn wait_for_block<E: ElectrumApi>(electrs: &E, min_height: usiz
546558
break;
547559
}
548560
header = exponential_backoff_poll(|| {
549-
electrs.ping().expect("failed to ping electrs");
550-
electrs.block_headers_pop().expect("failed to pop block header")
561+
electrs.ping().unwrap_or_else(|e| panic!("failed to ping electrs: {:?}", e));
562+
electrs
563+
.block_headers_pop()
564+
.unwrap_or_else(|e| panic!("failed to pop block header: {:?}", e))
551565
})
552566
.await;
553567
}
@@ -559,7 +573,7 @@ pub(crate) async fn wait_for_tx<E: ElectrumApi>(electrs: &E, txid: Txid) {
559573
}
560574

561575
exponential_backoff_poll(|| {
562-
electrs.ping().unwrap();
576+
electrs.ping().unwrap_or_else(|e| panic!("failed to ping electrs: {:?}", e));
563577
electrs.transaction_get(&txid).ok()
564578
})
565579
.await;
@@ -575,7 +589,7 @@ pub(crate) async fn wait_for_outpoint_spend<E: ElectrumApi>(electrs: &E, outpoin
575589
}
576590

577591
exponential_backoff_poll(|| {
578-
electrs.ping().unwrap();
592+
electrs.ping().unwrap_or_else(|e| panic!("failed to ping electrs: {:?}", e));
579593

580594
let is_spent = !electrs.script_get_history(&txout_script).unwrap().is_empty();
581595
is_spent.then_some(())

0 commit comments

Comments
 (0)