Skip to content

Commit db875f4

Browse files
Bryan C. Millsgopherbot
Bryan C. Mills
authored andcommitted
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 <[email protected]> Reviewed-by: Cherry Mui <[email protected]> Run-TryBot: Bryan Mills <[email protected]> Auto-Submit: Bryan Mills <[email protected]>
1 parent 2a6e138 commit db875f4

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/runtime/pprof/pprof_test.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -437,10 +437,14 @@ func testCPUProfile(t *testing.T, matches profileMatchFunc, f func(dur time.Dura
437437

438438
broken := cpuProfilingBroken()
439439

440-
maxDuration := 5 * time.Second
441-
if testing.Short() && broken {
442-
// If it's expected to be broken, no point waiting around.
443-
maxDuration /= 10
440+
deadline, ok := t.Deadline()
441+
if broken || !ok {
442+
if broken && testing.Short() {
443+
// If it's expected to be broken, no point waiting around.
444+
deadline = time.Now().Add(1 * time.Second)
445+
} else {
446+
deadline = time.Now().Add(10 * time.Second)
447+
}
444448
}
445449

446450
// 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
455459
// several others under go test std. If a test fails in a way
456460
// that could mean it just didn't run long enough, try with a
457461
// longer duration.
458-
for duration <= maxDuration {
462+
for {
459463
var prof bytes.Buffer
460464
if err := StartCPUProfile(&prof); err != nil {
461465
t.Fatal(err)
@@ -468,9 +472,10 @@ func testCPUProfile(t *testing.T, matches profileMatchFunc, f func(dur time.Dura
468472
}
469473

470474
duration *= 2
471-
if duration <= maxDuration {
472-
t.Logf("retrying with %s duration", duration)
475+
if time.Until(deadline) < duration {
476+
break
473477
}
478+
t.Logf("retrying with %s duration", duration)
474479
}
475480

476481
if broken {

0 commit comments

Comments
 (0)