Skip to content

Commit df2bb05

Browse files
committed
Fix dummy wallet test stalls
The dummy trusted wallet can miss payment wakeups or leave the rebalancer waiting after a failed LDK payment. Bound the dummy payment wait path and route test-only LDK shutdown through async timeouts so failures surface as test errors instead of CI stalls.
1 parent 18cde83 commit df2bb05

3 files changed

Lines changed: 35 additions & 10 deletions

File tree

orange-sdk/src/trusted_wallet/dummy.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ impl DummyTrustedWallet {
166166
.await
167167
.unwrap();
168168
}
169+
170+
let _ = payment_success_sender.send(());
169171
},
170172
Event::PaymentReceived { payment_id, amount_msat, payment_hash, .. } => {
171173
// convert id
@@ -258,10 +260,8 @@ impl DummyTrustedWallet {
258260
DummyTrustedWallet { current_bal_msats, payments, ldk_node, payment_success_flag }
259261
}
260262

261-
pub(crate) async fn await_payment_success(&self) {
262-
let mut flag = self.payment_success_flag.clone();
263-
flag.mark_unchanged();
264-
let _ = flag.changed().await;
263+
fn payment_wait_timeout() -> Duration {
264+
if std::env::var("CI").is_ok() { Duration::from_secs(120) } else { Duration::from_secs(20) }
265265
}
266266
}
267267

@@ -384,6 +384,8 @@ impl TrustedWalletInterface for DummyTrustedWallet {
384384
) -> Pin<Box<dyn Future<Output = Option<ReceivedLightningPayment>> + Send + '_>> {
385385
Box::pin(async move {
386386
let id = channelmanager::PaymentId(payment_hash);
387+
let mut flag = self.payment_success_flag.clone();
388+
flag.mark_unchanged();
387389
loop {
388390
if let Some(payment) = self.ldk_node.payment(&id) {
389391
let counterparty_skimmed_fee_msat = match payment.kind {
@@ -408,7 +410,12 @@ impl TrustedWalletInterface for DummyTrustedWallet {
408410
PaymentStatus::Failed => return None,
409411
}
410412
}
411-
self.await_payment_success().await;
413+
if !matches!(
414+
tokio::time::timeout(Self::payment_wait_timeout(), flag.changed()).await,
415+
Ok(Ok(()))
416+
) {
417+
return None;
418+
}
412419
}
413420
})
414421
}

orange-sdk/tests/integration_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2208,7 +2208,7 @@ async fn test_lsp_connectivity_fallback() {
22082208
assert!(!uri_with_lsp.from_trusted);
22092209

22102210
// Now simulate LSP being offline by stopping it
2211-
let _ = lsp.stop();
2211+
test_utils::stop_ldk_node("lsp", Arc::clone(&lsp)).await;
22122212

22132213
// Wait a moment for the stop to take effect
22142214
tokio::time::sleep(Duration::from_secs(2)).await;

orange-sdk/tests/test_utils.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ pub struct TestParams {
267267

268268
impl TestParams {
269269
async fn stop(&self) {
270-
self.wallet.stop().await;
270+
stop_wallet("wallet", Arc::clone(&self.wallet)).await;
271271

272272
#[cfg(feature = "_cashu-tests")]
273273
let _ = self._mint.stop().await;
@@ -279,7 +279,25 @@ impl TestParams {
279279
}
280280
}
281281

282-
async fn stop_ldk_node(name: &'static str, node: Arc<Node>) {
282+
async fn stop_wallet(name: &'static str, wallet: Arc<orange_sdk::Wallet>) {
283+
let (sender, receiver) = tokio::sync::oneshot::channel();
284+
std::thread::spawn(move || {
285+
let res = tokio::runtime::Builder::new_multi_thread()
286+
.enable_all()
287+
.build()
288+
.map(|runtime| runtime.block_on(async move { wallet.stop().await }));
289+
if let Err(e) = res {
290+
eprintln!("Warning: failed to create runtime for {name} stop: {e}");
291+
}
292+
let _ = sender.send(());
293+
});
294+
295+
if tokio::time::timeout(Duration::from_secs(20), receiver).await.is_err() {
296+
eprintln!("Warning: {name} stop timed out");
297+
}
298+
}
299+
300+
pub(crate) async fn stop_ldk_node(name: &'static str, node: Arc<Node>) {
283301
let (sender, receiver) = tokio::sync::oneshot::channel();
284302
std::thread::spawn(move || {
285303
let _ = node.stop();
@@ -317,13 +335,13 @@ where
317335
res = &mut test_task => Ok(res),
318336
_ = tokio::time::sleep(test_timeout) => {
319337
test_task.abort();
320-
let _ = test_task.await;
338+
let _ = tokio::time::timeout(Duration::from_secs(5), &mut test_task).await;
321339
Err(())
322340
},
323341
};
324342

325343
// Always clean up
326-
let timeout = Duration::from_secs(30);
344+
let timeout = Duration::from_secs(45);
327345
if tokio::time::timeout(timeout, params.stop()).await.is_err() {
328346
eprintln!("Warning: params stop timed out after {timeout:?}");
329347
}

0 commit comments

Comments
 (0)