Skip to content

Commit

Permalink
net: use t.Deadline instead of an arbitrary read deadline in TestDial…
Browse files Browse the repository at this point in the history
…ParallelSpuriousConnection

Also increase the default deadline to 5s, since it empirically
doesn't need to be short and 1s seems to be too slow on some platforms.

Fixes #37795

Change-Id: Ie6bf3916b107401235a1fa8cb0f22c4a98eb2dae
Reviewed-on: https://go-review.googlesource.com/c/go/+/222959
Reviewed-by: Dmitri Shuralyov <[email protected]>
  • Loading branch information
Bryan C. Mills committed Mar 11, 2020
1 parent 211ee9f commit cf82fea
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/net/dial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,14 @@ func TestDialParallelSpuriousConnection(t *testing.T) {
t.Skip("both IPv4 and IPv6 are required")
}

var readDeadline time.Time
if td, ok := t.Deadline(); ok {
const arbitraryCleanupMargin = 1 * time.Second
readDeadline = td.Add(-arbitraryCleanupMargin)
} else {
readDeadline = time.Now().Add(5 * time.Second)
}

var wg sync.WaitGroup
wg.Add(2)
handler := func(dss *dualStackServer, ln Listener) {
Expand All @@ -450,7 +458,7 @@ func TestDialParallelSpuriousConnection(t *testing.T) {
t.Fatal(err)
}
// The client should close itself, without sending data.
c.SetReadDeadline(time.Now().Add(1 * time.Second))
c.SetReadDeadline(readDeadline)
var b [1]byte
if _, err := c.Read(b[:]); err != io.EOF {
t.Errorf("got %v; want %v", err, io.EOF)
Expand Down

0 comments on commit cf82fea

Please sign in to comment.