redis/rate_limit_test.go

29 lines
372 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) {
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")
}
}