From: Ian Lance Taylor Date: Wed, 13 Sep 2017 18:16:40 +0000 (-0700) Subject: os: avoid crashing with a thundering herd in TestPipeThreads X-Git-Tag: go1.10beta1~1107 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=29415eb2b92e78481897c4161ba99f5b09fa6102;p=gostls13.git os: avoid crashing with a thundering herd in TestPipeThreads Fixes #21559 Change-Id: I3393c4bee4c84fe0724a9c9aeb1a809b1a92eea6 Reviewed-on: https://go-review.googlesource.com/63650 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Joe Tsai --- diff --git a/src/os/os_test.go b/src/os/os_test.go index c807786310..86f8652a2e 100644 --- a/src/os/os_test.go +++ b/src/os/os_test.go @@ -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 } }