mirror of
https://github.com/kubernetes/client-go.git
synced 2025-09-05 00:51:02 +00:00
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:
committed by
Kubernetes Publisher
parent
ac207faedf
commit
bcf88f084d
@@ -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)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user