summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorBrad Fitzpatrick <bradfitz@tailscale.com>2022-02-28 19:55:18 -0800
committerBrad Fitzpatrick <brad@danga.com>2022-03-08 13:54:13 -0800
commitbfd7f9d3182b46df420e9caf269c493971c94de1 (patch)
tree958d8bac57472a34f44518e1808b6d8335d5cb0c
parentfca3592c1c8e4e4fbb0fb84024c24c7d72b6154d (diff)
downloadtailscale-bfd7f9d3182b46df420e9caf269c493971c94de1.tar.xz
tailscale-bfd7f9d3182b46df420e9caf269c493971c94de1.zip
tstime/rate: deflake TestLongRunningQPS even more
Previous de-flakings: * 8cf1af8a0703c36256fc58e98ddb63b8907848f1 for #3733 * 30458c71c81a3d680aacecafa67fabc1c728c52d for #2727 Fixes #4044 Change-Id: I506cf1ff37bb224f5a9929f1998901e60b24535d Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com> (cherry picked from commit 6a2e94cbebe9f895106c2fbaaaa3320288bdaa87)
-rw-r--r--tstime/rate/rate_test.go56
1 files changed, 0 insertions, 56 deletions
diff --git a/tstime/rate/rate_test.go b/tstime/rate/rate_test.go
index 3e74cf6db..ced78b040 100644
--- a/tstime/rate/rate_test.go
+++ b/tstime/rate/rate_test.go
@@ -16,7 +16,6 @@ package rate
import (
"context"
"math"
- "runtime"
"sync"
"sync/atomic"
"testing"
@@ -155,61 +154,6 @@ func TestSimultaneousRequests(t *testing.T) {
}
}
-func TestLongRunningQPS(t *testing.T) {
- if testing.Short() {
- t.Skip("skipping in short mode")
- }
- if runtime.GOOS == "openbsd" {
- t.Skip("low resolution time.Sleep invalidates test (golang.org/issue/14183)")
- return
- }
-
- // The test runs for a few seconds executing many requests and then checks
- // that overall number of requests is reasonable.
- const (
- limit = 100
- burst = 100
- )
- var numOK = int32(0)
-
- lim := NewLimiter(limit, burst)
-
- var wg sync.WaitGroup
- f := func() {
- if ok := lim.Allow(); ok {
- atomic.AddInt32(&numOK, 1)
- }
- wg.Done()
- }
-
- // This will still offer ~500 requests per second,
- // but won't consume outrageous amount of CPU.
- start := time.Now()
- end := start.Add(1 * time.Second)
- ticker := time.NewTicker(2 * time.Millisecond)
- defer ticker.Stop()
- for now := range ticker.C {
- if now.After(end) {
- break
- }
- wg.Add(1)
- go f()
- }
- wg.Wait()
- elapsed := time.Since(start)
- ideal := burst + (limit * float64(elapsed) / float64(time.Second))
-
- // We should never get more requests than allowed.
- if want := int32(ideal + 1); numOK > want {
- t.Errorf("numOK = %d, want %d (ideal %f)", numOK, want, ideal)
- }
- // We should get close-ish to the number of requests allowed.
- // Trying to get too close causes flakes. Treat this as a sanity check.
- if want := int32(0.9 * ideal); numOK < want {
- t.Errorf("numOK = %d, want %d (ideal %f)", numOK, want, ideal)
- }
-}
-
type request struct {
t time.Time
n int