Skip to content

Commit 19dc8f9

Browse files
committed
Add a test for #42. Thanks @Bo0mer
1 parent 4ede2c3 commit 19dc8f9

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

rate_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,28 @@ func TestAllow(t *testing.T) {
5959
assert.InDelta(t, res.ResetAfter, 999*time.Millisecond, float64(10*time.Millisecond))
6060
}
6161

62+
func TestRetryAfter(t *testing.T) {
63+
limit := redis_rate.Limit{
64+
Rate: 1,
65+
Period: time.Millisecond,
66+
Burst: 1,
67+
}
68+
69+
ctx := context.Background()
70+
l := rateLimiter()
71+
72+
for i := 0; i < 1000; i++ {
73+
res, err := l.Allow(ctx, "test_id", limit)
74+
assert.Nil(t, err)
75+
76+
if res.Allowed > 0 {
77+
continue
78+
}
79+
80+
assert.LessOrEqual(t, int64(res.RetryAfter), int64(time.Millisecond))
81+
}
82+
}
83+
6284
func TestAllowAtMost(t *testing.T) {
6385
ctx := context.Background()
6486

0 commit comments

Comments
 (0)