]> Cypherpunks repositories - gostls13.git/commitdiff
os: avoid crashing with a thundering herd in TestPipeThreads
authorIan Lance Taylor <iant@golang.org>
Wed, 13 Sep 2017 18:16:40 +0000 (11:16 -0700)
committerIan Lance Taylor <iant@golang.org>
Wed, 13 Sep 2017 22:53:09 +0000 (22:53 +0000)
Fixes #21559

Change-Id: I3393c4bee4c84fe0724a9c9aeb1a809b1a92eea6
Reviewed-on: https://go-review.googlesource.com/63650
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Joe Tsai <joetsai@google.com>
src/os/os_test.go

index c8077863101a730b0f8dbd90195aaeb611bc87dd..86f8652a2e6fb3c984ad57247bad7c27805c227b 100644 (file)
@@ -2205,22 +2205,24 @@ func TestPipeThreads(t *testing.T) {
 
        defer debug.SetMaxThreads(debug.SetMaxThreads(threads / 2))
 
-       var wg sync.WaitGroup
-       wg.Add(threads)
-       c := make(chan bool, threads)
+       creading := make(chan bool, threads)
+       cdone := make(chan bool, threads)
        for i := 0; i < threads; i++ {
                go func(i int) {
-                       defer wg.Done()
                        var b [1]byte
-                       c <- true
+                       creading <- true
                        if _, err := r[i].Read(b[:]); err != nil {
                                t.Error(err)
                        }
+                       if err := r[i].Close(); err != nil {
+                               t.Error(err)
+                       }
+                       cdone <- true
                }(i)
        }
 
        for i := 0; i < threads; i++ {
-               <-c
+               <-creading
        }
 
        // If we are still alive, it means that the 100 goroutines did
@@ -2233,14 +2235,7 @@ func TestPipeThreads(t *testing.T) {
                if err := w[i].Close(); err != nil {
                        t.Error(err)
                }
-       }
-
-       wg.Wait()
-
-       for i := 0; i < threads; i++ {
-               if err := r[i].Close(); err != nil {
-                       t.Error(err)
-               }
+               <-cdone
        }
 }