]> Cypherpunks repositories - gostls13.git/commitdiff
os: deflake TestNewFileNonBlock
authorIan Lance Taylor <iant@golang.org>
Thu, 30 May 2019 22:08:08 +0000 (18:08 -0400)
committerIan Lance Taylor <iant@golang.org>
Thu, 30 May 2019 22:39:04 +0000 (22:39 +0000)
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: Brad Fitzpatrick <bradfitz@golang.org>
src/os/os_unix_test.go

index fa4c594136aaea5e254335296a9b319820250f3f..45cb6fc21f2ee7f045786a072142bb384008ea8e 100644 (file)
@@ -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.