@@ -155,7 +155,7 @@ func slowDialTCP(ctx context.Context, network string, laddr, raddr *TCPAddr) (*T
155
155
return c , err
156
156
}
157
157
158
- func dialClosedPort () (actual , expected time.Duration ) {
158
+ func dialClosedPort (t * testing. T ) (actual , expected time.Duration ) {
159
159
// Estimate the expected time for this platform.
160
160
// On Windows, dialing a closed port takes roughly 1 second,
161
161
// but other platforms should be instantaneous.
@@ -169,6 +169,7 @@ func dialClosedPort() (actual, expected time.Duration) {
169
169
170
170
l , err := Listen ("tcp" , "127.0.0.1:0" )
171
171
if err != nil {
172
+ t .Logf ("dialClosedPort: Listen failed: %v" , err )
172
173
return 999 * time .Hour , expected
173
174
}
174
175
addr := l .Addr ().String ()
@@ -184,6 +185,7 @@ func dialClosedPort() (actual, expected time.Duration) {
184
185
}
185
186
elapsed := time .Now ().Sub (startTime )
186
187
if i == 2 {
188
+ t .Logf ("dialClosedPort: measured delay %v" , elapsed )
187
189
return elapsed , expected
188
190
}
189
191
}
@@ -196,7 +198,7 @@ func TestDialParallel(t *testing.T) {
196
198
t .Skip ("both IPv4 and IPv6 are required" )
197
199
}
198
200
199
- closedPortDelay , expectClosedPortDelay := dialClosedPort ()
201
+ closedPortDelay , expectClosedPortDelay := dialClosedPort (t )
200
202
if closedPortDelay > expectClosedPortDelay {
201
203
t .Errorf ("got %v; want <= %v" , closedPortDelay , expectClosedPortDelay )
202
204
}
@@ -317,8 +319,14 @@ func TestDialParallel(t *testing.T) {
317
319
t .Errorf ("#%d: got nil; want non-nil" , i )
318
320
}
319
321
320
- expectElapsedMin := tt .expectElapsed - 95 * time .Millisecond
321
- expectElapsedMax := tt .expectElapsed + 95 * time .Millisecond
322
+ // We used to always use 95 milliseconds as the slop,
323
+ // but that was flaky on Windows. See issue 35616.
324
+ slop := 95 * time .Millisecond
325
+ if fifth := tt .expectElapsed / 5 ; fifth > slop {
326
+ slop = fifth
327
+ }
328
+ expectElapsedMin := tt .expectElapsed - slop
329
+ expectElapsedMax := tt .expectElapsed + slop
322
330
if elapsed < expectElapsedMin {
323
331
t .Errorf ("#%d: got %v; want >= %v" , i , elapsed , expectElapsedMin )
324
332
} else if elapsed > expectElapsedMax {
@@ -667,7 +675,7 @@ func TestDialerDualStack(t *testing.T) {
667
675
t .Skip ("both IPv4 and IPv6 are required" )
668
676
}
669
677
670
- closedPortDelay , expectClosedPortDelay := dialClosedPort ()
678
+ closedPortDelay , expectClosedPortDelay := dialClosedPort (t )
671
679
if closedPortDelay > expectClosedPortDelay {
672
680
t .Errorf ("got %v; want <= %v" , closedPortDelay , expectClosedPortDelay )
673
681
}
0 commit comments