]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: ensure no GC is running in TestParallelRWMutexReaders
authorMichael Anthony Knyszek <mknyszek@google.com>
Tue, 23 Nov 2021 14:30:56 +0000 (14:30 +0000)
committerMichael Knyszek <mknyszek@google.com>
Tue, 23 Nov 2021 16:00:03 +0000 (16:00 +0000)
Currently this test makes it clear that it's unsafe for a GC to run,
otherwise a deadlock could occur, so it calls SetGCPercent(-1). However,
a GC may be actively in progress, and SetGCPercent is not going to end
any in-progress GC. Call runtime.GC to block until at least the current
GC is over.

Updates #49680.

Change-Id: Ibdc7d378e8cf7e05270910e92effcad8c6874e59
Reviewed-on: https://go-review.googlesource.com/c/go/+/366534
Trust: Michael Knyszek <mknyszek@google.com>
Run-TryBot: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
src/runtime/rwmutex_test.go

index 291a32ea5ec31975231223b13cfce74319db943a..33ddd7d1d59c09a81ea0a5b1205dec7f34a59869 100644 (file)
@@ -55,6 +55,9 @@ func TestParallelRWMutexReaders(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))
+       // Finish any in-progress GCs and get ourselves to a clean slate.
+       GC()
+
        doTestParallelReaders(1)
        doTestParallelReaders(3)
        doTestParallelReaders(4)