mirror of
https://github.com/golang/go
synced 2024-09-15 22:20:06 +00:00
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 <gobot@golang.org> Reviewed-by: Cherry Mui <cherryyz@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> Auto-Submit: Bryan Mills <bcmills@google.com>
This commit is contained in:
parent
2a6e13843d
commit
db875f4d1b
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue