2
0
mirror of https://github.com/hibiken/asynq.git synced 2024-12-24 23:02:18 +08:00

Fix data race in test

This commit is contained in:
Ken Hibino 2020-06-05 21:23:28 -07:00
parent 4e800a7f68
commit 8af4cbad51

View File

@ -104,12 +104,14 @@ func TestProcessorSuccess(t *testing.T) {
t.Fatal(err)
}
}
time.Sleep(time.Second) // wait for one second to allow all enqueued tasks to be processed.
time.Sleep(2 * time.Second) // wait for two second to allow all enqueued tasks to be processed.
p.terminate()
mu.Lock()
if diff := cmp.Diff(tc.wantProcessed, processed, sortTaskOpt, cmp.AllowUnexported(Payload{})); diff != "" {
t.Errorf("mismatch found in processed tasks; (-want, +got)\n%s", diff)
}
mu.Unlock()
if l := r.LLen(base.InProgressQueue).Val(); l != 0 {
t.Errorf("%q has %d tasks, want 0", base.InProgressQueue, l)
@ -160,7 +162,7 @@ func TestProcessorRetry(t *testing.T) {
handler: HandlerFunc(func(ctx context.Context, task *Task) error {
return fmt.Errorf(errMsg)
}),
wait: time.Second,
wait: 2 * time.Second,
wantRetry: []h.ZSetEntry{
{Msg: &r2, Score: float64(now.Add(time.Minute).Unix())},
{Msg: &r3, Score: float64(now.Add(time.Minute).Unix())},
@ -217,7 +219,7 @@ func TestProcessorRetry(t *testing.T) {
t.Fatal(err)
}
}
time.Sleep(tc.wait)
time.Sleep(tc.wait) // FIXME: This makes test flaky.
p.terminate()
cmpOpt := cmpopts.EquateApprox(0, float64(time.Second)) // allow up to a second difference in zset score