mirror of
https://github.com/outbackdingo/kubernetes.git
synced 2026-02-15 23:40:25 +00:00
Automatic merge from submit-queue (batch tested with PRs 38294, 37009, 36778, 38130, 37835) Re-use tested ratelimiter The ratelimiter introduced in #35583 is not working correctly when called from multiple threads This reverts to the tested ratelimiter we were previously using to unblock 1.5 (automated revert wasn't possible) Ref #38273 reproducing test case: ``` func TestMultiThreadedBlocking(t *testing.T) { done := make(chan bool) // 100 QPS, burst of 100 b := NewBucketWithRate(100, 100) go func() { defer close(done) fmt.Println(time.Now(), "Waiting for 1000 (should block for ~9-10 seconds)") b.Wait(1000) fmt.Println(time.Now(), "Got 1000") }() // give the request for 1000 plenty of time to take the tokens time.Sleep(2 * time.Second) fmt.Println(time.Now(), "Waiting for 1 (should wait until 1000 block is refilled)") b.Wait(1) fmt.Println(time.Now(), "Got 1 (should happen right after the wait for 1000 completes)") <-done } $ go test ./pkg/util/ratelimit/ -v -run TestMultiThreadedBlocking === RUN TestMultiThreadedBlocking 2016-12-07 12:15:36.222133049 -0500 EST Waiting for 1000 (should block for ~9-10 seconds) 2016-12-07 12:15:38.222797752 -0500 EST Waiting for 1 (should wait until 1000 block is refilled) 2016-12-07 12:15:38.222897951 -0500 EST Got 1 (should happen right after the wait for 1000 completes) 2016-12-07 12:15:45.223125234 -0500 EST Got 1000 ``` in contrast, the same test run against juju/ratelimit: ``` go test ./pkg/util/flowcontrol/ -v -run TestMultiThreadedBlocking === RUN TestMultiThreadedBlocking 2016-12-07 12:32:56.796077782 -0500 EST Waiting for 1000 (should block for ~9-10 seconds) 2016-12-07 12:32:58.799159059 -0500 EST Waiting for 1 (should wait until 1000 block is refilled) 2016-12-07 12:33:05.801076002 -0500 EST Got 1000 2016-12-07 12:33:05.807510387 -0500 EST Got 1 (should happen right after the wait for 1000 completes) --- PASS: TestMultiThreadedBlocking (9.01s) ```