2
0
mirror of https://github.com/hibiken/asynq.git synced 2025-10-26 11:16:12 +08:00

Fix data race in subscriber test

This commit is contained in:
Ken Hibino
2020-02-16 14:42:21 -08:00
parent 39f237899b
commit 906f231e6c
2 changed files with 10 additions and 3 deletions

View File

@@ -27,8 +27,11 @@ func TestSubscriber(t *testing.T) {
}
for _, tc := range tests {
var mu sync.Mutex
called := false
fakeCancelFunc := func() {
mu.Lock()
defer mu.Unlock()
called = true
}
cancelations := base.NewCancelations()
@@ -46,6 +49,7 @@ func TestSubscriber(t *testing.T) {
// allow for redis to publish message
time.Sleep(time.Second)
mu.Lock()
if called != tc.wantCalled {
if tc.wantCalled {
t.Errorf("fakeCancelFunc was not called, want the function to be called")
@@ -53,6 +57,7 @@ func TestSubscriber(t *testing.T) {
t.Errorf("fakeCancelFunc was called, want the function to not be called")
}
}
mu.Unlock()
subscriber.terminate()
}