Skip to content

Commit

Permalink
Fix flaky tracker test (#13870)
Browse files Browse the repository at this point in the history
* Use Eventually instead of Sleep

* Increase tick duration

* Use WaitTimeout
  • Loading branch information
DylanTinianov authored Jul 17, 2024
1 parent 5cfab4f commit 9aef8d5
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions core/chains/evm/txmgr/tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package txmgr_test

import (
"math/big"
"slices"
"testing"
"time"

Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
})
}

0 comments on commit 9aef8d5

Please sign in to comment.