File: rate_limit_test.go

package info (click to toggle)
golang-gopkg-redis.v2 2.3.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 280 kB
  • sloc: makefile: 6
file content (31 lines) | stat: -rw-r--r-- 406 bytes parent folder | download | duplicates (2)
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")
	}
}