1
0
mirror of https://github.com/redis/go-redis.git synced 2025-07-28 06:42:00 +03:00

Fix rate limiter and add test.

This commit is contained in:
Vladimir Mihailenco
2014-11-13 14:26:14 +02:00
parent 9805fc35f8
commit b68ae5e548
5 changed files with 61 additions and 10 deletions

28
rate_limit_test.go Normal file
View File

@ -0,0 +1,28 @@
package redis
import (
"sync"
"testing"
"time"
)
func TestRateLimiter(t *testing.T) {
const n = 100000
rl := newRateLimiter(time.Second, n)
wg := &sync.WaitGroup{}
for i := 0; i < n; i++ {
wg.Add(1)
go func() {
if !rl.Check() {
panic("check failed")
}
wg.Done()
}()
}
wg.Wait()
if rl.Check() && rl.Check() {
t.Fatal("check passed")
}
}