From 2ca3eea3f7f175e9557d03908271febc013d397a Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Fri, 29 Oct 2021 09:50:27 +0200 Subject: [PATCH] itest: fix REST WebSocket ping/pong itest This commit fixes a flake in the REST itest that was caused by an invoice being created before the actual subscription client was registered. --- lntest/itest/lnd_rest_api_test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lntest/itest/lnd_rest_api_test.go b/lntest/itest/lnd_rest_api_test.go index 290b9817..c02e7da4 100644 --- a/lntest/itest/lnd_rest_api_test.go +++ b/lntest/itest/lnd_rest_api_test.go @@ -638,6 +638,16 @@ func wsTestPingPongTimeout(ht *harnessTest, net *lntest.NetworkHarness) { } }() + // The SubscribeInvoices call returns immediately after the gRPC/REST + // connection is established. But it can happen that the goroutine in + // lnd that actually registers the subscriber in the invoice backend + // didn't get any CPU time just yet. So we can run into the situation + // where we add our first invoice _before_ the subscription client is + // registered. If that happens, we'll never get notified about the + // invoice in question. So all we really can do is wait a bit here to + // make sure the subscription is registered correctly. + time.Sleep(500 * time.Millisecond) + // Let's create five invoices and wait for them to arrive. We'll wait // for at least one ping/pong cycle between each invoice. ctxb := context.Background()