Skip to content

Commit

Permalink
fix data race issue in the store limit test (tikv#6370)
Browse files Browse the repository at this point in the history
* fix data race issue in th estore limit test

Signed-off-by: Bin Shi <[email protected]>

* fix gmt error

Signed-off-by: Bin Shi <[email protected]>

---------

Signed-off-by: Bin Shi <[email protected]>
  • Loading branch information
binshi-bing authored and rleungx committed Aug 2, 2023
1 parent 08eb08d commit 700a312
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions pkg/core/storelimit/limit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"container/list"
"context"
"math/rand"
"sync/atomic"
"testing"
"time"

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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))
}
Expand Down

0 comments on commit 700a312

Please sign in to comment.