From 785e058b77b0dbebf2e43a5181ad8c5a7bf35497 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Fri, 25 Oct 2024 23:18:16 +0800 Subject: [PATCH] itest: fix flake in `testPaymentFailureReasonCanceled` Fix the case, ``` --- FAIL: TestLightningNetworkDaemon/tranche01/46-of-191/bitcoind/payment_failure_reason_canceled (20.86s) harness.go:2113: Error Trace: /home/runner/work/lnd/lnd/lntest/harness.go:2113 /home/runner/work/lnd/lnd/itest/lnd_payment_test.go:1183 /home/runner/work/lnd/lnd/itest/lnd_payment_test.go:1138 /home/runner/work/lnd/lnd/lntest/harness.go:396 /home/runner/work/lnd/lnd/itest/lnd_test.go:139 Error: err from HTLC interceptor stream Test: TestLightningNetworkDaemon/tranche01/46-of-191/bitcoind/payment_failure_reason_canceled Messages: received err from HTLC interceptor stream: rpc error: code = Unknown desc = interceptor already exists ``` --- itest/lnd_payment_test.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/itest/lnd_payment_test.go b/itest/lnd_payment_test.go index 317ca02eda..e49f5f6fe3 100644 --- a/itest/lnd_payment_test.go +++ b/itest/lnd_payment_test.go @@ -1113,12 +1113,16 @@ func testPaymentFailureReasonCanceled(ht *lntest.HarnessTest) { // Make sure Alice is aware of channel Bob=>Carol. ht.AssertTopologyChannelOpen(alice, cpBC) + // Connect the interceptor. + interceptor, cancelInterceptor := bob.RPC.HtlcInterceptor() + defer cancelInterceptor() + // First we check that the payment is successful when bob resumes the // htlc even though the payment context was canceled before invoice // settlement. sendPaymentInterceptAndCancel( ht, ts, cpAB, routerrpc.ResolveHoldForwardAction_RESUME, - lnrpc.Payment_SUCCEEDED, + lnrpc.Payment_SUCCEEDED, interceptor, ) // Next we check that the context cancellation results in the expected @@ -1128,7 +1132,7 @@ func testPaymentFailureReasonCanceled(ht *lntest.HarnessTest) { // htlc fail case before the htlc resume case. sendPaymentInterceptAndCancel( ht, ts, cpAB, routerrpc.ResolveHoldForwardAction_FAIL, - lnrpc.Payment_FAILED, + lnrpc.Payment_FAILED, interceptor, ) // Finally, close channels. @@ -1139,14 +1143,12 @@ func testPaymentFailureReasonCanceled(ht *lntest.HarnessTest) { func sendPaymentInterceptAndCancel(ht *lntest.HarnessTest, ts *interceptorTestScenario, cpAB *lnrpc.ChannelPoint, interceptorAction routerrpc.ResolveHoldForwardAction, - expectedPaymentStatus lnrpc.Payment_PaymentStatus) { + expectedPaymentStatus lnrpc.Payment_PaymentStatus, + interceptor rpc.InterceptorClient) { // Prepare the test cases. alice, bob, carol := ts.alice, ts.bob, ts.carol - // Connect the interceptor. - interceptor, cancelInterceptor := bob.RPC.HtlcInterceptor() - // Prepare the test cases. addResponse := carol.RPC.AddInvoice(&lnrpc.Invoice{ ValueMsat: 1000, @@ -1208,9 +1210,6 @@ func sendPaymentInterceptAndCancel(ht *lntest.HarnessTest, // should've been made, and we observe FAILURE_REASON_CANCELED. expectedReason := lnrpc.PaymentFailureReason_FAILURE_REASON_CANCELED ht.AssertPaymentFailureReason(alice, preimage, expectedReason) - - // Cancel the context, which will disconnect the above interceptor. - cancelInterceptor() } // testSendToRouteFailHTLCTimeout is similar to