mirror of
https://github.com/mattermost/mattermost.git
synced 2026-08-29 02:28:16 +08:00
Fix flaky TestScheduleOnceSequential (#36805)
The subtest used a fixed sleep before asserting callback counts, but job.run waits until runAt plus up to scheduleOnceJitter. Under the race detector or loaded CI that window can elapse after the sleep, so newCount3 is still 0 and the assertion flakes. Poll with require.Eventually (same approach as the paging subtest in #35891) so the test waits for the scheduled callback without weakening assertions. Tests-only change. Verified with: go test -run '^TestScheduleOnceSequential$/adding_two_callback_works' \ -race -count=100 ./pluginapi/cluster/... (from server/public) Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: mattermost-code <matty-code@mattermost.com>
This commit is contained in:
@@ -300,9 +300,13 @@ func TestScheduleOnceSequential(t *testing.T) {
|
||||
|
||||
_, err = s.ScheduleOnce("anything", time.Now().Add(50*time.Millisecond), nil)
|
||||
require.NoError(t, err)
|
||||
time.Sleep(70*time.Millisecond + scheduleOnceJitter)
|
||||
assert.Equal(t, int32(0), atomic.LoadInt32(newCount2))
|
||||
assert.Equal(t, int32(1), atomic.LoadInt32(newCount3))
|
||||
|
||||
// Poll for the scheduled callback. A fixed sleep is flaky under the race
|
||||
// detector and on loaded CI because job.run adds up to scheduleOnceJitter
|
||||
// on top of the scheduled delay.
|
||||
require.Eventually(t, func() bool {
|
||||
return atomic.LoadInt32(newCount2) == int32(0) && atomic.LoadInt32(newCount3) == int32(1)
|
||||
}, 5*time.Second, 50*time.Millisecond, "timed out waiting for scheduled callback")
|
||||
})
|
||||
|
||||
t.Run("test paging keys from the db by inserting 3 pages of jobs and starting scheduler", func(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user