Skip to content

Commit 67abaa7

Browse files
committed
improve wait
1 parent 8d6a915 commit 67abaa7

1 file changed

Lines changed: 16 additions & 24 deletions

File tree

verifier/pkg/sourcereader/service_test.go

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1602,25 +1602,19 @@ func TestSRS_EventMonitoringLoop_ContinuesAfterPanic(t *testing.T) {
16021602
require.NoError(t, srs.Close())
16031603
}()
16041604

1605-
// Wait for multiple poll cycles to complete
1606-
// This gives time for:
1607-
// - 1st call: successful processing
1608-
// - 2nd call: panic and recovery
1609-
// - 3rd+ calls: continued processing after panic
1610-
time.Sleep(300 * time.Millisecond)
1611-
1612-
// Verify that the loop continued processing after the panic
1605+
// Wait until we observe at least three LatestAndFinalizedBlock calls:
1606+
// 1) first successful poll, 2) poll that panics (recovered in-loop), 3) post-recovery poll.
1607+
// A fixed sleep is flaky under -race, -short, or slow CI schedulers.
1608+
require.Eventually(t, func() bool {
1609+
mu.Lock()
1610+
defer mu.Unlock()
1611+
return callCount >= 3
1612+
}, tests.WaitTimeout(t), 25*time.Millisecond,
1613+
"eventMonitoringLoop should continue processing after panic recovery")
1614+
16131615
mu.Lock()
16141616
actualCallCount := callCount
16151617
mu.Unlock()
1616-
1617-
// We should have at least 3 calls:
1618-
// 1. First successful call
1619-
// 2. Call that panicked
1620-
// 3. Call(s) after recovery proving the loop continued
1621-
assert.GreaterOrEqual(t, actualCallCount, 3,
1622-
"eventMonitoringLoop should continue processing after panic recovery")
1623-
16241618
t.Logf("LatestAndFinalizedBlock called %d times (including 1 panic)", actualCallCount)
16251619
}
16261620

@@ -1686,18 +1680,16 @@ func TestSRS_EventMonitoringLoop_PanicInProcessEventCycle(t *testing.T) {
16861680
require.NoError(t, srs.Close())
16871681
}()
16881682

1689-
// Wait for multiple poll cycles
1690-
time.Sleep(300 * time.Millisecond)
1683+
require.Eventually(t, func() bool {
1684+
mu.Lock()
1685+
defer mu.Unlock()
1686+
return fetchCallCount >= 3
1687+
}, tests.WaitTimeout(t), 25*time.Millisecond,
1688+
"eventMonitoringLoop should continue processing after panic in processEventCycle")
16911689

1692-
// Verify that the loop continued processing after the panic
16931690
mu.Lock()
16941691
actualFetchCount := fetchCallCount
16951692
mu.Unlock()
1696-
1697-
// Should have at least 3 fetch calls (before, panic, after)
1698-
assert.GreaterOrEqual(t, actualFetchCount, 3,
1699-
"eventMonitoringLoop should continue processing after panic in processEventCycle")
1700-
17011693
t.Logf("FetchMessageSentEvents called %d times (including 1 panic)", actualFetchCount)
17021694
}
17031695

0 commit comments

Comments
 (0)