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:
28
rate_limit_test.go
Normal file
28
rate_limit_test.go
Normal 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")
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user