fix no rate limiting if average is 0
This commit is contained in:
parent
e1e86763e3
commit
0861c47e54
2 changed files with 18 additions and 7 deletions
|
@ -15,6 +15,7 @@ import (
|
|||
"github.com/traefik/traefik/v2/pkg/config/dynamic"
|
||||
"github.com/traefik/traefik/v2/pkg/testhelpers"
|
||||
"github.com/vulcand/oxy/v2/utils"
|
||||
"golang.org/x/time/rate"
|
||||
)
|
||||
|
||||
func TestNewRateLimiter(t *testing.T) {
|
||||
|
@ -25,7 +26,16 @@ func TestNewRateLimiter(t *testing.T) {
|
|||
expectedSourceIP string
|
||||
requestHeader string
|
||||
expectedError string
|
||||
expectedRTL rate.Limit
|
||||
}{
|
||||
{
|
||||
desc: "no ratelimit on Average == 0",
|
||||
config: dynamic.RateLimit{
|
||||
Average: 0,
|
||||
Burst: 10,
|
||||
},
|
||||
expectedRTL: rate.Inf,
|
||||
},
|
||||
{
|
||||
desc: "maxDelay computation",
|
||||
config: dynamic.RateLimit{
|
||||
|
@ -120,6 +130,9 @@ func TestNewRateLimiter(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
assert.Equal(t, test.requestHeader, hd)
|
||||
}
|
||||
if test.expectedRTL != 0 {
|
||||
assert.Equal(t, test.expectedRTL, rtl.rate)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue