mirror of https://github.com/golang/go.git
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:
parent
0266671e3d
commit
8c17505da7
|
|
@ -227,7 +227,7 @@ func TestMorePanic(t *testing.T) {
|
||||||
{
|
{
|
||||||
desc: "Issue 48515: call t.Run in t.Cleanup should trigger panic",
|
desc: "Issue 48515: call t.Run in t.Cleanup should trigger panic",
|
||||||
flags: []string{"-test.run=TestCallRunInCleanupHelper"},
|
flags: []string{"-test.run=TestCallRunInCleanupHelper"},
|
||||||
want: `panic: testing: t.Run is called during t.Cleanup`,
|
want: `panic: testing: t.Run called during t.Cleanup`,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -805,13 +805,13 @@ func TestRacyOutput(t *T) {
|
||||||
return len(b), nil
|
return len(b), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
|
||||||
root := &T{
|
root := &T{
|
||||||
common: common{w: &funcWriter{raceDetector}},
|
common: common{w: &funcWriter{raceDetector}},
|
||||||
context: newTestContext(1, allMatcher()),
|
context: newTestContext(1, allMatcher()),
|
||||||
}
|
}
|
||||||
root.chatty = newChattyPrinter(root.w)
|
root.chatty = newChattyPrinter(root.w)
|
||||||
root.Run("", func(t *T) {
|
root.Run("", func(t *T) {
|
||||||
|
var wg sync.WaitGroup
|
||||||
for i := 0; i < 100; i++ {
|
for i := 0; i < 100; i++ {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func(i int) {
|
go func(i int) {
|
||||||
|
|
@ -821,8 +821,8 @@ func TestRacyOutput(t *T) {
|
||||||
})
|
})
|
||||||
}(i)
|
}(i)
|
||||||
}
|
}
|
||||||
|
wg.Wait()
|
||||||
})
|
})
|
||||||
wg.Wait()
|
|
||||||
|
|
||||||
if races > 0 {
|
if races > 0 {
|
||||||
t.Errorf("detected %d racy Writes", races)
|
t.Errorf("detected %d racy Writes", races)
|
||||||
|
|
|
||||||
|
|
@ -1588,7 +1588,7 @@ func tRunner(t *T, fn func(t *T)) {
|
||||||
// must return before the outer test function for t returns.
|
// must return before the outer test function for t returns.
|
||||||
func (t *T) Run(name string, f func(t *T)) bool {
|
func (t *T) Run(name string, f func(t *T)) bool {
|
||||||
if t.cleanupStarted.Load() {
|
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)
|
t.hasSub.Store(true)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue