mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
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>
This commit is contained in:
parent
8d31ca255b
commit
00a053bd4b
2 changed files with 25 additions and 0 deletions
21
src/cmd/go/testdata/script/testing_issue40908.txt
vendored
Normal file
21
src/cmd/go/testdata/script/testing_issue40908.txt
vendored
Normal file
|
|
@ -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
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -860,11 +860,15 @@ func (c *common) Cleanup(f func()) {
|
||||||
c.cleanup = func() {
|
c.cleanup = func() {
|
||||||
if oldCleanup != nil {
|
if oldCleanup != nil {
|
||||||
defer func() {
|
defer func() {
|
||||||
|
c.mu.Lock()
|
||||||
c.cleanupPc = oldCleanupPc
|
c.cleanupPc = oldCleanupPc
|
||||||
|
c.mu.Unlock()
|
||||||
oldCleanup()
|
oldCleanup()
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
c.mu.Lock()
|
||||||
c.cleanupName = callerName(0)
|
c.cleanupName = callerName(0)
|
||||||
|
c.mu.Unlock()
|
||||||
f()
|
f()
|
||||||
}
|
}
|
||||||
var pc [maxStackLen]uintptr
|
var pc [maxStackLen]uintptr
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue