From 700a312ea46d3118640431de06f5e1a8420b9974 Mon Sep 17 00:00:00 2001 From: Bin Shi <39923490+binshi-bing@users.noreply.github.com> Date: Sun, 23 Apr 2023 19:32:44 -0700 Subject: [PATCH] fix data race issue in the store limit test (#6370) * fix data race issue in th estore limit test Signed-off-by: Bin Shi * fix gmt error Signed-off-by: Bin Shi --------- Signed-off-by: Bin Shi --- pkg/core/storelimit/limit_test.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/pkg/core/storelimit/limit_test.go b/pkg/core/storelimit/limit_test.go index 2b418952bb6..6f57c01eccb 100644 --- a/pkg/core/storelimit/limit_test.go +++ b/pkg/core/storelimit/limit_test.go @@ -18,6 +18,7 @@ import ( "container/list" "context" "math/rand" + "sync/atomic" "testing" "time" @@ -125,21 +126,22 @@ func TestFeedback(t *testing.T) { } // region size is 10GB, snapshot write limit is 100MB/s and the snapshot concurrency is 3. // the best strategy is that the tikv executing queue equals the wait. - regionSize, limit, wait := int64(10000), int64(100), int64(4) - iter := 100 + const regionSize, limit, wait = int64(10000), int64(100), int64(4) + var iter atomic.Int32 + iter.Store(100) ops := make(chan int64, 10) ctx, cancel := context.WithCancel(context.Background()) // generate the operator go func() { for { - if s.Available(regionSize, SendSnapshot, constant.Low) && iter > 0 { - iter-- + if s.Available(regionSize, SendSnapshot, constant.Low) && iter.Load() > 0 { + iter.Add(-1) size := regionSize - rand.Int63n(regionSize/10) s.Take(size, SendSnapshot, constant.Low) ops <- size } - if iter == 0 { + if iter.Load() == 0 { cancel() return } @@ -185,7 +187,7 @@ func TestFeedback(t *testing.T) { err := exec*wait - cost queue.Remove(first) s.Feedback(float64(err)) - if iter < 5 { + if iter.Load() < 5 { re.Greater(float64(s.GetCap()), float64(regionSize*(wait-2))) re.Less(float64(s.GetCap()), float64(regionSize*wait)) }