Skip to content

Commit d96c407

Browse files
committed
Remove use of sleep when waiting for tx broadcast
1 parent a919fe3 commit d96c407

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

orange-sdk/tests/test_utils.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,7 @@ pub fn build_test_nodes() -> TestParams {
252252

253253
// open a channel from payer to LSP
254254
third_party.open_channel(lsp.node_id(), lsp_listen.clone(), 10_000_000, None, None).unwrap();
255-
// wait for tx to broadcast
256-
std::thread::sleep(Duration::from_secs(1)); // Keep short sleep for broadcast
255+
wait_for_tx_broadcast(&bitcoind);
257256
generate_blocks(&bitcoind, 6);
258257

259258
// wait for channel ready (needs blocking wait as we are not in async context here)
@@ -404,8 +403,7 @@ pub fn build_test_nodes() -> TestParams {
404403
cdk.node()
405404
.open_channel(lsp_node_id, lsp_listen_clone, 10_000_000, Some(5_000_000_000), None)
406405
.unwrap();
407-
// wait for tx to broadcast
408-
tokio::time::sleep(Duration::from_secs(1)).await;
406+
wait_for_tx_broadcast(&bitcoind_clone);
409407
generate_blocks(&bitcoind_clone, 6);
410408

411409
// wait for sync/channel ready
@@ -494,3 +492,14 @@ pub async fn open_channel_from_lsp(wallet: &orange_sdk::Wallet, payer: Arc<Node>
494492

495493
recv_amt
496494
}
495+
496+
fn wait_for_tx_broadcast(bitcoind: &Bitcoind) {
497+
let iterations = if std::env::var("CI").is_ok() { 120 } else { 10 };
498+
for _ in 0..iterations {
499+
let num_txs = bitcoind.client.get_mempool_info().unwrap().size;
500+
if num_txs > 0 {
501+
break;
502+
}
503+
std::thread::sleep(Duration::from_millis(250));
504+
}
505+
}

0 commit comments

Comments
 (0)