Commit c20b71eb authored by Ian Lance Taylor's avatar Ian Lance Taylor

net: add more timing slop for TestDialParallel on Windows

Fixes #35616

Change-Id: I51b2490100cfe0e902da09eee8d027e0ec86ed53
Reviewed-on: https://go-review.googlesource.com/c/go/+/207466
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarBryan C. Mills <bcmills@google.com>
Reviewed-by: default avatarBrad Fitzpatrick <bradfitz@golang.org>
parent 5042317d
......@@ -155,7 +155,7 @@ func slowDialTCP(ctx context.Context, network string, laddr, raddr *TCPAddr) (*T
return c, err
}
func dialClosedPort() (actual, expected time.Duration) {
func dialClosedPort(t *testing.T) (actual, expected time.Duration) {
// Estimate the expected time for this platform.
// On Windows, dialing a closed port takes roughly 1 second,
// but other platforms should be instantaneous.
......@@ -169,6 +169,7 @@ func dialClosedPort() (actual, expected time.Duration) {
l, err := Listen("tcp", "127.0.0.1:0")
if err != nil {
t.Logf("dialClosedPort: Listen failed: %v", err)
return 999 * time.Hour, expected
}
addr := l.Addr().String()
......@@ -184,6 +185,7 @@ func dialClosedPort() (actual, expected time.Duration) {
}
elapsed := time.Now().Sub(startTime)
if i == 2 {
t.Logf("dialClosedPort: measured delay %v", elapsed)
return elapsed, expected
}
}
......@@ -196,7 +198,7 @@ func TestDialParallel(t *testing.T) {
t.Skip("both IPv4 and IPv6 are required")
}
closedPortDelay, expectClosedPortDelay := dialClosedPort()
closedPortDelay, expectClosedPortDelay := dialClosedPort(t)
if closedPortDelay > expectClosedPortDelay {
t.Errorf("got %v; want <= %v", closedPortDelay, expectClosedPortDelay)
}
......@@ -317,8 +319,14 @@ func TestDialParallel(t *testing.T) {
t.Errorf("#%d: got nil; want non-nil", i)
}
expectElapsedMin := tt.expectElapsed - 95*time.Millisecond
expectElapsedMax := tt.expectElapsed + 95*time.Millisecond
// We used to always use 95 milliseconds as the slop,
// but that was flaky on Windows. See issue 35616.
slop := 95 * time.Millisecond
if fifth := tt.expectElapsed / 5; fifth > slop {
slop = fifth
}
expectElapsedMin := tt.expectElapsed - slop
expectElapsedMax := tt.expectElapsed + slop
if elapsed < expectElapsedMin {
t.Errorf("#%d: got %v; want >= %v", i, elapsed, expectElapsedMin)
} else if elapsed > expectElapsedMax {
......@@ -667,7 +675,7 @@ func TestDialerDualStack(t *testing.T) {
t.Skip("both IPv4 and IPv6 are required")
}
closedPortDelay, expectClosedPortDelay := dialClosedPort()
closedPortDelay, expectClosedPortDelay := dialClosedPort(t)
if closedPortDelay > expectClosedPortDelay {
t.Errorf("got %v; want <= %v", closedPortDelay, expectClosedPortDelay)
}
......
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