Skip to content
This repository has been archived by the owner on Oct 9, 2023. It is now read-only.

Commit

Permalink
Fix flaky test (#563)
Browse files Browse the repository at this point in the history
Signed-off-by: TungHoang <[email protected]>
  • Loading branch information
eapolinario authored and LaPetiteSouris committed May 16, 2023
1 parent e52e07a commit 5bd1cf3
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions tests/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 5bd1cf3

Please sign in to comment.