aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichał Łowicki <mlowicki@gmail.com>2020-08-23 23:53:04 +0100
committerBryan C. Mills <bcmills@google.com>2020-08-25 18:28:59 +0000
commit00a053bd4b2c19b2d9680f78f4c8657fcc6f1c88 (patch)
tree1d7df20758c884c9f13386d2bdf88800eb89bd67 /src
parent8d31ca255bd6b00d04f1673d26110b702e96662b (diff)
downloadgo-00a053bd4b2c19b2d9680f78f4c8657fcc6f1c88.tar.xz
testing: fix Cleanup race with Logf and Errorf
Fixes #40908 Change-Id: I25561a3f18e730a50e6fbf85aa7bd85bf1b73b6e Reviewed-on: https://go-review.googlesource.com/c/go/+/250078 Reviewed-by: Tobias Klauser <tobias.klauser@gmail.com> Run-TryBot: Bryan C. Mills <bcmills@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src')
-rw-r--r--src/cmd/go/testdata/script/testing_issue40908.txt21
-rw-r--r--src/testing/testing.go4
2 files changed, 25 insertions, 0 deletions
diff --git a/src/cmd/go/testdata/script/testing_issue40908.txt b/src/cmd/go/testdata/script/testing_issue40908.txt
new file mode 100644
index 0000000000..4939de080c
--- /dev/null
+++ b/src/cmd/go/testdata/script/testing_issue40908.txt
@@ -0,0 +1,21 @@
+[short] skip
+[!race] skip
+
+go test -race testrace
+
+-- testrace/race_test.go --
+package testrace
+
+import "testing"
+
+func TestRace(t *testing.T) {
+ helperDone := make(chan struct{})
+ go func() {
+ t.Logf("Something happened before cleanup.")
+ close(helperDone)
+ }()
+
+ t.Cleanup(func() {
+ <-helperDone
+ })
+}
diff --git a/src/testing/testing.go b/src/testing/testing.go
index 6fc8c4fa9f..bf83df8863 100644
--- a/src/testing/testing.go
+++ b/src/testing/testing.go
@@ -860,11 +860,15 @@ func (c *common) Cleanup(f func()) {
c.cleanup = func() {
if oldCleanup != nil {
defer func() {
+ c.mu.Lock()
c.cleanupPc = oldCleanupPc
+ c.mu.Unlock()
oldCleanup()
}()
}
+ c.mu.Lock()
c.cleanupName = callerName(0)
+ c.mu.Unlock()
f()
}
var pc [maxStackLen]uintptr