mirror of
https://github.com/golang/go.git
synced 2025-05-05 15:43:04 +00:00
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: Bryan C. Mills <bcmills@google.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
parent
5042317d69
commit
c20b71eb37
@ -155,7 +155,7 @@ func slowDialTCP(ctx context.Context, network string, laddr, raddr *TCPAddr) (*T
|
|||||||
return c, err
|
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.
|
// Estimate the expected time for this platform.
|
||||||
// On Windows, dialing a closed port takes roughly 1 second,
|
// On Windows, dialing a closed port takes roughly 1 second,
|
||||||
// but other platforms should be instantaneous.
|
// 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")
|
l, err := Listen("tcp", "127.0.0.1:0")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
t.Logf("dialClosedPort: Listen failed: %v", err)
|
||||||
return 999 * time.Hour, expected
|
return 999 * time.Hour, expected
|
||||||
}
|
}
|
||||||
addr := l.Addr().String()
|
addr := l.Addr().String()
|
||||||
@ -184,6 +185,7 @@ func dialClosedPort() (actual, expected time.Duration) {
|
|||||||
}
|
}
|
||||||
elapsed := time.Now().Sub(startTime)
|
elapsed := time.Now().Sub(startTime)
|
||||||
if i == 2 {
|
if i == 2 {
|
||||||
|
t.Logf("dialClosedPort: measured delay %v", elapsed)
|
||||||
return elapsed, expected
|
return elapsed, expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -196,7 +198,7 @@ func TestDialParallel(t *testing.T) {
|
|||||||
t.Skip("both IPv4 and IPv6 are required")
|
t.Skip("both IPv4 and IPv6 are required")
|
||||||
}
|
}
|
||||||
|
|
||||||
closedPortDelay, expectClosedPortDelay := dialClosedPort()
|
closedPortDelay, expectClosedPortDelay := dialClosedPort(t)
|
||||||
if closedPortDelay > expectClosedPortDelay {
|
if closedPortDelay > expectClosedPortDelay {
|
||||||
t.Errorf("got %v; want <= %v", 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)
|
t.Errorf("#%d: got nil; want non-nil", i)
|
||||||
}
|
}
|
||||||
|
|
||||||
expectElapsedMin := tt.expectElapsed - 95*time.Millisecond
|
// We used to always use 95 milliseconds as the slop,
|
||||||
expectElapsedMax := tt.expectElapsed + 95*time.Millisecond
|
// 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 {
|
if elapsed < expectElapsedMin {
|
||||||
t.Errorf("#%d: got %v; want >= %v", i, elapsed, expectElapsedMin)
|
t.Errorf("#%d: got %v; want >= %v", i, elapsed, expectElapsedMin)
|
||||||
} else if elapsed > expectElapsedMax {
|
} else if elapsed > expectElapsedMax {
|
||||||
@ -667,7 +675,7 @@ func TestDialerDualStack(t *testing.T) {
|
|||||||
t.Skip("both IPv4 and IPv6 are required")
|
t.Skip("both IPv4 and IPv6 are required")
|
||||||
}
|
}
|
||||||
|
|
||||||
closedPortDelay, expectClosedPortDelay := dialClosedPort()
|
closedPortDelay, expectClosedPortDelay := dialClosedPort(t)
|
||||||
if closedPortDelay > expectClosedPortDelay {
|
if closedPortDelay > expectClosedPortDelay {
|
||||||
t.Errorf("got %v; want <= %v", closedPortDelay, expectClosedPortDelay)
|
t.Errorf("got %v; want <= %v", closedPortDelay, expectClosedPortDelay)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user