Commit 224f807e authored by Mikio Hara's avatar Mikio Hara

net: add missing deadline test for RawConn

Updates #19435.

Change-Id: Ife4a31972b05094a86c60a48fcacdfe52d133ee4
Reviewed-on: https://go-review.googlesource.com/107395
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
parent 58cdecb9
......@@ -8,6 +8,7 @@ import (
"bytes"
"runtime"
"testing"
"time"
)
func TestRawConnReadWrite(t *testing.T) {
......@@ -93,6 +94,81 @@ func TestRawConnReadWrite(t *testing.T) {
t.Fatalf("got %q; want %q", b[:n], data)
}
})
t.Run("Deadline", func(t *testing.T) {
switch runtime.GOOS {
case "windows":
t.Skipf("not supported on %s", runtime.GOOS)
}
ln, err := newLocalListener("tcp")
if err != nil {
t.Fatal(err)
}
defer ln.Close()
c, err := Dial(ln.Addr().Network(), ln.Addr().String())
if err != nil {
t.Fatal(err)
}
defer c.Close()
cc, err := c.(*TCPConn).SyscallConn()
if err != nil {
t.Fatal(err)
}
var b [1]byte
c.SetDeadline(noDeadline)
if err := c.SetDeadline(time.Now().Add(-1)); err != nil {
t.Fatal(err)
}
if err = writeRawConn(cc, b[:]); err == nil {
t.Fatal("Write should fail")
}
if perr := parseWriteError(err); perr != nil {
t.Error(perr)
}
if nerr, ok := err.(Error); !ok || !nerr.Timeout() {
t.Errorf("got %v; want timeout", err)
}
if _, err = readRawConn(cc, b[:]); err == nil {
t.Fatal("Read should fail")
}
if perr := parseReadError(err); perr != nil {
t.Error(perr)
}
if nerr, ok := err.(Error); !ok || !nerr.Timeout() {
t.Errorf("got %v; want timeout", err)
}
c.SetReadDeadline(noDeadline)
if err := c.SetReadDeadline(time.Now().Add(-1)); err != nil {
t.Fatal(err)
}
if _, err = readRawConn(cc, b[:]); err == nil {
t.Fatal("Read should fail")
}
if perr := parseReadError(err); perr != nil {
t.Error(perr)
}
if nerr, ok := err.(Error); !ok || !nerr.Timeout() {
t.Errorf("got %v; want timeout", err)
}
c.SetWriteDeadline(noDeadline)
if err := c.SetWriteDeadline(time.Now().Add(-1)); err != nil {
t.Fatal(err)
}
if err = writeRawConn(cc, b[:]); err == nil {
t.Fatal("Write should fail")
}
if perr := parseWriteError(err); perr != nil {
t.Error(perr)
}
if nerr, ok := err.(Error); !ok || !nerr.Timeout() {
t.Errorf("got %v; want timeout", err)
}
})
}
func TestRawConnControl(t *testing.T) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment