Commit 3cee5505 authored by Ian Lance Taylor's avatar Ian Lance Taylor

os: deflake TestNewFileNonBlock

Fixes #32325

Change-Id: Ic06938c36a25ef1a6623e35e128b73729d02d955
Reviewed-on: https://go-review.googlesource.com/c/go/+/179698
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent ba66d89d
...@@ -259,12 +259,19 @@ func newFileTest(t *testing.T, blocking bool) { ...@@ -259,12 +259,19 @@ func newFileTest(t *testing.T, blocking bool) {
} }
defer file.Close() defer file.Close()
timeToWrite := 100 * time.Millisecond
timeToDeadline := 1 * time.Millisecond
if !blocking {
// Use a longer time to avoid flakes.
// We won't be waiting this long anyhow.
timeToWrite = 1 * time.Second
}
// Try to read with deadline (but don't block forever). // Try to read with deadline (but don't block forever).
b := make([]byte, 1) b := make([]byte, 1)
// Send something after 100ms. timer := time.AfterFunc(timeToWrite, func() { syscall.Write(p[1], []byte("a")) })
timer := time.AfterFunc(100*time.Millisecond, func() { syscall.Write(p[1], []byte("a")) })
defer timer.Stop() defer timer.Stop()
file.SetReadDeadline(time.Now().Add(10 * time.Millisecond)) file.SetReadDeadline(time.Now().Add(timeToDeadline))
_, err := file.Read(b) _, err := file.Read(b)
if !blocking { if !blocking {
// We want it to fail with a timeout. // We want it to fail with a timeout.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment