Skip to content

Commit 7e87a63

Browse files
ianlancetaylordmitshur
authored andcommitted
[release-branch.go1.13] net: add more timing slop for TestDialParallel on Windows
For #35616. Fixes #39538. For #29252. Change-Id: I51b2490100cfe0e902da09eee8d027e0ec86ed53 Reviewed-on: https://go-review.googlesource.com/c/go/+/207466 Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]> (cherry picked from commit c20b71e) Reviewed-on: https://go-review.googlesource.com/c/go/+/237602 Run-TryBot: Dmitri Shuralyov <[email protected]> Reviewed-by: Alexander Rakoczy <[email protected]>
1 parent 034ed80 commit 7e87a63

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/net/dial_test.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ func slowDialTCP(ctx context.Context, network string, laddr, raddr *TCPAddr) (*T
154154
return c, err
155155
}
156156

157-
func dialClosedPort() (actual, expected time.Duration) {
157+
func dialClosedPort(t *testing.T) (actual, expected time.Duration) {
158158
// Estimate the expected time for this platform.
159159
// On Windows, dialing a closed port takes roughly 1 second,
160160
// but other platforms should be instantaneous.
@@ -168,6 +168,7 @@ func dialClosedPort() (actual, expected time.Duration) {
168168

169169
l, err := Listen("tcp", "127.0.0.1:0")
170170
if err != nil {
171+
t.Logf("dialClosedPort: Listen failed: %v", err)
171172
return 999 * time.Hour, expected
172173
}
173174
addr := l.Addr().String()
@@ -183,6 +184,7 @@ func dialClosedPort() (actual, expected time.Duration) {
183184
}
184185
elapsed := time.Now().Sub(startTime)
185186
if i == 2 {
187+
t.Logf("dialClosedPort: measured delay %v", elapsed)
186188
return elapsed, expected
187189
}
188190
}
@@ -195,7 +197,7 @@ func TestDialParallel(t *testing.T) {
195197
t.Skip("both IPv4 and IPv6 are required")
196198
}
197199

198-
closedPortDelay, expectClosedPortDelay := dialClosedPort()
200+
closedPortDelay, expectClosedPortDelay := dialClosedPort(t)
199201
if closedPortDelay > expectClosedPortDelay {
200202
t.Errorf("got %v; want <= %v", closedPortDelay, expectClosedPortDelay)
201203
}
@@ -316,8 +318,14 @@ func TestDialParallel(t *testing.T) {
316318
t.Errorf("#%d: got nil; want non-nil", i)
317319
}
318320

319-
expectElapsedMin := tt.expectElapsed - 95*time.Millisecond
320-
expectElapsedMax := tt.expectElapsed + 95*time.Millisecond
321+
// We used to always use 95 milliseconds as the slop,
322+
// but that was flaky on Windows. See issue 35616.
323+
slop := 95 * time.Millisecond
324+
if fifth := tt.expectElapsed / 5; fifth > slop {
325+
slop = fifth
326+
}
327+
expectElapsedMin := tt.expectElapsed - slop
328+
expectElapsedMax := tt.expectElapsed + slop
321329
if elapsed < expectElapsedMin {
322330
t.Errorf("#%d: got %v; want >= %v", i, elapsed, expectElapsedMin)
323331
} else if elapsed > expectElapsedMax {
@@ -664,7 +672,7 @@ func TestDialerDualStack(t *testing.T) {
664672
t.Skip("both IPv4 and IPv6 are required")
665673
}
666674

667-
closedPortDelay, expectClosedPortDelay := dialClosedPort()
675+
closedPortDelay, expectClosedPortDelay := dialClosedPort(t)
668676
if closedPortDelay > expectClosedPortDelay {
669677
t.Errorf("got %v; want <= %v", closedPortDelay, expectClosedPortDelay)
670678
}

0 commit comments

Comments
 (0)