]> Cypherpunks repositories - gostls13.git/commitdiff
net: allow concurrent UNIX socket tests if TMPDIR is unique.
authorAlbert Strasheim <fullung@gmail.com>
Mon, 11 Mar 2013 17:24:52 +0000 (13:24 -0400)
committerRuss Cox <rsc@golang.org>
Mon, 11 Mar 2013 17:24:52 +0000 (13:24 -0400)
Only clever enough to allow concurrent stress testing.

R=mikioh.mikioh, rsc
CC=golang-dev
https://golang.org/cl/7703044

src/pkg/net/server_test.go

index 25c2be5a7cc086f3774954cfae9752958328d8c8..c101ffecd1f35352044856cce1e24bdbb9fabfd6 100644 (file)
@@ -9,6 +9,7 @@ import (
        "io"
        "os"
        "runtime"
+       "strconv"
        "testing"
        "time"
 )
@@ -41,6 +42,12 @@ func skipServerTest(net, unixsotype, addr string, ipv6, ipv4map, linuxonly bool)
        return false
 }
 
+func tempfile(filename string) string {
+       // use /tmp in case it is prohibited to create
+       // UNIX sockets in TMPDIR
+       return "/tmp/" + filename + "." + strconv.Itoa(os.Getpid())
+}
+
 var streamConnServerTests = []struct {
        snet    string // server side
        saddr   string
@@ -86,7 +93,7 @@ var streamConnServerTests = []struct {
 
        {snet: "tcp6", saddr: "[::1]", cnet: "tcp6", caddr: "[::1]", ipv6: true},
 
-       {snet: "unix", saddr: "/tmp/gotest1.net", cnet: "unix", caddr: "/tmp/gotest1.net.local"},
+       {snet: "unix", saddr: tempfile("gotest1.net"), cnet: "unix", caddr: tempfile("gotest1.net.local")},
        {snet: "unix", saddr: "@gotest2/net", cnet: "unix", caddr: "@gotest2/net.local", linux: true},
 }
 
@@ -135,7 +142,7 @@ var seqpacketConnServerTests = []struct {
        caddr string // client address
        empty bool   // test with empty data
 }{
-       {net: "unixpacket", saddr: "/tmp/gotest3.net", caddr: "/tmp/gotest3.net.local"},
+       {net: "unixpacket", saddr: tempfile("/gotest3.net"), caddr: tempfile("gotest3.net.local")},
        {net: "unixpacket", saddr: "@gotest4/net", caddr: "@gotest4/net.local"},
 }
 
@@ -294,10 +301,10 @@ var datagramPacketConnServerTests = []struct {
        {snet: "udp", saddr: "[::1]", cnet: "udp", caddr: "[::1]", ipv6: true, empty: true},
        {snet: "udp", saddr: "[::1]", cnet: "udp", caddr: "[::1]", ipv6: true, dial: true, empty: true},
 
-       {snet: "unixgram", saddr: "/tmp/gotest5.net", cnet: "unixgram", caddr: "/tmp/gotest5.net.local"},
-       {snet: "unixgram", saddr: "/tmp/gotest5.net", cnet: "unixgram", caddr: "/tmp/gotest5.net.local", dial: true},
-       {snet: "unixgram", saddr: "/tmp/gotest5.net", cnet: "unixgram", caddr: "/tmp/gotest5.net.local", empty: true},
-       {snet: "unixgram", saddr: "/tmp/gotest5.net", cnet: "unixgram", caddr: "/tmp/gotest5.net.local", dial: true, empty: true},
+       {snet: "unixgram", saddr: tempfile("gotest5.net"), cnet: "unixgram", caddr: tempfile("gotest5.net.local")},
+       {snet: "unixgram", saddr: tempfile("gotest5.net"), cnet: "unixgram", caddr: tempfile("gotest5.net.local"), dial: true},
+       {snet: "unixgram", saddr: tempfile("gotest5.net"), cnet: "unixgram", caddr: tempfile("gotest5.net.local"), empty: true},
+       {snet: "unixgram", saddr: tempfile("gotest5.net"), cnet: "unixgram", caddr: tempfile("gotest5.net.local"), dial: true, empty: true},
 
        {snet: "unixgram", saddr: "@gotest6/net", cnet: "unixgram", caddr: "@gotest6/net.local", linux: true},
 }