Commit bcf7175a authored by Mikio Hara's avatar Mikio Hara

ipv4: deflake multicast listener tests

Fixes golang/go#20558.

Change-Id: Iead39205e508aef4fa4cdbe5dabac96b0a60133a
Reviewed-on: https://go-review.googlesource.com/44775
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>
Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
parent e4fa1c54
...@@ -69,13 +69,16 @@ func TestUDPMultiplePacketConnWithMultipleGroupListeners(t *testing.T) { ...@@ -69,13 +69,16 @@ func TestUDPMultiplePacketConnWithMultipleGroupListeners(t *testing.T) {
} }
for _, gaddr := range udpMultipleGroupListenerTests { for _, gaddr := range udpMultipleGroupListenerTests {
c1, err := net.ListenPacket("udp4", "224.0.0.0:1024") // wildcard address with reusable port c1, err := net.ListenPacket("udp4", "224.0.0.0:0") // wildcard address with reusable port
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
defer c1.Close() defer c1.Close()
_, port, err := net.SplitHostPort(c1.LocalAddr().String())
c2, err := net.ListenPacket("udp4", "224.0.0.0:1024") // wildcard address with reusable port if err != nil {
t.Fatal(err)
}
c2, err := net.ListenPacket("udp4", net.JoinHostPort("224.0.0.0", port)) // wildcard address with reusable port
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
...@@ -131,16 +134,29 @@ func TestUDPPerInterfaceSinglePacketConnWithSingleGroupListener(t *testing.T) { ...@@ -131,16 +134,29 @@ func TestUDPPerInterfaceSinglePacketConnWithSingleGroupListener(t *testing.T) {
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
port := "0"
for i, ifi := range ift { for i, ifi := range ift {
ip, ok := nettest.IsMulticastCapable("ip4", &ifi) ip, ok := nettest.IsMulticastCapable("ip4", &ifi)
if !ok { if !ok {
continue continue
} }
c, err := net.ListenPacket("udp4", ip.String()+":"+"1024") // unicast address with non-reusable port c, err := net.ListenPacket("udp4", net.JoinHostPort(ip.String(), port)) // unicast address with non-reusable port
if err != nil { if err != nil {
t.Fatal(err) // The listen may fail when the serivce is
// already in use, but it's fine because the
// purpose of this is not to test the
// bookkeeping of IP control block inside the
// kernel.
t.Log(err)
continue
} }
defer c.Close() defer c.Close()
if port == "0" {
_, port, err = net.SplitHostPort(c.LocalAddr().String())
if err != nil {
t.Fatal(err)
}
}
p := ipv4.NewPacketConn(c) p := ipv4.NewPacketConn(c)
if err := p.JoinGroup(&ifi, &gaddr); err != nil { if err := p.JoinGroup(&ifi, &gaddr); err != nil {
t.Fatal(err) t.Fatal(err)
......
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