flowcontrol context aware and fix request may hang issue

Kubernetes-commit: ce8805f95fcf6540397eaa60b8d84db752f05eea
This commit is contained in:
chenjun.cj
2019-06-21 12:17:46 +08:00
committed by Kubernetes Publisher
parent 11059204e0
commit 8f99f83432
4 changed files with 64 additions and 6 deletions

View File

@@ -17,6 +17,8 @@ limitations under the License.
package flowcontrol
import (
"context"
"fmt"
"sync"
"testing"
"time"
@@ -151,3 +153,21 @@ func TestNeverFake(t *testing.T) {
t.Error("Stop should make Accept unblock in NeverFake.")
}
}
func TestWait(t *testing.T) {
r := NewTokenBucketRateLimiter(0.0001, 1)
ctx, cancelFn := context.WithTimeout(context.Background(), time.Second)
defer cancelFn()
if err := r.Wait(ctx); err != nil {
t.Errorf("unexpected wait failed, err: %v", err)
}
ctx2, cancelFn2 := context.WithTimeout(context.Background(), time.Second)
defer cancelFn2()
if err := r.Wait(ctx2); err == nil {
t.Errorf("unexpected wait success")
} else {
t.Log(fmt.Sprintf("wait err: %v", err))
}
}