From: Bryan C. Mills Date: Mon, 16 May 2022 15:41:12 +0000 (-0400) Subject: runtime/pprof: eliminate arbitrary deadline in testCPUProfile X-Git-Tag: go1.19beta1~230 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=db875f4d1b125e41a3999e3dd5c30d6b1bce235c;p=gostls13.git runtime/pprof: eliminate arbitrary deadline in testCPUProfile The testCPUProfile helper function iterates until the profile contains enough samples. However, in general very slow builders may need longer to complete tests, and may have less-responsive schedulers (leading to longer durations required to collect profiles with enough samples). To compensate, slower builders generally run tests with longer timeouts. Since this test helper already dynamically scales the profile duration based on the collected samples, allow it to continue to retry and rescale until it would exceed the test's deadline. Fixes #52656 (hopefully). Change-Id: I4561e721927503f33a6d23336efa979bb9d3221f Reviewed-on: https://go-review.googlesource.com/c/go/+/406614 TryBot-Result: Gopher Robot Reviewed-by: Cherry Mui Run-TryBot: Bryan Mills Auto-Submit: Bryan Mills --- diff --git a/src/runtime/pprof/pprof_test.go b/src/runtime/pprof/pprof_test.go index eeb7b2758b..faefd857f0 100644 --- a/src/runtime/pprof/pprof_test.go +++ b/src/runtime/pprof/pprof_test.go @@ -437,10 +437,14 @@ func testCPUProfile(t *testing.T, matches profileMatchFunc, f func(dur time.Dura broken := cpuProfilingBroken() - maxDuration := 5 * time.Second - if testing.Short() && broken { - // If it's expected to be broken, no point waiting around. - maxDuration /= 10 + deadline, ok := t.Deadline() + if broken || !ok { + if broken && testing.Short() { + // If it's expected to be broken, no point waiting around. + deadline = time.Now().Add(1 * time.Second) + } else { + deadline = time.Now().Add(10 * time.Second) + } } // If we're running a long test, start with a long duration @@ -455,7 +459,7 @@ func testCPUProfile(t *testing.T, matches profileMatchFunc, f func(dur time.Dura // several others under go test std. If a test fails in a way // that could mean it just didn't run long enough, try with a // longer duration. - for duration <= maxDuration { + for { var prof bytes.Buffer if err := StartCPUProfile(&prof); err != nil { t.Fatal(err) @@ -468,9 +472,10 @@ func testCPUProfile(t *testing.T, matches profileMatchFunc, f func(dur time.Dura } duration *= 2 - if duration <= maxDuration { - t.Logf("retrying with %s duration", duration) + if time.Until(deadline) < duration { + break } + t.Logf("retrying with %s duration", duration) } if broken {