testing: in TestRacyOutput, ensure that the Run calls complete before cleanup

Also tweak the failure message added in CL 352349.

Updates #18741.
Updates #48515.

Change-Id: I46ed84c6f498d7a68414cc3dab3c1cd55da69aa9
Reviewed-on: https://go-review.googlesource.com/c/go/+/451215
Reviewed-by: Austin Clements <austin@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Changkun Ou <mail@changkun.de>
Auto-Submit: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
Bryan C. Mills 2022-11-16 10:17:17 -05:00 committed by Gopher Robot
parent 0266671e3d
commit 8c17505da7
3 changed files with 4 additions and 4 deletions

View File

@ -227,7 +227,7 @@ func TestMorePanic(t *testing.T) {
{
desc: "Issue 48515: call t.Run in t.Cleanup should trigger panic",
flags: []string{"-test.run=TestCallRunInCleanupHelper"},
want: `panic: testing: t.Run is called during t.Cleanup`,
want: `panic: testing: t.Run called during t.Cleanup`,
},
}

View File

@ -805,13 +805,13 @@ func TestRacyOutput(t *T) {
return len(b), nil
}
var wg sync.WaitGroup
root := &T{
common: common{w: &funcWriter{raceDetector}},
context: newTestContext(1, allMatcher()),
}
root.chatty = newChattyPrinter(root.w)
root.Run("", func(t *T) {
var wg sync.WaitGroup
for i := 0; i < 100; i++ {
wg.Add(1)
go func(i int) {
@ -821,8 +821,8 @@ func TestRacyOutput(t *T) {
})
}(i)
}
wg.Wait()
})
wg.Wait()
if races > 0 {
t.Errorf("detected %d racy Writes", races)

View File

@ -1588,7 +1588,7 @@ func tRunner(t *T, fn func(t *T)) {
// must return before the outer test function for t returns.
func (t *T) Run(name string, f func(t *T)) bool {
if t.cleanupStarted.Load() {
panic("testing: t.Run is called during t.Cleanup")
panic("testing: t.Run called during t.Cleanup")
}
t.hasSub.Store(true)