From 7c1a9e8616c95f280a7b0a6f5fb66a2d559bbd19 Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Fri, 15 Jan 2021 18:00:40 -0800 Subject: [PATCH] net/nettest: de-flake tests on Windows Windows has a low resolution timer. Some of the tests assumed that unblock takes effect immediately. Consider: t := time.Now() elapsed := time.Now().After(t) It seems plausible that elapsed should always be true. However, with a low resolution timer, that might fail. Change time.Now().After to !time.Now().Before, so that unblocking always takes effect immediately. Fixes #873. --- net/nettest/pipe.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/nettest/pipe.go b/net/nettest/pipe.go index e4c6e18ac..366a23069 100644 --- a/net/nettest/pipe.go +++ b/net/nettest/pipe.go @@ -60,7 +60,7 @@ func (p *Pipe) Read(b []byte) (n int, err error) { for { p.mu.Lock() closed := p.closed - timedout := !p.readTimeout.IsZero() && time.Now().After(p.readTimeout) + timedout := !p.readTimeout.IsZero() && !time.Now().Before(p.readTimeout) blocked := p.blocked if !closed && !timedout && len(p.buf) > 0 { n2 := copy(b, p.buf) @@ -99,7 +99,7 @@ func (p *Pipe) Write(b []byte) (n int, err error) { for { p.mu.Lock() closed := p.closed - timedout := !p.writeTimeout.IsZero() && time.Now().After(p.writeTimeout) + timedout := !p.writeTimeout.IsZero() && !time.Now().Before(p.writeTimeout) blocked := p.blocked if !closed && !timedout { n2 := len(b)