summaryrefslogtreecommitdiffstats
path: root/Godeps/_workspace/src/gopkg.in/redis.v2/rate_limit_test.go
blob: 2f0d41a2eb93ce0e7a8b55ffde449c5062e3d5ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package redis

import (
	"sync"
	"testing"
	"time"
)

func TestRateLimiter(t *testing.T) {
	var n = 100000
	if testing.Short() {
		n = 1000
	}
	rl := newRateLimiter(time.Minute, 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")
	}
}