From e3823a51ce5ce522f296306dbcb142dd76a5c07e Mon Sep 17 00:00:00 2001 From: "cursor[bot]" <206951365+cursor[bot]@users.noreply.github.com> Date: Fri, 29 May 2026 12:39:07 +0200 Subject: [PATCH] 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 Co-authored-by: mattermost-code --- server/public/pluginapi/cluster/job_once_test.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/server/public/pluginapi/cluster/job_once_test.go b/server/public/pluginapi/cluster/job_once_test.go index 78c3ea3c7a3..e6aa40a8d7d 100644 --- a/server/public/pluginapi/cluster/job_once_test.go +++ b/server/public/pluginapi/cluster/job_once_test.go @@ -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) {