Commit e279280d authored by Mikio Hara's avatar Mikio Hara Committed by Brad Fitzpatrick

net: deflake TestAcceptTimeout

This change makes use of synchronization primitive instead of
context-based canceling not to depend on defer execution scheduling.

Fixes #17927.

Change-Id: I5ca9287a48bb5cdda6845a7f12757f95175c5db8
Reviewed-on: https://go-review.googlesource.com/33257Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent d8b14c52
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
package net package net
import ( import (
"context"
"fmt" "fmt"
"internal/testenv" "internal/testenv"
"io" "io"
...@@ -165,13 +164,14 @@ func TestAcceptTimeout(t *testing.T) { ...@@ -165,13 +164,14 @@ func TestAcceptTimeout(t *testing.T) {
} }
defer ln.Close() defer ln.Close()
ctx, cancel := context.WithCancel(context.Background()) var wg sync.WaitGroup
defer cancel()
for i, tt := range acceptTimeoutTests { for i, tt := range acceptTimeoutTests {
if tt.timeout < 0 { if tt.timeout < 0 {
wg.Add(1)
go func() { go func() {
var d Dialer defer wg.Done()
c, err := d.DialContext(ctx, ln.Addr().Network(), ln.Addr().String()) d := Dialer{Timeout: 100 * time.Millisecond}
c, err := d.Dial(ln.Addr().Network(), ln.Addr().String())
if err != nil { if err != nil {
t.Error(err) t.Error(err)
return return
...@@ -198,13 +198,14 @@ func TestAcceptTimeout(t *testing.T) { ...@@ -198,13 +198,14 @@ func TestAcceptTimeout(t *testing.T) {
} }
if err == nil { if err == nil {
c.Close() c.Close()
time.Sleep(tt.timeout / 3) time.Sleep(10 * time.Millisecond)
continue continue
} }
break break
} }
} }
} }
wg.Wait()
} }
func TestAcceptTimeoutMustReturn(t *testing.T) { func TestAcceptTimeoutMustReturn(t *testing.T) {
......
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