Skip to content

Commit 837671a

Browse files
authored
verifier: fix TestSRS_Readiness_CustomFinality_ReadyAgainstLatest flake (#508)
* Switch to tests.WaitTimeout(t) instead of a hardcoded 1 second timeout * Switch to tests.WaitTimeout(t) wherever we have a custom waitTimeout(t) defined to reduce duplication.
1 parent 74e8951 commit 837671a

File tree

6 files changed

+21
-39
lines changed

6 files changed

+21
-39
lines changed

build/devenv/tests/e2e/chaos_test.go

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/smartcontractkit/chainlink-ccv/devenv/cciptestinterfaces"
1414
"github.com/smartcontractkit/chainlink-ccv/devenv/evm"
1515
"github.com/smartcontractkit/chainlink-ccv/devenv/services"
16+
"github.com/smartcontractkit/chainlink-common/pkg/utils/tests"
1617
"github.com/smartcontractkit/chainlink-testing-framework/framework"
1718
"github.com/smartcontractkit/chainlink-testing-framework/framework/chaos"
1819
)
@@ -60,7 +61,7 @@ func TestChaos_AggregatorOutageRecovery(t *testing.T) {
6061

6162
runV2TestCase(t, tc, setup.chainMap, setup.defaultAggregatorClient, setup.indexerClient, AssertMessageOptions{
6263
TickInterval: 5 * time.Second,
63-
Timeout: waitTimeout(t),
64+
Timeout: tests.WaitTimeout(t),
6465
ExpectedVerifierResults: tc.numExpectedVerifications,
6566
AssertVerifierLogs: false,
6667
AssertExecutorLogs: false,
@@ -136,7 +137,7 @@ func TestChaos_VerifierFaultToleranceThresholdViolated(t *testing.T) {
136137
setup.indexerClient,
137138
AssertMessageOptions{
138139
TickInterval: 5 * time.Second,
139-
Timeout: waitTimeout(t),
140+
Timeout: tests.WaitTimeout(t),
140141
ExpectedVerifierResults: tc.numExpectedVerifications,
141142
AssertVerifierLogs: false,
142143
AssertExecutorLogs: false,
@@ -179,7 +180,7 @@ func TestChaos_AllExecutorsDown(t *testing.T) {
179180

180181
runV2TestCase(t, tc, setup.chainMap, setup.defaultAggregatorClient, setup.indexerClient, AssertMessageOptions{
181182
TickInterval: 5 * time.Second,
182-
Timeout: waitTimeout(t),
183+
Timeout: tests.WaitTimeout(t),
183184
ExpectedVerifierResults: tc.numExpectedVerifications,
184185
AssertVerifierLogs: false,
185186
AssertExecutorLogs: false,
@@ -216,21 +217,13 @@ func TestChaos_IndexerDown(t *testing.T) {
216217

217218
runV2TestCase(t, tc, setup.chainMap, setup.defaultAggregatorClient, setup.indexerClient, AssertMessageOptions{
218219
TickInterval: 5 * time.Second,
219-
Timeout: waitTimeout(t),
220+
Timeout: tests.WaitTimeout(t),
220221
ExpectedVerifierResults: tc.numExpectedVerifications,
221222
AssertVerifierLogs: false,
222223
AssertExecutorLogs: false,
223224
})
224225
}
225226

226-
func waitTimeout(t *testing.T) time.Duration {
227-
deadline, ok := t.Deadline()
228-
if !ok {
229-
deadline = time.Now().Add(10 * time.Second)
230-
}
231-
return time.Until(deadline)
232-
}
233-
234227
type chaosSetup struct {
235228
in *ccv.Cfg
236229
chains []ccv.ChainImpl

indexer/pkg/readers/verifier_reader_test.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/smartcontractkit/chainlink-ccv/indexer/pkg/common"
1313
"github.com/smartcontractkit/chainlink-ccv/indexer/pkg/config"
1414
"github.com/smartcontractkit/chainlink-ccv/protocol"
15+
"github.com/smartcontractkit/chainlink-common/pkg/utils/tests"
1516
)
1617

1718
// mockVerifierResultsAPI is a simple mock implementation of VerifierResultsAPI for testing.
@@ -167,7 +168,7 @@ func TestVerifierReader_Run_ProcessesBatches(t *testing.T) {
167168
default:
168169
return false
169170
}
170-
}, waitTimeout(t), 50*time.Millisecond, "waiting for result1")
171+
}, tests.WaitTimeout(t), 50*time.Millisecond, "waiting for result1")
171172
assert.Equal(t, ccvData1, result1.Value())
172173
assert.NoError(t, result1.Err())
173174

@@ -180,7 +181,7 @@ func TestVerifierReader_Run_ProcessesBatches(t *testing.T) {
180181
default:
181182
return false
182183
}
183-
}, waitTimeout(t), 50*time.Millisecond, "waiting for result2")
184+
}, tests.WaitTimeout(t), 50*time.Millisecond, "waiting for result2")
184185
assert.Equal(t, ccvData2, result2.Value())
185186
assert.NoError(t, result2.Err())
186187

@@ -365,11 +366,3 @@ func TestVerifierReader_Run_ChannelClosed(t *testing.T) {
365366
// Wait for run goroutine to finish
366367
reader.runWg.Wait()
367368
}
368-
369-
func waitTimeout(t *testing.T) time.Duration {
370-
deadline, ok := t.Deadline()
371-
if !ok {
372-
deadline = time.Now().Add(10 * time.Second)
373-
}
374-
return time.Until(deadline)
375-
}

verifier/source_reader_service_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212

1313
ccv_common "github.com/smartcontractkit/chainlink-ccv/common"
1414
"github.com/smartcontractkit/chainlink-ccv/protocol"
15+
"github.com/smartcontractkit/chainlink-common/pkg/utils/tests"
1516

1617
protocol_mocks "github.com/smartcontractkit/chainlink-ccv/protocol/common/mocks"
1718
)
@@ -437,7 +438,7 @@ func TestSRS_Readiness_CustomFinality_ReadyAgainstLatest(t *testing.T) {
437438
require.NoError(t, batch.Error)
438439
require.Len(t, batch.Items, 1)
439440
require.Equal(t, task.MessageID, batch.Items[0].MessageID)
440-
case <-time.After(time.Second):
441+
case <-time.After(tests.WaitTimeout(t)):
441442
t.Fatal("timed out waiting for readyTasks batch")
442443
}
443444
}

verifier/task_verifier_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/smartcontractkit/chainlink-ccv/verifier"
1414
"github.com/smartcontractkit/chainlink-ccv/verifier/pkg/monitoring"
1515
"github.com/smartcontractkit/chainlink-common/pkg/logger"
16+
"github.com/smartcontractkit/chainlink-common/pkg/utils/tests"
1617
)
1718

1819
func Test_ProcessingReadyTasks(t *testing.T) {
@@ -26,7 +27,7 @@ func Test_ProcessingReadyTasks(t *testing.T) {
2627

2728
fanoutCh := make(chan batcher.BatchResult[verifier.VerificationTask], 10)
2829
fakeFanout := FakeSourceReaderFanout{
29-
batcher: batcher.NewBatcher[verifier.VerificationTask](
30+
batcher: batcher.NewBatcher(
3031
t.Context(),
3132
2,
3233
100*time.Millisecond,
@@ -36,7 +37,7 @@ func Test_ProcessingReadyTasks(t *testing.T) {
3637
}
3738

3839
storageOutCh := make(chan batcher.BatchResult[protocol.VerifierNodeResult], 10)
39-
storageBatcher := batcher.NewBatcher[protocol.VerifierNodeResult](
40+
storageBatcher := batcher.NewBatcher(
4041
t.Context(),
4142
2,
4243
100*time.Millisecond,
@@ -86,7 +87,7 @@ func Test_ProcessingReadyTasks(t *testing.T) {
8687
require.Eventually(t, func() bool {
8788
return mockVerifier.Attempt(task1.MessageID) >= 3 &&
8889
mockVerifier.Attempt(task2.MessageID) >= 3
89-
}, waitTimeout(t), 10*time.Millisecond)
90+
}, tests.WaitTimeout(t), 10*time.Millisecond)
9091

9192
select {
9293
case res, ok := <-storageOutCh:

verifier/verification_coordinator_cctp_test.go

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/smartcontractkit/chainlink-ccv/verifier/pkg/monitoring"
2020
"github.com/smartcontractkit/chainlink-ccv/verifier/token/cctp"
2121
"github.com/smartcontractkit/chainlink-ccv/verifier/token/storage"
22+
"github.com/smartcontractkit/chainlink-common/pkg/utils/tests"
2223
)
2324

2425
var (
@@ -235,7 +236,7 @@ func Test_CCTPMessages_SingleSource(t *testing.T) {
235236
return false
236237
}
237238
return len(results) == 2
238-
}, waitTimeout(t), 500*time.Millisecond, "waiting for messages to land in ccv storage")
239+
}, tests.WaitTimeout(t), 500*time.Millisecond, "waiting for messages to land in ccv storage")
239240

240241
assertResultMatchesMessage(t, results[msg1.MessageID], msg1, ccvData1, testCCVAddr, destVerifier)
241242
assertResultMatchesMessage(t, results[msg2.MessageID], msg2, ccvData2, testCCVAddr, destVerifier)
@@ -335,7 +336,7 @@ func Test_CCTPMessages_MultipleSources(t *testing.T) {
335336
return false
336337
}
337338
return len(results) == 2
338-
}, waitTimeout(t), 500*time.Millisecond, "waiting for messages to land in ccv storage")
339+
}, tests.WaitTimeout(t), 500*time.Millisecond, "waiting for messages to land in ccv storage")
339340

340341
assertResultMatchesMessage(t, results[msg1337.MessageID], msg1337, ccvData1, testCCVAddr, destVerifier)
341342
assertResultMatchesMessage(t, results[msg2337.MessageID], msg2337, ccvData2, destVerifier, testCCVAddr)
@@ -425,7 +426,7 @@ func Test_CCTPMessages_RetryingAttestation(t *testing.T) {
425426
return false
426427
}
427428
return len(results) == 1
428-
}, waitTimeout(t), 200*time.Millisecond, "waiting for messages to land in ccv storage")
429+
}, tests.WaitTimeout(t), 200*time.Millisecond, "waiting for messages to land in ccv storage")
429430

430431
assertResultMatchesMessage(t, results[msg.MessageID], msg, ccvData, testCCVAddr, destVerifier)
431432
}
@@ -479,14 +480,6 @@ func createCCTPCoordinator(
479480
)
480481
}
481482

482-
func waitTimeout(t *testing.T) time.Duration {
483-
deadline, ok := t.Deadline()
484-
if !ok {
485-
deadline = time.Now().Add(10 * time.Second)
486-
}
487-
return time.Until(deadline)
488-
}
489-
490483
type attestationMock struct {
491484
domainID int
492485
txHash protocol.ByteSlice

verifier/verification_coordinator_lbtc_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/stretchr/testify/require"
1717

1818
"github.com/smartcontractkit/chainlink-ccv/protocol"
19+
"github.com/smartcontractkit/chainlink-common/pkg/utils/tests"
1920
)
2021

2122
// Please see lbtc/attestation.go to see how the CCV data is created and how TokenTransfer.ExtraData is used
@@ -138,7 +139,7 @@ func Test_LBTCMessages_Success(t *testing.T) {
138139
return false
139140
}
140141
return len(results) == 2
141-
}, waitTimeout(t), 500*time.Millisecond, "waiting for messages to land in ccv storage")
142+
}, tests.WaitTimeout(t), 500*time.Millisecond, "waiting for messages to land in ccv storage")
142143

143144
assertResultMatchesMessage(t, results[msg1.MessageID], msg1, ccvData1, testCCVAddr, destVerifier)
144145
assertResultMatchesMessage(t, results[msg2.MessageID], msg2, ccvData2, testCCVAddr, destVerifier)
@@ -240,7 +241,7 @@ func Test_LBTCMessages_RetryingAttestation(t *testing.T) {
240241
return false
241242
}
242243
return len(results) == 2
243-
}, waitTimeout(t), 200*time.Millisecond, "waiting for messages to land in ccv storage")
244+
}, tests.WaitTimeout(t), 200*time.Millisecond, "waiting for messages to land in ccv storage")
244245

245246
assertResultMatchesMessage(t, results[msg1.MessageID], msg1, ccvData1, testCCVAddr, destVerifier)
246247
assertResultMatchesMessage(t, results[msg2.MessageID], msg2, ccvData2, testCCVAddr, destVerifier)

0 commit comments

Comments
 (0)