RateLimiter: change CanAccept() to TryAccept()

This commit is contained in:
Hongchao Deng
2015-11-23 16:36:23 -08:00
parent 367f0e03dd
commit 13d152a873
6 changed files with 15 additions and 14 deletions

View File

@@ -24,28 +24,28 @@ import (
func TestBasicThrottle(t *testing.T) {
r := NewTokenBucketRateLimiter(1, 3)
for i := 0; i < 3; i++ {
if !r.CanAccept() {
if !r.TryAccept() {
t.Error("unexpected false accept")
}
}
if r.CanAccept() {
if r.TryAccept() {
t.Error("unexpected true accept")
}
}
func TestIncrementThrottle(t *testing.T) {
r := NewTokenBucketRateLimiter(1, 1)
if !r.CanAccept() {
if !r.TryAccept() {
t.Error("unexpected false accept")
}
if r.CanAccept() {
if r.TryAccept() {
t.Error("unexpected true accept")
}
// Allow to refill
time.Sleep(2 * time.Second)
if !r.CanAccept() {
if !r.TryAccept() {
t.Error("unexpected false accept")
}
}