]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: call runtime.GC in several tests that disable GC
authorMichael Anthony Knyszek <mknyszek@google.com>
Mon, 6 Dec 2021 22:35:58 +0000 (17:35 -0500)
committerMichael Knyszek <mknyszek@google.com>
Mon, 6 Dec 2021 23:02:28 +0000 (23:02 +0000)
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>

src/runtime/proc_test.go
src/runtime/testdata/testprog/badtraceback.go
src/runtime/testdata/testprog/preempt.go

index 53cafe8907fc0962f5b13cd3df15fa1dbfb2dc88..9198022ace2f04cad4c7a4dcb8520c86a25da345 100644 (file)
@@ -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() {
index d558adceec3f95b971c8b78f998265bc5bc68bf8..09aa2b877ecf5a108812479ee0cde2c525d1da9e 100644 (file)
@@ -17,6 +17,9 @@ func init() {
 func BadTraceback() {
        // Disable GC to prevent traceback at unexpected time.
        debug.SetGCPercent(-1)
+       // Out of an abundance of caution, also make sure that there are
+       // no GCs actively in progress.
+       runtime.GC()
 
        // Run badLR1 on its own stack to minimize the stack size and
        // exercise the stack bounds logic in the hex dump.
index 1c74d0e435238afa383b9e93ad8e3807d43cc9d3..eb9f59053cf170af9b38cf0035a4bd40157beca2 100644 (file)
@@ -20,6 +20,9 @@ func AsyncPreempt() {
        runtime.GOMAXPROCS(1)
        // Disable GC so we have complete control of what we're testing.
        debug.SetGCPercent(-1)
+       // Out of an abundance of caution, also make sure that there are
+       // no GCs actively in progress.
+       runtime.GC()
 
        // Start a goroutine with no sync safe-points.
        var ready, ready2 uint32