FAQ
Reviewers: golang-dev_googlegroups.com,

Message:
Hello golang-dev@googlegroups.com (cc: golang-dev@googlegroups.com),

I'd like you to review this change to
https://code.google.com/p/go


Description:
net: add more tests for protocol specific methods

Please review this at http://codereview.appspot.com/6821100/

Affected files:
M src/pkg/net/protoconn_test.go


Index: src/pkg/net/protoconn_test.go
===================================================================
--- a/src/pkg/net/protoconn_test.go
+++ b/src/pkg/net/protoconn_test.go
@@ -13,6 +13,27 @@
"time"
)

+func TestTCPListenerSpecificMethods(t *testing.T) {
+ la, err := net.ResolveTCPAddr("tcp4", "127.0.0.1:0")
+ if err != nil {
+ t.Fatalf("net.ResolveTCPAddr failed: %v", err)
+ }
+ ln, err := net.ListenTCP("tcp4", la)
+ if err != nil {
+ t.Fatalf("net.ListenTCP failed: %v", err)
+ }
+ ln.Addr()
+ ln.SetDeadline(time.Now().Add(100 * time.Millisecond))
+ defer ln.Close()
+
+ ln.Accept()
+ ln.AcceptTCP()
+
+ if f, err := ln.File(); err == nil {
+ f.Close()
+ }
+}
+
func TestUDPConnSpecificMethods(t *testing.T) {
la, err := net.ResolveUDPAddr("udp4", "127.0.0.1:0")
if err != nil {
@@ -22,7 +43,6 @@
if err != nil {
t.Fatalf("net.ListenUDP failed: %v", err)
}
- c.File()
c.LocalAddr()
c.RemoteAddr()
c.SetDeadline(time.Now().Add(100 * time.Millisecond))
@@ -40,6 +60,13 @@
if _, _, err := c.ReadFromUDP(rb); err != nil {
t.Fatalf("net.UDPConn.ReadFromUDP failed: %v", err)
}
+
+ c.WriteMsgUDP(wb, nil, c.LocalAddr().(*net.UDPAddr))
+ c.ReadMsgUDP(rb, nil)
+
+ if f, err := c.File(); err == nil {
+ f.Close()
+ }
}

func TestIPConnSpecificMethods(t *testing.T) {
@@ -61,7 +88,6 @@
if err != nil {
t.Fatalf("net.ListenIP failed: %v", err)
}
- c.File()
c.LocalAddr()
c.RemoteAddr()
c.SetDeadline(time.Now().Add(100 * time.Millisecond))
@@ -80,9 +106,45 @@
if _, _, err := c.ReadFromIP(rb); err != nil {
t.Fatalf("net.IPConn.ReadFromIP failed: %v", err)
}
+
+ c.WriteMsgIP(wb, nil, c.LocalAddr().(*net.IPAddr))
+ c.ReadMsgIP(rb, nil)
+
+ if f, err := c.File(); err == nil {
+ f.Close()
+ }
}

-// TODO: Find out the use case of ListenUnixgram, I have no idea.
+func TestUnixListenerSpecificMethods(t *testing.T) {
+ switch runtime.GOOS {
+ case "plan9", "windows":
+ t.Logf("skipping read test on %q", runtime.GOOS)
+ return
+ }
+
+ p := "/tmp/gotest.net"
+ os.Remove(p)
+ la, err := net.ResolveUnixAddr("unix", p)
+ if err != nil {
+ t.Fatalf("net.ResolveUnixAddr failed: %v", err)
+ }
+ ln, err := net.ListenUnix("unix", la)
+ if err != nil {
+ t.Fatalf("net.ListenUnix failed: %v", err)
+ }
+ ln.Addr()
+ ln.SetDeadline(time.Now().Add(100 * time.Millisecond))
+ defer ln.Close()
+ defer os.Remove(p)
+
+ ln.Accept()
+ ln.AcceptUnix()
+
+ if f, err := ln.File(); err == nil {
+ f.Close()
+ }
+}
+
func TestUnixConnSpecificMethods(t *testing.T) {
switch runtime.GOOS {
case "plan9", "windows":
@@ -102,7 +164,6 @@
if err != nil {
t.Fatalf("net.DialUnix failed: %v", err)
}
- c1.File()
c1.LocalAddr()
c1.RemoteAddr()
c1.SetDeadline(time.Now().Add(100 * time.Millisecond))
@@ -121,7 +182,6 @@
if err != nil {
t.Fatalf("net.DialUnix failed: %v", err)
}
- c2.File()
c2.LocalAddr()
c2.RemoteAddr()
c2.SetDeadline(time.Now().Add(100 * time.Millisecond))
@@ -147,6 +207,16 @@
if _, _, err := c1.ReadFromUnix(rb1); err != nil {
t.Fatalf("net.UnixConn.ReadFromUnix failed: %v", err)
}
+
+ // TODO: http://golang.org/issue/3875
+ net.ListenUnixgram("unixgram", nil)
+
+ if f, err := c1.File(); err == nil {
+ f.Close()
+ }
+ if f, err := c2.File(); err == nil {
+ f.Close()
+ }
}

func newICMPEchoRequest(id, seqnum, msglen int, filler []byte) []byte {

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-dev @
categoriesgo
postedNov 9, '12 at 12:22p
activeNov 10, '12 at 5:34a
posts13
users2
websitegolang.org

2 users in discussion

Mikioh Mikioh: 9 posts Bradfitz: 4 posts

People

Translate

site design / logo © 2021 Grokbase