From 9aef8d5fe1420eb503eef6e96c9471140dd9488c Mon Sep 17 00:00:00 2001 From: Dylan Tinianov Date: Wed, 17 Jul 2024 12:47:00 -0400 Subject: [PATCH] Fix flaky tracker test (#13870) * Use Eventually instead of Sleep * Increase tick duration * Use WaitTimeout --- core/chains/evm/txmgr/tracker_test.go | 29 +++++++++++++++------------ 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/core/chains/evm/txmgr/tracker_test.go b/core/chains/evm/txmgr/tracker_test.go index 904a10d48c3..3e5ab6ed2ef 100644 --- a/core/chains/evm/txmgr/tracker_test.go +++ b/core/chains/evm/txmgr/tracker_test.go @@ -2,6 +2,7 @@ package txmgr_test import ( "math/big" + "slices" "testing" "time" @@ -19,8 +20,6 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/internal/testutils/pgtest" ) -const waitTime = 5 * time.Millisecond - func newTestEvmTrackerSetup(t *testing.T) (*txmgr.Tracker, txmgr.TestEvmTxStore, keystore.Eth, []common.Address) { db := pgtest.NewSqlxDB(t) txStore := cltest.NewTestTxStore(t, db) @@ -81,11 +80,12 @@ func TestEvmTracker_AddressTracking(t *testing.T) { require.NoError(t, err) }(tracker) - time.Sleep(waitTime) - addrs := tracker.GetAbandonedAddresses() - require.NotContains(t, addrs, inProgressAddr) - require.NotContains(t, addrs, unstartedAddr) - require.Contains(t, addrs, unconfirmedAddr) + require.Eventually(t, func() bool { + addrs := tracker.GetAbandonedAddresses() + return !slices.Contains(addrs, inProgressAddr) && + !slices.Contains(addrs, unstartedAddr) && + slices.Contains(addrs, unconfirmedAddr) + }, tests.WaitTimeout(t), 100*time.Millisecond) }) /* TODO: finalized tx state https://smartcontract-it.atlassian.net/browse/BCI-2920 @@ -137,12 +137,15 @@ func TestEvmTracker_ExceedingTTL(t *testing.T) { require.NoError(t, err) }(tracker) - time.Sleep(100 * waitTime) - require.NotContains(t, tracker.GetAbandonedAddresses(), addr1, addr2) + require.Eventually(t, func() bool { + addrs := tracker.GetAbandonedAddresses() + return !slices.Contains(addrs, addr1) && !slices.Contains(addrs, addr2) + }, tests.WaitTimeout(t), 100*time.Millisecond) - fatalTxes, err := txStore.GetFatalTransactions(ctx) - require.NoError(t, err) - require.True(t, containsID(fatalTxes, tx1.ID)) - require.True(t, containsID(fatalTxes, tx2.ID)) + require.Eventually(t, func() bool { + fatalTxes, err := txStore.GetFatalTransactions(ctx) + require.NoError(t, err) + return containsID(fatalTxes, tx1.ID) && containsID(fatalTxes, tx2.ID) + }, tests.WaitTimeout(t), 100*time.Millisecond) }) }