forked from mirror/redis
Migrate rate limiter test
This commit is contained in:
parent
1a56e736aa
commit
d7afd989b9
|
@ -1,31 +1,25 @@
|
||||||
package redis
|
package redis
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sync"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
. "github.com/onsi/ginkgo"
|
||||||
|
. "github.com/onsi/gomega"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestRateLimiter(t *testing.T) {
|
var _ = Describe("RateLimiter", func() {
|
||||||
var n = 100000
|
var n = 100000
|
||||||
if testing.Short() {
|
if testing.Short() {
|
||||||
n = 1000
|
n = 1000
|
||||||
}
|
}
|
||||||
rl := newRateLimiter(time.Minute, n)
|
|
||||||
|
|
||||||
wg := &sync.WaitGroup{}
|
It("should rate limit", func() {
|
||||||
for i := 0; i < n; i++ {
|
rl := newRateLimiter(time.Minute, n)
|
||||||
wg.Add(1)
|
for i := 0; i <= n; i++ {
|
||||||
go func() {
|
Expect(rl.Check()).To(BeTrue())
|
||||||
if !rl.Check() {
|
}
|
||||||
panic("check failed")
|
Expect(rl.Check()).To(BeFalse())
|
||||||
}
|
})
|
||||||
wg.Done()
|
|
||||||
}()
|
|
||||||
}
|
|
||||||
wg.Wait()
|
|
||||||
|
|
||||||
if rl.Check() && rl.Check() {
|
})
|
||||||
t.Fatal("check passed")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue