From 95cd37ef964a19c3a41c4ac5c9f9e85fc62dd89e Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Mon, 10 Mar 2025 15:42:23 +0800 Subject: [PATCH] itest: fix flake in `testFundingExpiryBlocksOnPending` We need to make sure to wait for the RPC to show the updated results. --- itest/lnd_open_channel_test.go | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/itest/lnd_open_channel_test.go b/itest/lnd_open_channel_test.go index e46acd682..9377fd4d8 100644 --- a/itest/lnd_open_channel_test.go +++ b/itest/lnd_open_channel_test.go @@ -837,6 +837,24 @@ func testFundingExpiryBlocksOnPending(ht *lntest.HarnessTest) { param := lntest.OpenChannelParams{Amt: 100000} ht.OpenChannelAssertPending(alice, bob, param) + // assertExpiry is a helper closure to assert the FundingExpiryBlocks + // has been updated to the expected value. + assertExpiry := func(hn *node.HarnessNode, expected int32) { + err := wait.NoError(func() error { + pending := ht.AssertNumPendingOpenChannels(hn, 1) + expiry := pending[0].FundingExpiryBlocks + + // Exit early if matched. + if expected == expiry { + return nil + } + + return fmt.Errorf("want %v, got %v", expected, expiry) + }, wait.DefaultTimeout) + require.NoErrorf(ht, err, "%s: assert FundingExpiryBlocks "+ + "timeout", hn.Name()) + } + // At this point, the channel's funding transaction will have been // broadcast, but not confirmed. Alice and Bob's nodes should reflect // this when queried via RPC. FundingExpiryBlock should decrease @@ -846,15 +864,16 @@ func testFundingExpiryBlocksOnPending(ht *lntest.HarnessTest) { const numEmptyBlocks = 3 for i := int32(0); i < numEmptyBlocks; i++ { expectedVal := lncfg.DefaultMaxWaitNumBlocksFundingConf - i - pending := ht.AssertNumPendingOpenChannels(alice, 1) - require.Equal(ht, expectedVal, pending[0].FundingExpiryBlocks) - pending = ht.AssertNumPendingOpenChannels(bob, 1) - require.Equal(ht, expectedVal, pending[0].FundingExpiryBlocks) + + // Assert Alice and Bob have updated the FundingExpiryBlocks. + assertExpiry(alice, expectedVal) + assertExpiry(bob, expectedVal) + ht.MineEmptyBlocks(1) } - // Mine 1 block to confirm the funding transaction, and then close the - // channel. + // Mine 1 block to confirm the funding transaction so clean up the + // mempool. ht.MineBlocksAndAssertNumTxes(1, 1) }