Atlas › Test

TestSetRate_Same

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

Package
go.temporal.io/server/common/quotas
Suite / test hierarchy
TestRateLimiterSuite/TestSetRate_Same
Test
TestSetRate_Same
Introduced at
rate_limiter_impl.go ×1 Frontier kind: Joint frontier
Covered ranges
9
Covered lines
46
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 36 covered LOC · 7 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
40 > func (rl *RateLimiterImpl) SetRPS(rps float64) { rate_limiter_impl.go
41 > rl.refreshInternalRateLimiterImpl(&rps, nil)
42 > }
43
44 // SetBurst sets the burst of the rate limiter
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
97 refresh = true
98 }
99
100 > if newBurst != nil && rl.burst != *newBurst { rate_limiter_impl.go
101 rl.burst = *newBurst
102 refresh = true
103 }
104
105 > if refresh { rate_limiter_impl.go
106 now := rl.timeSource.Now()
107 rl.SetLimitAt(now, rate.Limit(rl.rps))
go.temporal.io/server/common/quotas/clocked_rate_limiter.go 7 covered LOC · 1 range

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 {
go.temporal.io/server/common/clock/time_source.go 3 covered LOC · 1 range

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.