aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Anthony Knyszek <mknyszek@google.com>2021-07-09 17:34:07 +0000
committerMichael Knyszek <mknyszek@google.com>2021-07-09 18:00:16 +0000
commitab4085ce84f8378b4ec2dfdbbc44c98cb92debe5 (patch)
treebfc896f25e9aeec4d7ec3aff5987d9b0601bb1d0
parent296ddf2a936a30866303a64d49bc0e3e034730a8 (diff)
downloadgo-ab4085ce84f8378b4ec2dfdbbc44c98cb92debe5.tar.gz
go-ab4085ce84f8378b4ec2dfdbbc44c98cb92debe5.zip
runtime/pprof: call runtime.GC twice in memory profile test
This change fixes #46500 by working around #45315 which may cause freed objects to get missed in the heap profile published for the test. By calling runtime.GC one more time this change ensures that all freed objects are accounted for. Fixes #46500. Change-Id: Iedcd0b37dbaffa688b0ff8631a8b79f7a1169634 Reviewed-on: https://go-review.googlesource.com/c/go/+/333549 Trust: Michael Knyszek <mknyszek@google.com> Run-TryBot: Michael Knyszek <mknyszek@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com>
-rw-r--r--src/runtime/pprof/mprof_test.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/runtime/pprof/mprof_test.go b/src/runtime/pprof/mprof_test.go
index 3ef40d3de7..b4680fbdee 100644
--- a/src/runtime/pprof/mprof_test.go
+++ b/src/runtime/pprof/mprof_test.go
@@ -86,6 +86,17 @@ func TestMemoryProfiler(t *testing.T) {
runtime.GC() // materialize stats
+ // TODO(mknyszek): Fix #45315 and remove this extra call.
+ //
+ // Unfortunately, it's possible for the sweep termination condition
+ // to flap, so with just one runtime.GC call, a freed object could be
+ // missed, leading this test to fail. A second call reduces the chance
+ // of this happening to zero, because sweeping actually has to finish
+ // to move on to the next GC, during which nothing will happen.
+ //
+ // See #46500 for more details.
+ runtime.GC()
+
memoryProfilerRun++
tests := []struct {