Skip to content

Commit 1db110f

Browse files
committed
itest: fix flake in testFundingExpiryBlocksOnPending
We need to make sure to wait for the RPC to show the updated results.
1 parent d122a2e commit 1db110f

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

itest/lnd_open_channel_test.go

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,24 @@ func testFundingExpiryBlocksOnPending(ht *lntest.HarnessTest) {
837837
param := lntest.OpenChannelParams{Amt: 100000}
838838
ht.OpenChannelAssertPending(alice, bob, param)
839839

840+
// assertExpiry is a helper closure to assert the FundingExpiryBlocks
841+
// has been updated to the expected value.
842+
assertExpiry := func(hn *node.HarnessNode, expected int32) {
843+
err := wait.NoError(func() error {
844+
pending := ht.AssertNumPendingOpenChannels(hn, 1)
845+
expiry := pending[0].FundingExpiryBlocks
846+
847+
// Exit early if matched.
848+
if expected == expiry {
849+
return nil
850+
}
851+
852+
return fmt.Errorf("want %v, got %v", expected, expiry)
853+
}, wait.DefaultTimeout)
854+
require.NoErrorf(ht, err, "%s: assert FundingExpiryBlocks "+
855+
"timeout", hn.Name())
856+
}
857+
840858
// At this point, the channel's funding transaction will have been
841859
// broadcast, but not confirmed. Alice and Bob's nodes should reflect
842860
// this when queried via RPC. FundingExpiryBlock should decrease
@@ -846,15 +864,16 @@ func testFundingExpiryBlocksOnPending(ht *lntest.HarnessTest) {
846864
const numEmptyBlocks = 3
847865
for i := int32(0); i < numEmptyBlocks; i++ {
848866
expectedVal := lncfg.DefaultMaxWaitNumBlocksFundingConf - i
849-
pending := ht.AssertNumPendingOpenChannels(alice, 1)
850-
require.Equal(ht, expectedVal, pending[0].FundingExpiryBlocks)
851-
pending = ht.AssertNumPendingOpenChannels(bob, 1)
852-
require.Equal(ht, expectedVal, pending[0].FundingExpiryBlocks)
867+
868+
// Assert Alice and Bob have updated the FundingExpiryBlocks.
869+
assertExpiry(alice, expectedVal)
870+
assertExpiry(bob, expectedVal)
871+
853872
ht.MineEmptyBlocks(1)
854873
}
855874

856-
// Mine 1 block to confirm the funding transaction, and then close the
857-
// channel.
875+
// Mine 1 block to confirm the funding transaction so clean up the
876+
// mempool.
858877
ht.MineBlocksAndAssertNumTxes(1, 1)
859878
}
860879

0 commit comments

Comments
 (0)