mirror of
https://github.com/tailscale/tailscale.git
synced 2025-01-05 23:07:44 +00:00
tstime/rate: deflake TestLongRunningQPS
This test is highly dependent on the accuracy of OS timers. Reduce the number of failures by decreasing the required accuracy from 0.999 to 0.995. Also, switch from repeated time.Sleep to using a time.Ticker for improved accuracy. Updates #2727 Signed-off-by: Joe Tsai <joetsai@digital-static.net>
This commit is contained in:
parent
bb47feca44
commit
30458c71c8
@ -182,15 +182,18 @@ func TestLongRunningQPS(t *testing.T) {
|
||||
wg.Done()
|
||||
}
|
||||
|
||||
// This will still offer ~500 requests per second,
|
||||
// but won't consume outrageous amount of CPU.
|
||||
start := time.Now()
|
||||
end := start.Add(5 * time.Second)
|
||||
for time.Now().Before(end) {
|
||||
ticker := time.NewTicker(2 * time.Millisecond)
|
||||
defer ticker.Stop()
|
||||
for now := range ticker.C {
|
||||
if now.After(end) {
|
||||
break
|
||||
}
|
||||
wg.Add(1)
|
||||
go f()
|
||||
|
||||
// This will still offer ~500 requests per second, but won't consume
|
||||
// outrageous amount of CPU.
|
||||
time.Sleep(2 * time.Millisecond)
|
||||
}
|
||||
wg.Wait()
|
||||
elapsed := time.Since(start)
|
||||
@ -201,7 +204,7 @@ func TestLongRunningQPS(t *testing.T) {
|
||||
t.Errorf("numOK = %d, want %d (ideal %f)", numOK, want, ideal)
|
||||
}
|
||||
// We should get very close to the number of requests allowed.
|
||||
if want := int32(0.999 * ideal); numOK < want {
|
||||
if want := int32(0.995 * ideal); numOK < want {
|
||||
t.Errorf("numOK = %d, want %d (ideal %f)", numOK, want, ideal)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user