]> Cypherpunks repositories - gostls13.git/commitdiff
testing: in TestRacyOutput, ensure that the Run calls complete before cleanup
authorBryan C. Mills <bcmills@google.com>
Wed, 16 Nov 2022 15:17:17 +0000 (10:17 -0500)
committerGopher Robot <gobot@golang.org>
Wed, 16 Nov 2022 17:22:19 +0000 (17:22 +0000)
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>

src/testing/panic_test.go
src/testing/sub_test.go
src/testing/testing.go

index 4648057b77466ed8bce7a547ff34f55af84104f7..8733bc3f30cef4067ea928ac72b2cfd9b1891543 100644 (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`,
                },
        }
 
index e1da99d07af39217e44e9b2930acb40d3073d9a2..55b14c3795ff35355f3f2b481393da60c13c53c2 100644 (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)
index 9c6b6605821edcd02b8d2c49ac31054dd1d8e512..acd28667c2803dc82e6ee9540028fb7641f58ef7 100644 (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)