From 099270c62225f18f75c12eb9773c24746ff8f554 Mon Sep 17 00:00:00 2001 From: Carsten Otto Date: Thu, 15 Feb 2024 22:09:20 +0100 Subject: [PATCH] treat timeout as failure fixes #88 --- .../de/cotto/lndmanagej/pickhardtpayments/PaymentLoop.java | 4 ++-- .../cotto/lndmanagej/pickhardtpayments/PaymentLoopTest.java | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/pickhardt-payments/src/main/java/de/cotto/lndmanagej/pickhardtpayments/PaymentLoop.java b/pickhardt-payments/src/main/java/de/cotto/lndmanagej/pickhardtpayments/PaymentLoop.java index c22c3054..0753ad29 100644 --- a/pickhardt-payments/src/main/java/de/cotto/lndmanagej/pickhardtpayments/PaymentLoop.java +++ b/pickhardt-payments/src/main/java/de/cotto/lndmanagej/pickhardtpayments/PaymentLoop.java @@ -67,7 +67,7 @@ public void start( if (paymentStatus.isFailure() && decodedPaymentRequest.destination().equals(ownPubkey)) { grpcInvoices.cancelPaymentRequest(decodedPaymentRequest); } - if (paymentStatus.isPending() || paymentStatus.isFailure()) { + if (paymentStatus.isFailure()) { grpcSendToRoute.forceFailureForPayment(decodedPaymentRequest); } } @@ -103,7 +103,7 @@ private void start() { loopIterationCounter++; Coins residualAmount = totalAmountToSend.subtract(inFlight); if (Coins.NONE.equals(residualAmount)) { - paymentStatus.info(TIMEOUT_MESSAGE); + paymentStatus.failed(TIMEOUT_MESSAGE); return; } if (shouldAbort(loopIterationCounter)) { diff --git a/pickhardt-payments/src/test/java/de/cotto/lndmanagej/pickhardtpayments/PaymentLoopTest.java b/pickhardt-payments/src/test/java/de/cotto/lndmanagej/pickhardtpayments/PaymentLoopTest.java index bf6949c8..f507aa2a 100644 --- a/pickhardt-payments/src/test/java/de/cotto/lndmanagej/pickhardtpayments/PaymentLoopTest.java +++ b/pickhardt-payments/src/test/java/de/cotto/lndmanagej/pickhardtpayments/PaymentLoopTest.java @@ -265,10 +265,8 @@ void aborts_for_stuck_pending_amount() { .thenReturn(Coins.NONE) .thenReturn(DECODED_PAYMENT_REQUEST.amount()); paymentLoop.start(DECODED_PAYMENT_REQUEST, PAYMENT_OPTIONS, paymentStatus); - SoftAssertions softly = new SoftAssertions(); - softly.assertThat(paymentStatus.isSuccess()).isFalse(); - softly.assertThat(paymentStatus.isFailure()).isFalse(); - softly.assertAll(); + // it's not strictly a failure, but we need to complete the flux/stream (see #88) + assertThat(paymentStatus.isFailure()).isTrue(); verify(grpcSendToRoute).forceFailureForPayment(DECODED_PAYMENT_REQUEST); }