@@ -344,46 +344,48 @@ func TestDialTimeout(t *testing.T) {
344
344
}
345
345
}
346
346
347
- // netConnDeadlineObserver fails test if read or write called without deadline.
348
- type netConnDeadlineObserver struct {
349
- t * testing.T
350
- c net.Conn
351
- read , write bool
352
- }
353
-
354
- func (c * netConnDeadlineObserver ) SetDeadline (t time.Time ) error {
355
- c .write = ! t .Equal (time.Time {})
356
- c .read = c .write
347
+ // requireDeadlineNetConn fails the current test when Read or Write are called
348
+ // with no deadline.
349
+ type requireDeadlineNetConn struct {
350
+ t * testing.T
351
+ c net.Conn
352
+ readDeadlineIsSet bool
353
+ writeDeadlineIsSet bool
354
+ }
355
+
356
+ func (c * requireDeadlineNetConn ) SetDeadline (t time.Time ) error {
357
+ c .writeDeadlineIsSet = ! t .Equal (time.Time {})
358
+ c .readDeadlineIsSet = c .writeDeadlineIsSet
357
359
return c .c .SetDeadline (t )
358
360
}
359
361
360
- func (c * netConnDeadlineObserver ) SetReadDeadline (t time.Time ) error {
361
- c .read = ! t .Equal (time.Time {})
362
+ func (c * requireDeadlineNetConn ) SetReadDeadline (t time.Time ) error {
363
+ c .readDeadlineIsSet = ! t .Equal (time.Time {})
362
364
return c .c .SetDeadline (t )
363
365
}
364
366
365
- func (c * netConnDeadlineObserver ) SetWriteDeadline (t time.Time ) error {
366
- c .write = ! t .Equal (time.Time {})
367
+ func (c * requireDeadlineNetConn ) SetWriteDeadline (t time.Time ) error {
368
+ c .writeDeadlineIsSet = ! t .Equal (time.Time {})
367
369
return c .c .SetDeadline (t )
368
370
}
369
371
370
- func (c * netConnDeadlineObserver ) Write (p []byte ) (int , error ) {
371
- if ! c .write {
372
+ func (c * requireDeadlineNetConn ) Write (p []byte ) (int , error ) {
373
+ if ! c .writeDeadlineIsSet {
372
374
c .t .Fatalf ("write with no deadline" )
373
375
}
374
376
return c .c .Write (p )
375
377
}
376
378
377
- func (c * netConnDeadlineObserver ) Read (p []byte ) (int , error ) {
378
- if ! c .read {
379
+ func (c * requireDeadlineNetConn ) Read (p []byte ) (int , error ) {
380
+ if ! c .readDeadlineIsSet {
379
381
c .t .Fatalf ("read with no deadline" )
380
382
}
381
383
return c .c .Read (p )
382
384
}
383
385
384
- func (c * netConnDeadlineObserver ) Close () error { return c .c .Close () }
385
- func (c * netConnDeadlineObserver ) LocalAddr () net.Addr { return c .c .LocalAddr () }
386
- func (c * netConnDeadlineObserver ) RemoteAddr () net.Addr { return c .c .RemoteAddr () }
386
+ func (c * requireDeadlineNetConn ) Close () error { return c .c .Close () }
387
+ func (c * requireDeadlineNetConn ) LocalAddr () net.Addr { return c .c .LocalAddr () }
388
+ func (c * requireDeadlineNetConn ) RemoteAddr () net.Addr { return c .c .RemoteAddr () }
387
389
388
390
func TestHandshakeTimeout (t * testing.T ) {
389
391
s := newServer (t )
@@ -392,7 +394,7 @@ func TestHandshakeTimeout(t *testing.T) {
392
394
d := cstDialer
393
395
d .NetDial = func (n , a string ) (net.Conn , error ) {
394
396
c , err := net .Dial (n , a )
395
- return & netConnDeadlineObserver {c : c , t : t }, err
397
+ return & requireDeadlineNetConn {c : c , t : t }, err
396
398
}
397
399
ws , _ , err := d .Dial (s .URL , nil )
398
400
if err != nil {
0 commit comments