mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
os: deflake TestFdReadRace
The test would hang if the call to Fd set the pipe to be non-blocking before the Read entered the first read system call. Avoid that problem by writing data to the pipe to wake up the read. For #24481 Fixes #44818 Change-Id: I0b798874c7b81e7308a38ebbf657efc4392ffacd Reviewed-on: https://go-review.googlesource.com/c/go/+/322893 Trust: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Damien Neil <dneil@google.com>
This commit is contained in:
parent
a62c08734f
commit
3075ffc93e
1 changed files with 7 additions and 4 deletions
|
|
@ -442,12 +442,14 @@ func TestFdReadRace(t *testing.T) {
|
||||||
defer r.Close()
|
defer r.Close()
|
||||||
defer w.Close()
|
defer w.Close()
|
||||||
|
|
||||||
c := make(chan bool)
|
const count = 10
|
||||||
|
|
||||||
|
c := make(chan bool, 1)
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
var buf [10]byte
|
var buf [count]byte
|
||||||
r.SetReadDeadline(time.Now().Add(time.Minute))
|
r.SetReadDeadline(time.Now().Add(time.Minute))
|
||||||
c <- true
|
c <- true
|
||||||
if _, err := r.Read(buf[:]); os.IsTimeout(err) {
|
if _, err := r.Read(buf[:]); os.IsTimeout(err) {
|
||||||
|
|
@ -466,8 +468,9 @@ func TestFdReadRace(t *testing.T) {
|
||||||
r.Fd()
|
r.Fd()
|
||||||
|
|
||||||
// The bug was that Fd would hang until Read timed out.
|
// The bug was that Fd would hang until Read timed out.
|
||||||
// If the bug is fixed, then closing r here will cause
|
// If the bug is fixed, then writing to w and closing r here
|
||||||
// the Read to exit before the timeout expires.
|
// will cause the Read to exit before the timeout expires.
|
||||||
|
w.Write(make([]byte, count))
|
||||||
r.Close()
|
r.Close()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue