Update golang.org/x/time/rate (#104014)

* Add failing test case

* Update golang.org/x/time/rate

* Call update-internal-modules from update-vendor

Kubernetes-commit: 09dc055984e9532f29f37acae7aea7a979ded764
This commit is contained in:
Tim Hockin 2021-07-29 16:13:38 -07:00 committed by Kubernetes Publisher
parent ac207faedf
commit bcf88f084d
3 changed files with 37 additions and 3 deletions

2
go.mod
View File

@ -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-20210720141931-aa30bdaf750c
k8s.io/apimachinery v0.0.0-20210712060818-a644435e2c13

4
go.sum
View File

@ -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=

View File

@ -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)
}
}