]> Cypherpunks repositories - gostls13.git/commitdiff
net/http/pprof: make TestDeltaProfile less flaky by retrying
authorHana (Hyang-Ah) Kim <hyangah@gmail.com>
Wed, 22 Apr 2020 19:35:45 +0000 (15:35 -0400)
committerHyang-Ah Hana Kim <hyangah@gmail.com>
Wed, 22 Apr 2020 21:08:29 +0000 (21:08 +0000)
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>
src/net/http/pprof/pprof_test.go

index 5a6cfbd2ac8a55c869e48105d06ea20b0a83f03c..49c4c81caa003687f6827e82a6c76a4dd9810186 100644 (file)
@@ -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)
        }
 }