Skip to content

Commit badcf87

Browse files
author
dottyjones
authored
Improve names in handshake deadline test
1 parent f90b62c commit badcf87

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

client_server_test.go

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -344,46 +344,48 @@ func TestDialTimeout(t *testing.T) {
344344
}
345345
}
346346

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
357359
return c.c.SetDeadline(t)
358360
}
359361

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{})
362364
return c.c.SetDeadline(t)
363365
}
364366

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{})
367369
return c.c.SetDeadline(t)
368370
}
369371

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 {
372374
c.t.Fatalf("write with no deadline")
373375
}
374376
return c.c.Write(p)
375377
}
376378

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 {
379381
c.t.Fatalf("read with no deadline")
380382
}
381383
return c.c.Read(p)
382384
}
383385

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() }
387389

388390
func TestHandshakeTimeout(t *testing.T) {
389391
s := newServer(t)
@@ -392,7 +394,7 @@ func TestHandshakeTimeout(t *testing.T) {
392394
d := cstDialer
393395
d.NetDial = func(n, a string) (net.Conn, error) {
394396
c, err := net.Dial(n, a)
395-
return &netConnDeadlineObserver{c: c, t: t}, err
397+
return &requireDeadlineNetConn{c: c, t: t}, err
396398
}
397399
ws, _, err := d.Dial(s.URL, nil)
398400
if err != nil {

0 commit comments

Comments
 (0)