Skip to content

Commit

Permalink
Fix data race in test
Browse files Browse the repository at this point in the history
  • Loading branch information
hibiken committed Jun 8, 2020
1 parent 4e800a7 commit 8af4cba
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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())},
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8af4cba

Please sign in to comment.