@@ -22,6 +22,7 @@ package txthrottler
22
22
//go:generate mockgen -destination mock_topology_watcher_test.go -package txthrottler vitess.io/vitess/go/vt/vttablet/tabletserver/txthrottler TopologyWatcherInterface
23
23
24
24
import (
25
+ "sync/atomic"
25
26
"testing"
26
27
"time"
27
28
@@ -148,9 +149,12 @@ func TestEnabledThrottler(t *testing.T) {
148
149
149
150
throttlerImpl , ok := throttler .state .(* txThrottlerStateImpl )
150
151
assert .True (t , ok )
152
+ // Stop the go routine that keeps updating the cached shard's max lag to preventi it from changing the value in a
153
+ // way that will interfere with how we manipulate that value in our tests to evaluate different cases:
154
+ throttlerImpl .endChannel <- true
151
155
152
156
// 1 should not throttle due to return value of underlying Throttle(), despite high lag
153
- throttlerImpl .shardMaxLag . Store ( 20 )
157
+ atomic . StoreInt64 ( & throttlerImpl .shardMaxLag , 20 )
154
158
assert .False (t , throttler .Throttle (100 , "some-workload" ))
155
159
assert .Equal (t , int64 (1 ), throttler .requestsTotal .Counts ()["some-workload" ])
156
160
assert .Zero (t , throttler .requestsThrottled .Counts ()["some-workload" ])
@@ -175,7 +179,7 @@ func TestEnabledThrottler(t *testing.T) {
175
179
assert .Equal (t , int64 (1 ), throttler .requestsThrottled .Counts ()["some-workload" ])
176
180
177
181
// 4 should not throttle despite return value of underlying Throttle() and priority = 100, due to low lag
178
- throttlerImpl .shardMaxLag . Store ( 1 )
182
+ atomic . StoreInt64 ( & throttlerImpl .shardMaxLag , 1 )
179
183
assert .False (t , throttler .Throttle (100 , "some-workload" ))
180
184
assert .Equal (t , int64 (4 ), throttler .requestsTotal .Counts ()["some-workload" ])
181
185
assert .Equal (t , int64 (1 ), throttler .requestsThrottled .Counts ()["some-workload" ])
0 commit comments