1
0
mirror of https://github.com/golang/go synced 2024-11-19 08:44:39 -07:00

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 <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Joe Tsai <joetsai@google.com>
This commit is contained in:
Ian Lance Taylor 2017-09-13 11:16:40 -07:00
parent c64e793850
commit 29415eb2b9

View 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
}
}