|
|
@ -46,7 +46,8 @@ func TestBuffConnReadTimeout(t *testing.T) { |
|
|
|
|
|
|
|
|
|
|
|
tcpConn, terr := tcpListener.AcceptTCP() |
|
|
|
tcpConn, terr := tcpListener.AcceptTCP() |
|
|
|
if terr != nil { |
|
|
|
if terr != nil { |
|
|
|
t.Fatalf("failed to accept new connection. %v", terr) |
|
|
|
t.Errorf("failed to accept new connection. %v", terr) |
|
|
|
|
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
bufconn := newBufConn(tcpConn, 1*time.Second, 1*time.Second) |
|
|
|
bufconn := newBufConn(tcpConn, 1*time.Second, 1*time.Second) |
|
|
|
defer bufconn.Close() |
|
|
|
defer bufconn.Close() |
|
|
@ -55,11 +56,13 @@ func TestBuffConnReadTimeout(t *testing.T) { |
|
|
|
var b = make([]byte, 12) |
|
|
|
var b = make([]byte, 12) |
|
|
|
_, terr = bufconn.Read(b) |
|
|
|
_, terr = bufconn.Read(b) |
|
|
|
if terr != nil { |
|
|
|
if terr != nil { |
|
|
|
t.Fatalf("failed to read from client. %v", terr) |
|
|
|
t.Errorf("failed to read from client. %v", terr) |
|
|
|
|
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
received := string(b) |
|
|
|
received := string(b) |
|
|
|
if received != "message one\n" { |
|
|
|
if received != "message one\n" { |
|
|
|
t.Fatalf(`server: expected: "message one\n", got: %v`, received) |
|
|
|
t.Errorf(`server: expected: "message one\n", got: %v`, received) |
|
|
|
|
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Wait for more than read timeout to simulate processing.
|
|
|
|
// Wait for more than read timeout to simulate processing.
|
|
|
@ -67,17 +70,20 @@ func TestBuffConnReadTimeout(t *testing.T) { |
|
|
|
|
|
|
|
|
|
|
|
_, terr = bufconn.Read(b) |
|
|
|
_, terr = bufconn.Read(b) |
|
|
|
if terr != nil { |
|
|
|
if terr != nil { |
|
|
|
t.Fatalf("failed to read from client. %v", terr) |
|
|
|
t.Errorf("failed to read from client. %v", terr) |
|
|
|
|
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
received = string(b) |
|
|
|
received = string(b) |
|
|
|
if received != "message two\n" { |
|
|
|
if received != "message two\n" { |
|
|
|
t.Fatalf(`server: expected: "message two\n", got: %v`, received) |
|
|
|
t.Errorf(`server: expected: "message two\n", got: %v`, received) |
|
|
|
|
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Send a response.
|
|
|
|
// Send a response.
|
|
|
|
_, terr = io.WriteString(bufconn, "messages received\n") |
|
|
|
_, terr = io.WriteString(bufconn, "messages received\n") |
|
|
|
if terr != nil { |
|
|
|
if terr != nil { |
|
|
|
t.Fatalf("failed to write to client. %v", terr) |
|
|
|
t.Errorf("failed to write to client. %v", terr) |
|
|
|
|
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Removes all deadlines if any.
|
|
|
|
// Removes all deadlines if any.
|
|
|
|