Skip to content

Commit 4430487

Browse files
committed
itest: fix flake in testCoopCloseWithExternalDeliveryImpl
The response from `ClosedChannels` may not be up-to-date, so we wrap it inside a wait closure.
1 parent 994f434 commit 4430487

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

itest/lnd_coop_close_external_delivery_test.go

+18-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package itest
22

33
import (
4+
"fmt"
45
"testing"
56

67
"github.com/btcsuite/btcd/btcutil"
78
"github.com/lightningnetwork/lnd/lnrpc"
89
"github.com/lightningnetwork/lnd/lntest"
10+
"github.com/lightningnetwork/lnd/lntest/wait"
911
"github.com/stretchr/testify/require"
1012
)
1113

@@ -114,11 +116,20 @@ func testCoopCloseWithExternalDeliveryImpl(ht *lntest.HarnessTest,
114116
// assertion. We want to ensure that even though alice's delivery
115117
// address is set to an address in bob's wallet, we should still show
116118
// the balance as settled.
117-
closed := alice.RPC.ClosedChannels(&lnrpc.ClosedChannelsRequest{
118-
Cooperative: true,
119-
})
120-
121-
// The settled balance should never be zero at this point.
122-
require.NotZero(ht, len(closed.Channels))
123-
require.NotZero(ht, closed.Channels[0].SettledBalance)
119+
err = wait.NoError(func() error {
120+
closed := alice.RPC.ClosedChannels(&lnrpc.ClosedChannelsRequest{
121+
Cooperative: true,
122+
})
123+
124+
if len(closed.Channels) == 0 {
125+
return fmt.Errorf("expected closed channel not found")
126+
}
127+
128+
if closed.Channels[0].SettledBalance == 0 {
129+
return fmt.Errorf("expected settled balance to be zero")
130+
}
131+
132+
return nil
133+
}, defaultTimeout)
134+
require.NoError(ht, err, "timeout checking closed channels")
124135
}

0 commit comments

Comments
 (0)