@@ -154,7 +154,7 @@ func slowDialTCP(ctx context.Context, network string, laddr, raddr *TCPAddr) (*T
154
154
return c , err
155
155
}
156
156
157
- func dialClosedPort () (actual , expected time.Duration ) {
157
+ func dialClosedPort (t * testing. T ) (actual , expected time.Duration ) {
158
158
// Estimate the expected time for this platform.
159
159
// On Windows, dialing a closed port takes roughly 1 second,
160
160
// but other platforms should be instantaneous.
@@ -168,6 +168,7 @@ func dialClosedPort() (actual, expected time.Duration) {
168
168
169
169
l , err := Listen ("tcp" , "127.0.0.1:0" )
170
170
if err != nil {
171
+ t .Logf ("dialClosedPort: Listen failed: %v" , err )
171
172
return 999 * time .Hour , expected
172
173
}
173
174
addr := l .Addr ().String ()
@@ -183,6 +184,7 @@ func dialClosedPort() (actual, expected time.Duration) {
183
184
}
184
185
elapsed := time .Now ().Sub (startTime )
185
186
if i == 2 {
187
+ t .Logf ("dialClosedPort: measured delay %v" , elapsed )
186
188
return elapsed , expected
187
189
}
188
190
}
@@ -195,7 +197,7 @@ func TestDialParallel(t *testing.T) {
195
197
t .Skip ("both IPv4 and IPv6 are required" )
196
198
}
197
199
198
- closedPortDelay , expectClosedPortDelay := dialClosedPort ()
200
+ closedPortDelay , expectClosedPortDelay := dialClosedPort (t )
199
201
if closedPortDelay > expectClosedPortDelay {
200
202
t .Errorf ("got %v; want <= %v" , closedPortDelay , expectClosedPortDelay )
201
203
}
@@ -316,8 +318,14 @@ func TestDialParallel(t *testing.T) {
316
318
t .Errorf ("#%d: got nil; want non-nil" , i )
317
319
}
318
320
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
321
329
if elapsed < expectElapsedMin {
322
330
t .Errorf ("#%d: got %v; want >= %v" , i , elapsed , expectElapsedMin )
323
331
} else if elapsed > expectElapsedMax {
@@ -664,7 +672,7 @@ func TestDialerDualStack(t *testing.T) {
664
672
t .Skip ("both IPv4 and IPv6 are required" )
665
673
}
666
674
667
- closedPortDelay , expectClosedPortDelay := dialClosedPort ()
675
+ closedPortDelay , expectClosedPortDelay := dialClosedPort (t )
668
676
if closedPortDelay > expectClosedPortDelay {
669
677
t .Errorf ("got %v; want <= %v" , closedPortDelay , expectClosedPortDelay )
670
678
}
0 commit comments