From 6f65d470d8b688573891420f7a428191d8c6cd49 Mon Sep 17 00:00:00 2001 From: Michael Anthony Knyszek Date: Mon, 6 Dec 2021 17:53:35 -0500 Subject: [PATCH] runtime: clean up redundant calls to SetGCPercent in debug_test.go SetGCPercent(-1) is called by several tests in debug_test.go (followed by a call to runtime.GC) due to #49370. However, startDebugCallWorker already actually has this, just without the runtime.GC call (allowing an in-progress GC to still mess up the test). This CL consolidates SetGCPercent into startDebugDebugCallWorker where applicable. Change-Id: Ifa12d6a911f1506e252d3ddf03004cf2ab3f4ee4 Reviewed-on: https://go-review.googlesource.com/c/go/+/369751 Trust: Michael Knyszek Run-TryBot: Michael Knyszek TryBot-Result: Gopher Robot Reviewed-by: David Chase --- src/runtime/debug_test.go | 35 +++++------------------------------ 1 file changed, 5 insertions(+), 30 deletions(-) diff --git a/src/runtime/debug_test.go b/src/runtime/debug_test.go index 89ea577d644..44585b1744a 100644 --- a/src/runtime/debug_test.go +++ b/src/runtime/debug_test.go @@ -34,12 +34,15 @@ func startDebugCallWorker(t *testing.T) (g *runtime.G, after func()) { skipUnderDebugger(t) // This can deadlock if there aren't enough threads or if a GC - // tries to interrupt an atomic loop (see issue #10958). We + // tries to interrupt an atomic loop (see issue #10958). A GC + // could also actively be in progress (see issue #49370), so we + // need to call runtime.GC to block until it has complete. We // use 8 Ps so there's room for the debug call worker, // something that's trying to preempt the call worker, and the // goroutine that's trying to stop the call worker. ogomaxprocs := runtime.GOMAXPROCS(8) ogcpercent := debug.SetGCPercent(-1) + runtime.GC() // ready is a buffered channel so debugCallWorker won't block // on sending to it. This makes it less likely we'll catch @@ -114,13 +117,6 @@ func skipUnderDebugger(t *testing.T) { } func TestDebugCall(t *testing.T) { - // InjectDebugCall cannot be executed while a GC is actively in - // progress. Wait until the current GC is done, and turn it off. - // - // See #49370. - runtime.GC() - defer debug.SetGCPercent(debug.SetGCPercent(-1)) - g, after := startDebugCallWorker(t) defer after() @@ -172,13 +168,6 @@ func TestDebugCall(t *testing.T) { } func TestDebugCallLarge(t *testing.T) { - // InjectDebugCall cannot be executed while a GC is actively in - // progress. Wait until the current GC is done, and turn it off. - // - // See #49370. - runtime.GC() - defer debug.SetGCPercent(debug.SetGCPercent(-1)) - g, after := startDebugCallWorker(t) defer after() @@ -208,13 +197,6 @@ func TestDebugCallLarge(t *testing.T) { } func TestDebugCallGC(t *testing.T) { - // InjectDebugCall cannot be executed while a GC is actively in - // progress. Wait until the current GC is done, and turn it off. - // - // See #49370. - runtime.GC() - defer debug.SetGCPercent(debug.SetGCPercent(-1)) - g, after := startDebugCallWorker(t) defer after() @@ -225,13 +207,6 @@ func TestDebugCallGC(t *testing.T) { } func TestDebugCallGrowStack(t *testing.T) { - // InjectDebugCall cannot be executed while a GC is actively in - // progress. Wait until the current GC is done, and turn it off. - // - // See #49370. - runtime.GC() - defer debug.SetGCPercent(debug.SetGCPercent(-1)) - g, after := startDebugCallWorker(t) defer after() @@ -294,7 +269,7 @@ func TestDebugCallPanic(t *testing.T) { // InjectDebugCall cannot be executed while a GC is actively in // progress. Wait until the current GC is done, and turn it off. // - // See #49370. + // See #10958 and #49370. runtime.GC() defer debug.SetGCPercent(debug.SetGCPercent(-1))