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")) }
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) }
func TestMemoryLimiter(t *testing.T) { rf := limiter.RateLimiter(limiter.UseMemory(), limiter.BucketLimit(1000*time.Millisecond, 10)) mr := rf() assertRateLimiter(mr, t) }