Skip to content

Commit

Permalink
test recent check period
Browse files Browse the repository at this point in the history
Signed-off-by: Shlomi Noach <[email protected]>
  • Loading branch information
shlomi-noach committed May 23, 2024
1 parent 6456fcf commit d45ff81
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
3 changes: 3 additions & 0 deletions go/vt/vttablet/tabletserver/throttle/throttler.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ func NewThrottler(env tabletenv.Env, srvTopoServer srvtopo.Server, ts *topo.Serv
throttler.dormantPeriod = dormantPeriod
throttler.recentCheckDormantDiff = int64(throttler.dormantPeriod / recentCheckRateLimiterInterval)
throttler.recentCheckDiff = int64(1 * time.Second / recentCheckRateLimiterInterval)
if throttler.recentCheckDiff < 1 {
throttler.recentCheckDiff = 1
}

throttler.StoreMetricsThreshold(defaultThrottleLagThreshold.Seconds()) //default
throttler.readSelfThrottleMetric = func(ctx context.Context, p *mysql.Probe) *mysql.MySQLThrottleMetric {
Expand Down
7 changes: 7 additions & 0 deletions go/vt/vttablet/tabletserver/throttle/throttler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,13 @@ func newTestThrottler() *Throttler {
return throttler
}

func TestInitThrottler(t *testing.T) {
throttler := newTestThrottler()
assert.Equal(t, 5*time.Second, throttler.dormantPeriod)
assert.EqualValues(t, 5, throttler.recentCheckDormantDiff)
assert.EqualValues(t, 3, throttler.recentCheckDiff)
}

func TestIsAppThrottled(t *testing.T) {
throttler := Throttler{
throttledApps: cache.New(cache.NoExpiration, 0),
Expand Down

0 comments on commit d45ff81

Please sign in to comment.