Esempio n. 1
0
func TestRedisLimiter(t *testing.T) {
	clearUpRedis()
	rf := limiter.RateLimiter(limiter.UseRedis(redisPool), limiter.BucketLimit(1000*time.Millisecond, 10))
	rr := rf()
	assertRateLimiter(rr, t)
	assert.Equal(t, 100, size("rl-key1"))
}
Esempio n. 2
0
func TestFloodThreshold(t *testing.T) {
	clearUpRedis()
	rf := limiter.RateLimiter(limiter.UseRedis(redisPool), limiter.BucketLimit(1000*time.Millisecond, 10), limiter.FloodThreshold(5))
	rr := rf()
	assertRateLimiter(rr, t)
	assert.Equal(t, 51, size("rl-key1"))
	time.Sleep(1500 * time.Millisecond)
	assertRateLimiter(rr, t)
}
Esempio n. 3
0
func TestMemoryLimiter(t *testing.T) {
	rf := limiter.RateLimiter(limiter.UseMemory(), limiter.BucketLimit(1000*time.Millisecond, 10))
	mr := rf()
	assertRateLimiter(mr, t)
}