diff options
| author | Hana (Hyang-Ah) Kim <hyangah@gmail.com> | 2020-04-22 15:35:45 -0400 |
|---|---|---|
| committer | Hyang-Ah Hana Kim <hyangah@gmail.com> | 2020-04-22 21:08:29 +0000 |
| commit | 3e342e8719b8d84a976c05df0c03d9084c5f39e6 (patch) | |
| tree | 8f12c78ba9ae13d41c042c1e780e7c72727e32f0 /src/net/http | |
| parent | 4a5d6916ede1a5547f78140c7594a9519bda90e7 (diff) | |
| download | go-3e342e8719b8d84a976c05df0c03d9084c5f39e6.tar.xz | |
net/http/pprof: make TestDeltaProfile less flaky by retrying
In some slow environment, the goroutine for mutexHog2 may not run
within 1secs. So, try with increasing seconds parameters,
and declare failure if it still fails with the longest duration
parameter (32sec).
Also, relax the test condition - previously we expected the
profile's duration is within 0.5~2sec. But obviously, in some
slow environment, that's not even guaranteed. Just check we get
non-zero duration in the result.
Update #38544
Change-Id: Ia9b0d51429a2093e6c9eb92cf463ff6952ef3e10
Reviewed-on: https://go-review.googlesource.com/c/go/+/229498
Run-TryBot: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/net/http')
| -rw-r--r-- | src/net/http/pprof/pprof_test.go | 50 |
1 files changed, 19 insertions, 31 deletions
diff --git a/src/net/http/pprof/pprof_test.go b/src/net/http/pprof/pprof_test.go index 5a6cfbd2ac..49c4c81caa 100644 --- a/src/net/http/pprof/pprof_test.go +++ b/src/net/http/pprof/pprof_test.go @@ -192,37 +192,25 @@ func TestDeltaProfile(t *testing.T) { <-done // wait for the goroutine to exit. }() - for _, tc := range []struct { - endpoint string - seconds int - mutexHog1, mutexHog2 bool - }{ - {"/debug/pprof/mutex?seconds=1", 1, false, true}, - {"/debug/pprof/mutex", 0, true, true}, - } { - t.Run(tc.endpoint, func(t *testing.T) { - p, err := query(tc.endpoint) - if err != nil { - t.Fatalf("failed to query profile: %v", err) - } - t.Logf("Profile=%v", p) - - if got := seen(p, "mutexHog1"); got != tc.mutexHog1 { - t.Errorf("seen(mutexHog1) = %t, want %t", got, tc.mutexHog1) - } - if got := seen(p, "mutexHog2"); got != tc.mutexHog2 { - t.Errorf("seen(mutexHog2) = %t, want %t", got, tc.mutexHog2) - } - - if tc.seconds > 0 { - got := time.Duration(p.DurationNanos) * time.Nanosecond - want := time.Duration(tc.seconds) * time.Second - if got < want/2 || got > 2*want { - t.Errorf("got duration = %v; want ~%v", got, want) - } - } - - }) + for _, d := range []int{1, 4, 16, 32} { + endpoint := fmt.Sprintf("/debug/pprof/mutex?seconds=%d", d) + p, err := query(endpoint) + if err != nil { + t.Fatalf("failed to query %q: %v", endpoint, err) + } + if !seen(p, "mutexHog1") && seen(p, "mutexHog2") && p.DurationNanos > 0 { + break // pass + } + if d == 32 { + t.Errorf("want mutexHog2 but no mutexHog1 in the profile, and non-zero p.DurationNanos, got %v", p) + } + } + p, err = query("/debug/pprof/mutex") + if err != nil { + t.Fatalf("failed to query mutex profile: %v", err) + } + if !seen(p, "mutexHog1") || !seen(p, "mutexHog2") { + t.Errorf("want both mutexHog1 and mutexHog2 in the profile, got %v", p) } } |
