mirror of
https://github.com/kubernetes/client-go.git
synced 2025-09-02 07:35:21 +00:00
flowcontrol context aware and fix request may hang issue
Kubernetes-commit: ce8805f95fcf6540397eaa60b8d84db752f05eea
This commit is contained in:
committed by
Kubernetes Publisher
parent
11059204e0
commit
8f99f83432
@@ -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))
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user