diff options
Diffstat (limited to 'libgo/go/net/unicast_test.go')
-rw-r--r-- | libgo/go/net/unicast_test.go | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/libgo/go/net/unicast_test.go b/libgo/go/net/unicast_test.go index 6ed6f59..297276d 100644 --- a/libgo/go/net/unicast_test.go +++ b/libgo/go/net/unicast_test.go @@ -5,6 +5,7 @@ package net import ( + "io" "runtime" "testing" ) @@ -15,10 +16,12 @@ var unicastTests = []struct { ipv6 bool packet bool }{ - {"tcp4", "127.0.0.1:0", false, false}, - {"tcp6", "[::1]:0", true, false}, - {"udp4", "127.0.0.1:0", false, true}, - {"udp6", "[::1]:0", true, true}, + {net: "tcp4", laddr: "127.0.0.1:0"}, + {net: "tcp4", laddr: "previous"}, + {net: "tcp6", laddr: "[::1]:0", ipv6: true}, + {net: "tcp6", laddr: "previous", ipv6: true}, + {net: "udp4", laddr: "127.0.0.1:0", packet: true}, + {net: "udp6", laddr: "[::1]:0", ipv6: true, packet: true}, } func TestUnicastTCPAndUDP(t *testing.T) { @@ -26,24 +29,32 @@ func TestUnicastTCPAndUDP(t *testing.T) { return } + prevladdr := "" for _, tt := range unicastTests { if tt.ipv6 && !supportsIPv6 { continue } - var fd *netFD + var ( + fd *netFD + closer io.Closer + ) if !tt.packet { - c, err := Listen(tt.net, tt.laddr) + if tt.laddr == "previous" { + tt.laddr = prevladdr + } + l, err := Listen(tt.net, tt.laddr) if err != nil { t.Fatalf("Listen failed: %v", err) } - defer c.Close() - fd = c.(*TCPListener).fd + prevladdr = l.Addr().String() + closer = l + fd = l.(*TCPListener).fd } else { c, err := ListenPacket(tt.net, tt.laddr) if err != nil { t.Fatalf("ListenPacket failed: %v", err) } - defer c.Close() + closer = c fd = c.(*UDPConn).fd } if !tt.ipv6 { @@ -51,6 +62,7 @@ func TestUnicastTCPAndUDP(t *testing.T) { } else { testIPv6UnicastSocketOptions(t, fd) } + closer.Close() } } |