Skip to content

Commit cf82fea

Browse files
author
Bryan C. Mills
committed
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 golang#37795 Change-Id: Ie6bf3916b107401235a1fa8cb0f22c4a98eb2dae Reviewed-on: https://go-review.googlesource.com/c/go/+/222959 Reviewed-by: Dmitri Shuralyov <[email protected]>
1 parent 211ee9f commit cf82fea

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/net/dial_test.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,14 @@ func TestDialParallelSpuriousConnection(t *testing.T) {
441441
t.Skip("both IPv4 and IPv6 are required")
442442
}
443443

444+
var readDeadline time.Time
445+
if td, ok := t.Deadline(); ok {
446+
const arbitraryCleanupMargin = 1 * time.Second
447+
readDeadline = td.Add(-arbitraryCleanupMargin)
448+
} else {
449+
readDeadline = time.Now().Add(5 * time.Second)
450+
}
451+
444452
var wg sync.WaitGroup
445453
wg.Add(2)
446454
handler := func(dss *dualStackServer, ln Listener) {
@@ -450,7 +458,7 @@ func TestDialParallelSpuriousConnection(t *testing.T) {
450458
t.Fatal(err)
451459
}
452460
// The client should close itself, without sending data.
453-
c.SetReadDeadline(time.Now().Add(1 * time.Second))
461+
c.SetReadDeadline(readDeadline)
454462
var b [1]byte
455463
if _, err := c.Read(b[:]); err != io.EOF {
456464
t.Errorf("got %v; want %v", err, io.EOF)

0 commit comments

Comments
 (0)