From 3cee55057f57a38003d8ff5f8495dbf82f91d5ef Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Thu, 30 May 2019 18:08:08 -0400 Subject: [PATCH] os: deflake TestNewFileNonBlock Fixes #32325 Change-Id: Ic06938c36a25ef1a6623e35e128b73729d02d955 Reviewed-on: https://go-review.googlesource.com/c/go/+/179698 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/os/os_unix_test.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/os/os_unix_test.go b/src/os/os_unix_test.go index fa4c594136..45cb6fc21f 100644 --- a/src/os/os_unix_test.go +++ b/src/os/os_unix_test.go @@ -259,12 +259,19 @@ func newFileTest(t *testing.T, blocking bool) { } 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). b := make([]byte, 1) - // Send something after 100ms. - timer := time.AfterFunc(100*time.Millisecond, func() { syscall.Write(p[1], []byte("a")) }) + timer := time.AfterFunc(timeToWrite, func() { syscall.Write(p[1], []byte("a")) }) defer timer.Stop() - file.SetReadDeadline(time.Now().Add(10 * time.Millisecond)) + file.SetReadDeadline(time.Now().Add(timeToDeadline)) _, err := file.Read(b) if !blocking { // We want it to fail with a timeout. -- 2.50.0