Atlas › Test
TestSetBurst_Diff
Exact test identity: go.temporal.io/server/common/quotas/TestRateLimiterSuite/TestSetBurst_Diff
- Package
go.temporal.io/server/common/quotas
- Suite / test hierarchy
TestRateLimiterSuite/TestSetBurst_Diff
- Test
TestSetBurst_Diff
- Introduced at
- TestSetBurst_Diff Frontier kind: Test frontier
- Covered ranges
- 15
- Covered lines
- 63
- Covered files
- 3
Covered source
Expand a file to inspect source; the > gutter marks covered lines.
go.temporal.io/server/common/quotas/rate_limiter_impl.go 43 covered LOC · 9 ranges
Open complete file
24
// NewRateLimiter returns a new rate limiter that can handle dynamic
25
// configuration updates
27
>
limiter := rate.NewLimiter(rate.Limit(newRPS), newBurst)
28
>
ts := clock.NewRealTimeSource()
29
>
rl := &RateLimiterImpl{
30
>
rps: newRPS,
31
>
burst: newBurst,
32
>
timeSource: ts,
33
>
ClockedRateLimiter: NewClockedRateLimiter(limiter, ts),
34
>
}
35
>
36
>
return rl
37
>
}
38
39
// SetRPS sets the rate of the rate limiter
43
44
// SetBurst sets the burst of the rate limiter
46
>
rl.refreshInternalRateLimiterImpl(nil, &burst)
47
>
}
48
49
func (rl *RateLimiterImpl) Reserve() Reservation {
61
62
// Rate returns the rps for this rate limiter
64
>
rl.Lock()
65
>
defer rl.Unlock()
66
>
67
>
return rl.rps
68
>
}
69
70
// Burst returns the burst for this rate limiter
72
>
rl.Lock()
73
>
defer rl.Unlock()
74
>
75
>
return rl.burst
76
>
}
77
78
// TokensAt returns the number of tokens that will be available at time t
87
newRate *float64,
88
newBurst *int,
90
>
rl.Lock()
91
>
defer rl.Unlock()
92
>
93
>
refresh := false
94
>
95
>
if newRate != nil && rl.rps != *newRate {
96
rl.rps = *newRate
97
refresh = true
98
}
99
102
>
refresh = true
103
>
}
104
107
>
rl.SetLimitAt(now, rate.Limit(rl.rps))
108
>
rl.SetBurstAt(now, rl.burst)
109
>
}
110
}
111
go.temporal.io/server/common/quotas/clocked_rate_limiter.go 14 covered LOC · 4 ranges
Open complete file
25
)
26
27
>
func NewClockedRateLimiter(rateLimiter *rate.Limiter, timeSource clock.TimeSource) ClockedRateLimiter {
clocked_rate_limiter.go
28
>
return ClockedRateLimiter{
29
>
rateLimiter: rateLimiter,
30
>
timeSource: timeSource,
31
>
recycleCh: make(chan struct{}),
32
>
}
33
>
}
34
35
func (l ClockedRateLimiter) Allow() bool {
142
}
143
145
>
l.rateLimiter.SetLimitAt(t, newLimit)
146
>
}
147
149
>
// Clamp burst to >=1 when rate is positive; burst=0 with rate=0 is allowed for pause.
150
>
if newBurst < 1 && l.rateLimiter.Limit() > 0 {
151
newBurst = 1
152
}
154
}
155
go.temporal.io/server/common/clock/time_source.go 6 covered LOC · 2 ranges
Open complete file
31
32
// NewRealTimeSource returns a timeSource that uses the real wall timeSource time.
34
>
return RealTimeSource{}
35
>
}
36
37
// Now returns the current time, with the location set to UTC.
39
>
return time.Now().UTC()
40
>
}
41
42
// Since returns the time elapsed since t