]> Cypherpunks repositories - gostls13.git/commitdiff
sync: deflake TestWaitGroupMisuse3
authorIan Lance Taylor <iant@golang.org>
Thu, 5 Dec 2019 22:49:25 +0000 (14:49 -0800)
committerIan Lance Taylor <iant@golang.org>
Fri, 6 Dec 2019 05:12:15 +0000 (05:12 +0000)
If one of the helper goroutine panics, the main goroutine call to Wait
may hang forever waiting for something to call Done. Put that call in
a goroutine like the others.

Fixes #35774

Change-Id: I8d2b58d8f473644a49a95338f70111d4e6ed4e12
Reviewed-on: https://go-review.googlesource.com/c/go/+/210218
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
src/sync/waitgroup_test.go

index 4ab438cbab1c1e19504448b39ca0f9928c47f13a..c569e0faa2ebf21950dd7442bf7de9c869a3ec1c 100644 (file)
@@ -147,7 +147,7 @@ func TestWaitGroupMisuse3(t *testing.T) {
                }
        }()
        defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(4))
-       done := make(chan interface{}, 2)
+       done := make(chan interface{}, 3)
        // The detection is opportunistically, so we want it to panic
        // at least in one run out of a million.
        for i := 0; i < 1e6; i++ {
@@ -171,8 +171,13 @@ func TestWaitGroupMisuse3(t *testing.T) {
                        }()
                        wg.Wait()
                }()
-               wg.Wait()
-               for j := 0; j < 2; j++ {
+               go func() {
+                       defer func() {
+                               done <- recover()
+                       }()
+                       wg.Wait()
+               }()
+               for j := 0; j < 3; j++ {
                        if err := <-done; err != nil {
                                panic(err)
                        }