Improve names in handshake deadline test

This commit is contained in:
dottyjones 2018-05-28 12:07:56 -07:00 committed by GitHub
parent f90b62c3ce
commit badcf87185
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 20 deletions

View File

@ -344,46 +344,48 @@ func TestDialTimeout(t *testing.T) {
} }
} }
// netConnDeadlineObserver fails test if read or write called without deadline. // requireDeadlineNetConn fails the current test when Read or Write are called
type netConnDeadlineObserver struct { // with no deadline.
t *testing.T type requireDeadlineNetConn struct {
c net.Conn t *testing.T
read, write bool c net.Conn
readDeadlineIsSet bool
writeDeadlineIsSet bool
} }
func (c *netConnDeadlineObserver) SetDeadline(t time.Time) error { func (c *requireDeadlineNetConn) SetDeadline(t time.Time) error {
c.write = !t.Equal(time.Time{}) c.writeDeadlineIsSet = !t.Equal(time.Time{})
c.read = c.write c.readDeadlineIsSet = c.writeDeadlineIsSet
return c.c.SetDeadline(t) return c.c.SetDeadline(t)
} }
func (c *netConnDeadlineObserver) SetReadDeadline(t time.Time) error { func (c *requireDeadlineNetConn) SetReadDeadline(t time.Time) error {
c.read = !t.Equal(time.Time{}) c.readDeadlineIsSet = !t.Equal(time.Time{})
return c.c.SetDeadline(t) return c.c.SetDeadline(t)
} }
func (c *netConnDeadlineObserver) SetWriteDeadline(t time.Time) error { func (c *requireDeadlineNetConn) SetWriteDeadline(t time.Time) error {
c.write = !t.Equal(time.Time{}) c.writeDeadlineIsSet = !t.Equal(time.Time{})
return c.c.SetDeadline(t) return c.c.SetDeadline(t)
} }
func (c *netConnDeadlineObserver) Write(p []byte) (int, error) { func (c *requireDeadlineNetConn) Write(p []byte) (int, error) {
if !c.write { if !c.writeDeadlineIsSet {
c.t.Fatalf("write with no deadline") c.t.Fatalf("write with no deadline")
} }
return c.c.Write(p) return c.c.Write(p)
} }
func (c *netConnDeadlineObserver) Read(p []byte) (int, error) { func (c *requireDeadlineNetConn) Read(p []byte) (int, error) {
if !c.read { if !c.readDeadlineIsSet {
c.t.Fatalf("read with no deadline") c.t.Fatalf("read with no deadline")
} }
return c.c.Read(p) return c.c.Read(p)
} }
func (c *netConnDeadlineObserver) Close() error { return c.c.Close() } func (c *requireDeadlineNetConn) Close() error { return c.c.Close() }
func (c *netConnDeadlineObserver) LocalAddr() net.Addr { return c.c.LocalAddr() } func (c *requireDeadlineNetConn) LocalAddr() net.Addr { return c.c.LocalAddr() }
func (c *netConnDeadlineObserver) RemoteAddr() net.Addr { return c.c.RemoteAddr() } func (c *requireDeadlineNetConn) RemoteAddr() net.Addr { return c.c.RemoteAddr() }
func TestHandshakeTimeout(t *testing.T) { func TestHandshakeTimeout(t *testing.T) {
s := newServer(t) s := newServer(t)
@ -392,7 +394,7 @@ func TestHandshakeTimeout(t *testing.T) {
d := cstDialer d := cstDialer
d.NetDial = func(n, a string) (net.Conn, error) { d.NetDial = func(n, a string) (net.Conn, error) {
c, err := net.Dial(n, a) c, err := net.Dial(n, a)
return &netConnDeadlineObserver{c: c, t: t}, err return &requireDeadlineNetConn{c: c, t: t}, err
} }
ws, _, err := d.Dial(s.URL, nil) ws, _, err := d.Dial(s.URL, nil)
if err != nil { if err != nil {