From cc89b327816bec518c1c72806adcd43d6bd97470 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Tue, 10 Dec 2024 15:43:49 +0800 Subject: [PATCH] itest: fix flake in `testCoopCloseWithExternalDeliveryImpl` The response from `ClosedChannels` may not be up-to-date, so we wrap it inside a wait closure. --- .../lnd_coop_close_external_delivery_test.go | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/itest/lnd_coop_close_external_delivery_test.go b/itest/lnd_coop_close_external_delivery_test.go index 8341a2f650..eea09a48d9 100644 --- a/itest/lnd_coop_close_external_delivery_test.go +++ b/itest/lnd_coop_close_external_delivery_test.go @@ -1,11 +1,13 @@ package itest import ( + "fmt" "testing" "github.com/btcsuite/btcd/btcutil" "github.com/lightningnetwork/lnd/lnrpc" "github.com/lightningnetwork/lnd/lntest" + "github.com/lightningnetwork/lnd/lntest/wait" "github.com/stretchr/testify/require" ) @@ -114,11 +116,20 @@ func testCoopCloseWithExternalDeliveryImpl(ht *lntest.HarnessTest, // assertion. We want to ensure that even though alice's delivery // address is set to an address in bob's wallet, we should still show // the balance as settled. - closed := alice.RPC.ClosedChannels(&lnrpc.ClosedChannelsRequest{ - Cooperative: true, - }) - - // The settled balance should never be zero at this point. - require.NotZero(ht, len(closed.Channels)) - require.NotZero(ht, closed.Channels[0].SettledBalance) + err = wait.NoError(func() error { + closed := alice.RPC.ClosedChannels(&lnrpc.ClosedChannelsRequest{ + Cooperative: true, + }) + + if len(closed.Channels) == 0 { + return fmt.Errorf("expected closed channel not found") + } + + if closed.Channels[0].SettledBalance == 0 { + return fmt.Errorf("expected settled balance to be zero") + } + + return nil + }, defaultTimeout) + require.NoError(ht, err, "timeout checking closed channels") }