Files
kubernetes/pkg
Kubernetes Submit Queue 440ed2cfa8 Merge pull request #38294 from liggitt/rate-limit
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)
```
2016-12-07 10:45:13 -08:00
..
2016-11-23 22:30:47 -06:00
2016-11-23 22:30:47 -06:00
2016-10-21 17:32:32 -07:00
2016-12-07 07:54:04 -05:00
2016-12-06 11:14:59 -05:00
2016-11-23 15:53:09 -08:00
2016-11-23 15:53:09 -08:00
2016-10-21 17:32:32 -07:00
2016-12-06 10:32:54 -08:00
2016-10-21 17:32:32 -07:00
2016-10-21 17:32:32 -07:00
2016-11-23 15:53:09 -08:00
2016-10-21 17:32:32 -07:00
2016-11-23 15:53:09 -08:00
2016-10-21 17:32:32 -07:00
2016-12-03 19:10:46 -05:00
2016-11-23 15:53:09 -08:00
2016-11-23 15:53:09 -08:00
2016-10-21 17:32:32 -07:00
2016-11-23 15:53:09 -08:00
2016-10-21 17:32:32 -07:00
2016-12-07 10:32:47 -05:00
2016-10-24 14:41:56 -07:00
2016-11-23 22:30:47 -06:00