Skip to content

Commit df47e8d

Browse files
committed
fix test
1 parent 936873a commit df47e8d

File tree

1 file changed

+16
-4
lines changed
  • lightning-background-processor/src

1 file changed

+16
-4
lines changed

lightning-background-processor/src/lib.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -1129,7 +1129,7 @@ mod tests {
11291129
SCORER_PERSISTENCE_SECONDARY_NAMESPACE,
11301130
};
11311131
use lightning::util::ser::Writeable;
1132-
use lightning::util::sweep::{OutputSpendStatus, OutputSweeperSync, PRUNE_DELAY_BLOCKS};
1132+
use lightning::util::sweep::{OutputSpendStatus, OutputSweeperSync, TrackedSpendableOutput, PRUNE_DELAY_BLOCKS};
11331133
use lightning::util::test_utils;
11341134
use lightning::{get_event, get_event_msg};
11351135
use lightning_persister::fs_store::FilesystemStore;
@@ -2258,10 +2258,22 @@ mod tests {
22582258

22592259
advance_chain(&mut nodes[0], 3);
22602260

2261+
let tx_broadcaster = nodes[0].tx_broadcaster.clone();
2262+
let wait_for_sweep_tx = || -> Transaction {
2263+
loop {
2264+
let sweep_tx = tx_broadcaster.txn_broadcasted.lock().unwrap().pop();
2265+
if let Some(sweep_tx) = sweep_tx {
2266+
return sweep_tx;
2267+
}
2268+
2269+
std::thread::sleep(Duration::from_millis(100));
2270+
}
2271+
};
2272+
22612273
// Check we generate an initial sweeping tx.
22622274
assert_eq!(nodes[0].sweeper.tracked_spendable_outputs().len(), 1);
2275+
let sweep_tx_0 = wait_for_sweep_tx();
22632276
let tracked_output = nodes[0].sweeper.tracked_spendable_outputs().first().unwrap().clone();
2264-
let sweep_tx_0 = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().pop().unwrap();
22652277
match tracked_output.status {
22662278
OutputSpendStatus::PendingFirstConfirmation { latest_spending_tx, .. } => {
22672279
assert_eq!(sweep_tx_0.compute_txid(), latest_spending_tx.compute_txid());
@@ -2272,8 +2284,8 @@ mod tests {
22722284
// Check we regenerate and rebroadcast the sweeping tx each block.
22732285
advance_chain(&mut nodes[0], 1);
22742286
assert_eq!(nodes[0].sweeper.tracked_spendable_outputs().len(), 1);
2287+
let sweep_tx_1 = wait_for_sweep_tx();
22752288
let tracked_output = nodes[0].sweeper.tracked_spendable_outputs().first().unwrap().clone();
2276-
let sweep_tx_1 = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().pop().unwrap();
22772289
match tracked_output.status {
22782290
OutputSpendStatus::PendingFirstConfirmation { latest_spending_tx, .. } => {
22792291
assert_eq!(sweep_tx_1.compute_txid(), latest_spending_tx.compute_txid());
@@ -2284,8 +2296,8 @@ mod tests {
22842296

22852297
advance_chain(&mut nodes[0], 1);
22862298
assert_eq!(nodes[0].sweeper.tracked_spendable_outputs().len(), 1);
2299+
let sweep_tx_2 = wait_for_sweep_tx();
22872300
let tracked_output = nodes[0].sweeper.tracked_spendable_outputs().first().unwrap().clone();
2288-
let sweep_tx_2 = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap().pop().unwrap();
22892301
match tracked_output.status {
22902302
OutputSpendStatus::PendingFirstConfirmation { latest_spending_tx, .. } => {
22912303
assert_eq!(sweep_tx_2.compute_txid(), latest_spending_tx.compute_txid());

0 commit comments

Comments
 (0)