diff options
| author | Michael Anthony Knyszek <mknyszek@google.com> | 2021-12-06 17:35:58 -0500 |
|---|---|---|
| committer | Michael Knyszek <mknyszek@google.com> | 2021-12-06 23:02:28 +0000 |
| commit | 871d63fb73476bc3bf52ceec9aa8bef3ffc85d51 (patch) | |
| tree | c2a7e1ec6f0128e3debac85c3bdd44edc60fb8c6 /src/runtime/proc_test.go | |
| parent | 8ea0ffb84a5807438061d34256448df9948a3809 (diff) | |
| download | go-871d63fb73476bc3bf52ceec9aa8bef3ffc85d51.tar.xz | |
runtime: call runtime.GC in several tests that disable GC
These tests disable GC because of the potential for a deadlock, but
don't consider that a GC could be in progress due to other tests. The
likelihood of this case was increased when the minimum heap size was
lowered during the Go 1.18 cycle. The issue was then mitigated by
CL 368137 but in theory is always a problem.
This change is intended specifically for #45867, but I just walked over
a whole bunch of other tests that don't take this precaution where it
seems like it could be relevant (some tests it's not, like the
UserForcedGC test, or testprogs where no other code has run before it).
Fixes #45867.
Change-Id: I6a1b4ae73e05cab5a0b2d2cce14126bd13be0ba5
Reviewed-on: https://go-review.googlesource.com/c/go/+/369747
Reviewed-by: Michael Pratt <mpratt@google.com>
Reviewed-by: David Chase <drchase@google.com>
Trust: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/runtime/proc_test.go')
| -rw-r--r-- | src/runtime/proc_test.go | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/runtime/proc_test.go b/src/runtime/proc_test.go index 53cafe8907..9198022ace 100644 --- a/src/runtime/proc_test.go +++ b/src/runtime/proc_test.go @@ -119,6 +119,9 @@ func TestGoroutineParallelism(t *testing.T) { // since the goroutines can't be stopped/preempted. // Disable GC for this test (see issue #10958). defer debug.SetGCPercent(debug.SetGCPercent(-1)) + // Now that GCs are disabled, block until any outstanding GCs + // are also done. + runtime.GC() for try := 0; try < N; try++ { done := make(chan bool) x := uint32(0) @@ -163,6 +166,9 @@ func testGoroutineParallelism2(t *testing.T, load, netpoll bool) { // since the goroutines can't be stopped/preempted. // Disable GC for this test (see issue #10958). defer debug.SetGCPercent(debug.SetGCPercent(-1)) + // Now that GCs are disabled, block until any outstanding GCs + // are also done. + runtime.GC() for try := 0; try < N; try++ { if load { // Create P goroutines and wait until they all run. @@ -623,6 +629,9 @@ func TestSchedLocalQueueEmpty(t *testing.T) { // If runtime triggers a forced GC during this test then it will deadlock, // since the goroutines can't be stopped/preempted during spin wait. defer debug.SetGCPercent(debug.SetGCPercent(-1)) + // Now that GCs are disabled, block until any outstanding GCs + // are also done. + runtime.GC() iters := int(1e5) if testing.Short() { |
