@@ -63,6 +63,39 @@ func TestItemExponentialFailureRateLimiter(t *testing.T) {
6363
6464}
6565
66+ func TestItemExponentialFailureRateLimiterOverFlow (t * testing.T ) {
67+ limiter := NewItemExponentialFailureRateLimiter (1 * time .Millisecond , 1000 * time .Second )
68+ for i := 0 ; i < 5 ; i ++ {
69+ limiter .When ("one" )
70+ }
71+ if e , a := 100000 * time .Millisecond , limiter .When ("one" ); e != a {
72+ t .Errorf ("expected %v, got %v" , e , a )
73+ }
74+
75+ for i := 0 ; i < 1000 ; i ++ {
76+ limiter .When ("overflow1" )
77+ }
78+ if e , a := 1000 * time .Second , limiter .When ("overflow1" ); e != a {
79+ t .Errorf ("expected %v, got %v" , e , a )
80+ }
81+
82+ limiter = NewItemExponentialFailureRateLimiter (1 * time .Minute , 1000 * time .Hour )
83+ for i := 0 ; i < 2 ; i ++ {
84+ limiter .When ("two" )
85+ }
86+ if e , a := 100 * time .Minute , limiter .When ("two" ); e != a {
87+ t .Errorf ("expected %v, got %v" , e , a )
88+ }
89+
90+ for i := 0 ; i < 1000 ; i ++ {
91+ limiter .When ("overflow2" )
92+ }
93+ if e , a := 1000 * time .Hour , limiter .When ("overflow2" ); e != a {
94+ t .Errorf ("expected %v, got %v" , e , a )
95+ }
96+
97+ }
98+
6699func TestItemFastSlowRateLimiter (t * testing.T ) {
67100 limiter := NewItemFastSlowRateLimiter (5 * time .Millisecond , 10 * time .Second , 3 )
68101
0 commit comments