redis/rate_limit_test.go

32 lines
406 B
Go
Raw Normal View History

2014-11-13 15:26:14 +03:00
package redis
import (
"sync"
"testing"
"time"
)
func TestRateLimiter(t *testing.T) {
2014-11-18 13:11:06 +03:00
var n = 100000
if testing.Short() {
n = 1000
}
rl := newRateLimiter(time.Minute, n)
2014-11-13 15:26:14 +03:00
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")
}
}