aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan C. Mills <bcmills@google.com>2020-03-11 11:03:35 -0400
committerBryan C. Mills <bcmills@google.com>2020-03-11 16:49:13 +0000
commitcf82feabb634ece598044ffe98ff445daec35c0a (patch)
tree8c293194e7efd2160796c3db18369f635b84134a
parent211ee9f07cb454058fab5914117c19f33a7f64de (diff)
downloadgo-cf82feabb634ece598044ffe98ff445daec35c0a.tar.gz
go-cf82feabb634ece598044ffe98ff445daec35c0a.zip
net: use t.Deadline instead of an arbitrary read deadline in TestDialParallelSpuriousConnection
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 <dmitshur@golang.org>
-rw-r--r--src/net/dial_test.go10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/net/dial_test.go b/src/net/dial_test.go
index 493cdfc648..78feaae7f4 100644
--- a/src/net/dial_test.go
+++ b/src/net/dial_test.go
@@ -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) {
@@ -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)