Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix data race
Browse files Browse the repository at this point in the history
Signed-off-by: Neil Shen <[email protected]>
overvenus authored and ti-chi-bot committed Dec 8, 2021
1 parent 0b83e39 commit fd0a8ba
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/workerpool/pool_test.go
Original file line number Diff line number Diff line change
@@ -432,14 +432,19 @@ func TestSynchronizeLog(t *testing.T) {
// Always report "synchronize is taking too long".
w.slowSynchronizeThreshold = time.Duration(0)
w.slowSynchronizeLimiter = rate.NewLimiter(rate.Every(100*time.Minute), 1)
go w.synchronize()

counter := int32(0)
logWarn = func(msg string, fields ...zap.Field) {
atomic.AddInt32(&counter, 1)
}
defer func() { logWarn = log.Warn }()

doneCh := make(chan struct{})
go func() {
w.synchronize()
close(doneCh)
}()

time.Sleep(300 * time.Millisecond)
w.stopNotifier.Notify()
time.Sleep(300 * time.Millisecond)
@@ -448,6 +453,7 @@ func TestSynchronizeLog(t *testing.T) {
// Close worker.
atomic.StoreInt32(&w.isRunning, 0)
w.stopNotifier.Close()
<-doneCh

require.EqualValues(t, 1, atomic.LoadInt32(&counter))
}

0 comments on commit fd0a8ba

Please sign in to comment.