Skip to content

Commit 6f65d47

Browse files
committed
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 <[email protected]> Run-TryBot: Michael Knyszek <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: David Chase <[email protected]>
1 parent 79b425e commit 6f65d47

File tree

1 file changed

+5
-30
lines changed

1 file changed

+5
-30
lines changed

src/runtime/debug_test.go

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,15 @@ func startDebugCallWorker(t *testing.T) (g *runtime.G, after func()) {
3434
skipUnderDebugger(t)
3535

3636
// This can deadlock if there aren't enough threads or if a GC
37-
// tries to interrupt an atomic loop (see issue #10958). We
37+
// tries to interrupt an atomic loop (see issue #10958). A GC
38+
// could also actively be in progress (see issue #49370), so we
39+
// need to call runtime.GC to block until it has complete. We
3840
// use 8 Ps so there's room for the debug call worker,
3941
// something that's trying to preempt the call worker, and the
4042
// goroutine that's trying to stop the call worker.
4143
ogomaxprocs := runtime.GOMAXPROCS(8)
4244
ogcpercent := debug.SetGCPercent(-1)
45+
runtime.GC()
4346

4447
// ready is a buffered channel so debugCallWorker won't block
4548
// on sending to it. This makes it less likely we'll catch
@@ -114,13 +117,6 @@ func skipUnderDebugger(t *testing.T) {
114117
}
115118

116119
func TestDebugCall(t *testing.T) {
117-
// InjectDebugCall cannot be executed while a GC is actively in
118-
// progress. Wait until the current GC is done, and turn it off.
119-
//
120-
// See #49370.
121-
runtime.GC()
122-
defer debug.SetGCPercent(debug.SetGCPercent(-1))
123-
124120
g, after := startDebugCallWorker(t)
125121
defer after()
126122

@@ -172,13 +168,6 @@ func TestDebugCall(t *testing.T) {
172168
}
173169

174170
func TestDebugCallLarge(t *testing.T) {
175-
// InjectDebugCall cannot be executed while a GC is actively in
176-
// progress. Wait until the current GC is done, and turn it off.
177-
//
178-
// See #49370.
179-
runtime.GC()
180-
defer debug.SetGCPercent(debug.SetGCPercent(-1))
181-
182171
g, after := startDebugCallWorker(t)
183172
defer after()
184173

@@ -208,13 +197,6 @@ func TestDebugCallLarge(t *testing.T) {
208197
}
209198

210199
func TestDebugCallGC(t *testing.T) {
211-
// InjectDebugCall cannot be executed while a GC is actively in
212-
// progress. Wait until the current GC is done, and turn it off.
213-
//
214-
// See #49370.
215-
runtime.GC()
216-
defer debug.SetGCPercent(debug.SetGCPercent(-1))
217-
218200
g, after := startDebugCallWorker(t)
219201
defer after()
220202

@@ -225,13 +207,6 @@ func TestDebugCallGC(t *testing.T) {
225207
}
226208

227209
func TestDebugCallGrowStack(t *testing.T) {
228-
// InjectDebugCall cannot be executed while a GC is actively in
229-
// progress. Wait until the current GC is done, and turn it off.
230-
//
231-
// See #49370.
232-
runtime.GC()
233-
defer debug.SetGCPercent(debug.SetGCPercent(-1))
234-
235210
g, after := startDebugCallWorker(t)
236211
defer after()
237212

@@ -294,7 +269,7 @@ func TestDebugCallPanic(t *testing.T) {
294269
// InjectDebugCall cannot be executed while a GC is actively in
295270
// progress. Wait until the current GC is done, and turn it off.
296271
//
297-
// See #49370.
272+
// See #10958 and #49370.
298273
runtime.GC()
299274
defer debug.SetGCPercent(debug.SetGCPercent(-1))
300275

0 commit comments

Comments
 (0)