From 19680340759703b75cad6c0f12ae6970f0165248 Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Thu, 24 Aug 2023 23:01:27 +0800 Subject: [PATCH] chainntnfs: fix `testHistoricalConfDetailsTxIndex` Fix the following uint test flake, ``` --- FAIL: TestHistoricalConfDetailsTxIndex (0.00s) --- FAIL: TestHistoricalConfDetailsTxIndex/rpc_polling_enabled (1.16s) bitcoind_test.go:174: should have found the transaction within the mempool, but did not: TxNotFoundIndex FAIL ``` --- chainntnfs/bitcoindnotify/bitcoind_test.go | 27 +++++++++++++--------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/chainntnfs/bitcoindnotify/bitcoind_test.go b/chainntnfs/bitcoindnotify/bitcoind_test.go index 124872de0..3eefe8e32 100644 --- a/chainntnfs/bitcoindnotify/bitcoind_test.go +++ b/chainntnfs/bitcoindnotify/bitcoind_test.go @@ -5,6 +5,7 @@ package bitcoindnotify import ( "bytes" + "fmt" "testing" "time" @@ -14,6 +15,7 @@ import ( "github.com/lightningnetwork/lnd/blockcache" "github.com/lightningnetwork/lnd/chainntnfs" "github.com/lightningnetwork/lnd/channeldb" + "github.com/lightningnetwork/lnd/lntest/wait" "github.com/stretchr/testify/require" ) @@ -162,18 +164,21 @@ func testHistoricalConfDetailsTxIndex(t *testing.T, rpcPolling bool) { confReq, err := chainntnfs.NewConfRequest(txid, pkScript) require.NoError(t, err, "unable to create conf request") - // The transaction should be found in the mempool at this point. - _, txStatus, err = notifier.historicalConfDetails(confReq, 0, 0) - require.NoError(t, err, "unable to retrieve historical conf details") + // The transaction should be found in the mempool at this point. We use + // wait here to give miner some time to propagate the tx to our node. + err = wait.NoError(func() error { + // The call should return no error. + _, txStatus, err = notifier.historicalConfDetails(confReq, 0, 0) + require.NoError(t, err) - // Since it has yet to be included in a block, it should have been found - // within the mempool. - switch txStatus { - case chainntnfs.TxFoundMempool: - default: - t.Fatalf("should have found the transaction within the "+ - "mempool, but did not: %v", txStatus) - } + if txStatus != chainntnfs.TxFoundMempool { + return fmt.Errorf("cannot the tx in mempool, status "+ + "is: %v", txStatus) + } + + return nil + }, wait.DefaultTimeout) + require.NoError(t, err, "timeout waitinfg for historicalConfDetails") if _, err := miner.Client.Generate(1); err != nil { t.Fatalf("unable to generate block: %v", err)