Skip to content

Commit

Permalink
Automated cherry pick of #104014: Update golang.org/x/time/rate (#104…
Browse files Browse the repository at this point in the history
…018)

* Add failing test case

* Update golang.org/x/time/rate

* Call update-internal-modules from update-vendor

Kubernetes-commit: 64ab974abe00396a527905d247fb09808b25b8c3
  • Loading branch information
thockin authored and k8s-publishing-bot committed Aug 3, 2021
1 parent 1e037e8 commit 5629b66
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ require (
golang.org/x/net v0.0.0-20210520170846-37e1c6afe023
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
golang.org/x/term v0.0.0-20210220032956-6a3ed077a48d
golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac
google.golang.org/protobuf v1.26.0
k8s.io/api v0.0.0-20210716001550-68328c152cca
k8s.io/apimachinery v0.0.0-20210712060818-a644435e2c13
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,8 @@ golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba h1:O8mE0/t419eoIwhTFpKVkHiTs/Igowgfkj25AcZrtiE=
golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac h1:7zkz7BUtwNFFqcowJ+RIgu2MaV/MapERkDIy+mwPyjs=
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
Expand Down
34 changes: 34 additions & 0 deletions util/flowcontrol/throttle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,37 @@ func TestWait(t *testing.T) {
t.Log(fmt.Sprintf("wait err: %v", err))
}
}

type fakeClock struct {
now time.Time
}

func newFakeClock() *fakeClock {
return &fakeClock{
now: time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC),
}
}

func (fc *fakeClock) Now() time.Time {
return fc.now
}

func (fc *fakeClock) Sleep(d time.Duration) {
fc.now = fc.now.Add(d)
}

func TestRatePrecisionBug(t *testing.T) {
// golang.org/x/time/rate used to have bugs around precision and this
// proves that they don't recur (at least in the form we know about). This
// case is specifically designed to trigger the problem after 14 seconds.
qps := float32(time.Second) / float32(1031425*time.Microsecond)
clock := newFakeClock()
tb := NewTokenBucketRateLimiterWithClock(qps, 1, clock)

for i := 0; i < 60; i++ {
if !tb.TryAccept() {
t.Fatalf("failed after %d seconds", i*2)
}
clock.Sleep(2 * time.Second)
}
}

0 comments on commit 5629b66

Please sign in to comment.