Skip to content

Commit

Permalink
Make test_esplora_syncs more robust
Browse files Browse the repository at this point in the history
The test generally works and the parts in question *should* never fail.
However, they did, so we give the test server instances some leeway.
  • Loading branch information
tnull committed Feb 15, 2023
1 parent 9f10203 commit 6d8dff9
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions lightning-transaction-sync/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ fn get_bitcoind() -> &'static BitcoinD {
);
let mut conf = bitcoind::Conf::default();
conf.network = "regtest";
BitcoinD::with_conf(bitcoind_exe, &conf).unwrap()
let bitcoind = BitcoinD::with_conf(bitcoind_exe, &conf).unwrap();
std::thread::sleep(Duration::from_secs(3));
bitcoind
})
}

Expand All @@ -46,7 +48,9 @@ fn get_electrsd() -> &'static ElectrsD {
let mut conf = electrsd::Conf::default();
conf.http_enabled = true;
conf.network = "regtest";
ElectrsD::with_conf(electrs_exe, &bitcoind, &conf).unwrap()
let electrsd = ElectrsD::with_conf(electrs_exe, &bitcoind, &conf).unwrap();
std::thread::sleep(Duration::from_secs(3));
electrsd
})
}

Expand All @@ -60,15 +64,22 @@ fn generate_blocks_and_wait(num: usize) {
}

fn wait_for_block(min_height: usize) {
let mut header = get_electrsd().client.block_headers_subscribe().unwrap();
let mut header = match get_electrsd().client.block_headers_subscribe() {
Ok(header) => header,
Err(_) => {
std::thread::sleep(Duration::from_secs(3));
get_electrsd().client.block_headers_subscribe().expect("failed to subscribe to block headers")
}
};

loop {
if header.height >= min_height {
break;
}
header = exponential_backoff_poll(|| {
get_electrsd().trigger().unwrap();
get_electrsd().client.ping().unwrap();
get_electrsd().client.block_headers_pop().unwrap()
get_electrsd().trigger().expect("failed to trigger electrsd");
get_electrsd().client.ping().expect("failed to ping electrsd");
get_electrsd().client.block_headers_pop().expect("failed to pop block header")
});
}
}
Expand Down

0 comments on commit 6d8dff9

Please sign in to comment.