aboutsummaryrefslogtreecommitdiff
path: root/src/net/timeout_test.go
diff options
context:
space:
mode:
authorDmitri Goutnik <dgoutnik@gmail.com>2022-06-17 12:10:09 -0500
committerDamien Neil <dneil@google.com>2022-06-17 21:21:26 +0000
commitdd2d00f9d57ba6aafb084d83ffc7fb35f97b8c84 (patch)
treec093d5067e1df8f0c9ee946840b51d6ab8a64605 /src/net/timeout_test.go
parent6c25ba624fd032a20dcfa94f9f9f0ae32c57c54b (diff)
downloadgo-dd2d00f9d57ba6aafb084d83ffc7fb35f97b8c84.tar.xz
net: fix flaky *TimeoutMustNotReturn tests
The tester goroutine doesn't always gets a chance to run before the timeout expires. Wait for the goroutine to start and set deadlines before staring the timer. Fixes #36796 Change-Id: Iffed6259de31340c3f66e34da473826a1d09fcde Reviewed-on: https://go-review.googlesource.com/c/go/+/412858 Reviewed-by: Damien Neil <dneil@google.com> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/net/timeout_test.go')
-rw-r--r--src/net/timeout_test.go21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/net/timeout_test.go b/src/net/timeout_test.go
index d1cfbf853c..3ad026c490 100644
--- a/src/net/timeout_test.go
+++ b/src/net/timeout_test.go
@@ -243,8 +243,7 @@ func TestAcceptTimeoutMustNotReturn(t *testing.T) {
ln := newLocalListener(t, "tcp")
defer ln.Close()
- max := time.NewTimer(100 * time.Millisecond)
- defer max.Stop()
+ maxch := make(chan *time.Timer)
ch := make(chan error)
go func() {
if err := ln.(*TCPListener).SetDeadline(time.Now().Add(-5 * time.Second)); err != nil {
@@ -253,10 +252,14 @@ func TestAcceptTimeoutMustNotReturn(t *testing.T) {
if err := ln.(*TCPListener).SetDeadline(noDeadline); err != nil {
t.Error(err)
}
+ maxch <- time.NewTimer(100 * time.Millisecond)
_, err := ln.Accept()
ch <- err
}()
+ max := <-maxch
+ defer max.Stop()
+
select {
case err := <-ch:
if perr := parseAcceptError(err); perr != nil {
@@ -348,8 +351,7 @@ func TestReadTimeoutMustNotReturn(t *testing.T) {
}
defer c.Close()
- max := time.NewTimer(100 * time.Millisecond)
- defer max.Stop()
+ maxch := make(chan *time.Timer)
ch := make(chan error)
go func() {
if err := c.SetDeadline(time.Now().Add(-5 * time.Second)); err != nil {
@@ -361,11 +363,15 @@ func TestReadTimeoutMustNotReturn(t *testing.T) {
if err := c.SetReadDeadline(noDeadline); err != nil {
t.Error(err)
}
+ maxch <- time.NewTimer(100 * time.Millisecond)
var b [1]byte
_, err := c.Read(b[:])
ch <- err
}()
+ max := <-maxch
+ defer max.Stop()
+
select {
case err := <-ch:
if perr := parseReadError(err); perr != nil {
@@ -517,8 +523,7 @@ func TestWriteTimeoutMustNotReturn(t *testing.T) {
}
defer c.Close()
- max := time.NewTimer(100 * time.Millisecond)
- defer max.Stop()
+ maxch := make(chan *time.Timer)
ch := make(chan error)
go func() {
if err := c.SetDeadline(time.Now().Add(-5 * time.Second)); err != nil {
@@ -530,6 +535,7 @@ func TestWriteTimeoutMustNotReturn(t *testing.T) {
if err := c.SetWriteDeadline(noDeadline); err != nil {
t.Error(err)
}
+ maxch <- time.NewTimer(100 * time.Millisecond)
var b [1]byte
for {
if _, err := c.Write(b[:]); err != nil {
@@ -539,6 +545,9 @@ func TestWriteTimeoutMustNotReturn(t *testing.T) {
}
}()
+ max := <-maxch
+ defer max.Stop()
+
select {
case err := <-ch:
if perr := parseWriteError(err); perr != nil {