From 3827d15ca66fc2aea0ffe0cbf4f89c1d19603a87 Mon Sep 17 00:00:00 2001 From: Joost Jager Date: Tue, 14 Sep 2021 15:01:28 +0200 Subject: [PATCH] lntest/itest: fix SendPaymentAMP test --- docs/release-notes/release-notes-0.14.0.md | 2 ++ lntest/itest/lnd_amp_test.go | 16 +++++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/docs/release-notes/release-notes-0.14.0.md b/docs/release-notes/release-notes-0.14.0.md index e7e351d45..f36fd6214 100644 --- a/docs/release-notes/release-notes-0.14.0.md +++ b/docs/release-notes/release-notes-0.14.0.md @@ -225,6 +225,8 @@ you. * [Fixed restore backup file test flake with bitcoind](https://github.com/lightningnetwork/lnd/pull/5637). +* [Timing fix in AMP itest](https://github.com/lightningnetwork/lnd/pull/5725) + ## Database * [Ensure single writer for legacy diff --git a/lntest/itest/lnd_amp_test.go b/lntest/itest/lnd_amp_test.go index 505255e95..5921304ef 100644 --- a/lntest/itest/lnd_amp_test.go +++ b/lntest/itest/lnd_amp_test.go @@ -38,6 +38,15 @@ func testSendPaymentAMPInvoiceCase(net *lntest.NetworkHarness, t *harnessTest, ctx := newMppTestContext(t, net) defer ctx.shutdownNodes() + // Subscribe to bob's invoices. Do this early in the test to make sure + // that the subscription has actually been completed when we add an + // invoice. Otherwise the notification will be missed. + req := &lnrpc.InvoiceSubscription{} + ctxc, cancelSubscription := context.WithCancel(ctxb) + bobInvoiceSubscription, err := ctx.bob.SubscribeInvoices(ctxc, req) + require.NoError(t.t, err) + defer cancelSubscription() + const paymentAmt = btcutil.Amount(300000) // Set up a network with three different paths Alice <-> Bob. Channel @@ -61,13 +70,6 @@ func testSendPaymentAMPInvoiceCase(net *lntest.NetworkHarness, t *harnessTest, ctx.waitForChannels() - // Subscribe to bob's invoices. - req := &lnrpc.InvoiceSubscription{} - ctxc, cancelSubscription := context.WithCancel(ctxb) - bobInvoiceSubscription, err := ctx.bob.SubscribeInvoices(ctxc, req) - require.NoError(t.t, err) - defer cancelSubscription() - addInvoiceResp, err := ctx.bob.AddInvoice(context.Background(), &lnrpc.Invoice{ Value: int64(paymentAmt), IsAmp: true,