diff --git a/api/scheduler/scheduler_test.go b/api/scheduler/scheduler_test.go index 126c00b6e..279c8d8b6 100644 --- a/api/scheduler/scheduler_test.go +++ b/api/scheduler/scheduler_test.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "sync/atomic" "testing" "time" @@ -70,12 +71,10 @@ func Test_JobShouldNotStop_UponError(t *testing.T) { s := NewScheduler(context.Background()) defer s.Shutdown() - var acc int + var acc atomic.Int64 ch := make(chan struct{}) s.StartJobEvery(jobInterval, func() error { - acc++ - - if acc == 2 { + if acc.Add(1) == 2 { close(ch) return NewPermanentError(fmt.Errorf("failed")) } @@ -85,7 +84,7 @@ func Test_JobShouldNotStop_UponError(t *testing.T) { <-time.After(3 * jobInterval) <-ch - assert.Equal(t, 2, acc) + assert.Equal(t, int64(2), acc.Load()) } func Test_CanTerminateAllJobs_ByShuttingDownScheduler(t *testing.T) {