Atlas › Test

TestSetRateBurst_Diff

Exact test identity: go.temporal.io/server/common/quotas/TestRateLimiterSuite/TestSetRateBurst_Diff

Package
go.temporal.io/server/common/quotas
Suite / test hierarchy
TestRateLimiterSuite/TestSetRateBurst_Diff
Test
TestSetRateBurst_Diff
Introduced at
TestSetRateBurst_Diff Frontier kind: Test frontier
Covered ranges
16
Covered lines
66
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 46 covered LOC · 10 ranges

Open complete file

24 // NewRateLimiter returns a new rate limiter that can handle dynamic
25 // configuration updates
26 > func NewRateLimiter(newRPS float64, newBurst int) *RateLimiterImpl { rate_limiter_impl.go
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
56
57 // SetRateBurst sets the rps & burst of the rate limiter
58 > func (rl *RateLimiterImpl) SetRateBurst(rps float64, burst int) { rate_limiter_impl.go
59 > rl.refreshInternalRateLimiterImpl(&rps, &burst)
60 > }
61
62 // Rate returns the rps for this rate limiter
63 > func (rl *RateLimiterImpl) Rate() float64 { rate_limiter_impl.go
64 > rl.Lock()
65 > defer rl.Unlock()
66 >
67 > return rl.rps
68 > }
69
70 // Burst returns the burst for this rate limiter
71 > func (rl *RateLimiterImpl) Burst() int { rate_limiter_impl.go
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 rate_limiter_impl.go
97 > refresh = true
98 > }
99
100 > if newBurst != nil && rl.burst != *newBurst { rate_limiter_impl.go
101 > rl.burst = *newBurst rate_limiter_impl.go
102 > refresh = true
103 > }
104
105 > if refresh { rate_limiter_impl.go
106 > now := rl.timeSource.Now() rate_limiter_impl.go
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
144 > func (l ClockedRateLimiter) SetLimitAt(t time.Time, newLimit rate.Limit) { clocked_rate_limiter.go
145 > l.rateLimiter.SetLimitAt(t, newLimit)
146 > }
147
148 > func (l ClockedRateLimiter) SetBurstAt(t time.Time, newBurst int) { clocked_rate_limiter.go
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 }
153 > l.rateLimiter.SetBurstAt(t, newBurst) clocked_rate_limiter.go
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.
33 > func NewRealTimeSource() RealTimeSource { time_source.go
34 > return RealTimeSource{}
35 > }
36
37 // Now returns the current time, with the location set to UTC.
38 > func (ts RealTimeSource) Now() time.Time { time_source.go
39 > return time.Now().UTC()
40 > }
41
42 // Since returns the time elapsed since t