From fc3db04218941d0da8b02ddf5fac6e060730f3f9 Mon Sep 17 00:00:00 2001 From: Eduardo Apolinario <653394+eapolinario@users.noreply.github.com> Date: Mon, 15 May 2023 21:32:39 -0700 Subject: [PATCH] Fix flaky test (#563) --- tests/scheduler_test.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/scheduler_test.go b/tests/scheduler_test.go index 1e792966c..caa6081d0 100644 --- a/tests/scheduler_test.go +++ b/tests/scheduler_test.go @@ -59,15 +59,19 @@ func TestScheduleJob(t *testing.T) { lastExecTime *time.Time assertionFunc func(t assert.TestingT, expected, actual interface{}, msgAndArgs ...interface{}) bool }{ - {testName: "using_schedule_time", lastExecTime: &now, assertionFunc: assert.Equal}, - {testName: "without_schedule_time", lastExecTime: nil, assertionFunc: assert.NotEqual}, + {testName: "without_schedule_time", lastExecTime: nil}, + {testName: "using_schedule_time", lastExecTime: &now}, } wg := &sync.WaitGroup{} for _, tc := range tests { t.Run(tc.testName, func(t *testing.T) { wg.Add(1) timedFuncWithSchedule := func(jobCtx context.Context, schedule models.SchedulableEntity, scheduleTime time.Time) error { - tc.assertionFunc(t, now, scheduleTime) + if scheduleTime.IsZero() { + assert.NotEqual(t, now, scheduleTime) + } else { + assert.WithinDuration(t, now, scheduleTime, time.Minute*2) + } wg.Done() return nil }