diff --git a/errors.go b/errors.go index 2fc1c87..8576e26 100644 --- a/errors.go +++ b/errors.go @@ -140,6 +140,6 @@ var ( errNotImplemented = errors.New("not implemented yet") errNoUDPMuxAvailable = errors.New("no UDP mux is available") errNoTCPMuxAvailable = errors.New("no TCP mux is available") - errListenUnspecified = errors.New("can't listen on unspecified address") - errInvalidAddress = errors.New("invalid address") + // errListenUnspecified = errors.New("can't listen on unspecified address") + errInvalidAddress = errors.New("invalid address") ) diff --git a/udp_mux_test.go b/udp_mux_test.go index 16d44d1..36192ae 100644 --- a/udp_mux_test.go +++ b/udp_mux_test.go @@ -33,75 +33,35 @@ func TestUDPMux(t *testing.T) { t.Log("IPv6 is not supported on this machine") } - for network, c := range map[string]net.PacketConn{udp4: conn4, udp6: conn6} { - if udpConn, ok := c.(*net.UDPConn); !ok || udpConn == nil { - continue - } - conn := c - t.Run(network, func(t *testing.T) { - udpMux, err := NewUDPMuxDefault(UDPMuxParams{ - Logger: nil, - UDPConn: conn, - }) - - require.NoError(t, err) - - defer func() { - _ = udpMux.Close() - _ = conn.Close() - }() - - require.NotNil(t, udpMux.LocalAddr(), "udpMux.LocalAddr() is nil") - - wg := sync.WaitGroup{} - - wg.Add(1) - go func() { - defer wg.Done() - testMuxConnection(t, udpMux, "ufrag1", udp) - }() - - // skip ipv6 test on i386 - const ptrSize = 32 << (^uintptr(0) >> 63) - if ptrSize != 32 || network != udp6 { - testMuxConnection(t, udpMux, "ufrag2", network) - } - - wg.Wait() - - require.NoError(t, udpMux.Close()) - - // can't create more connections - _, err = udpMux.GetConn("failufrag", udpMux.LocalAddr()) - require.Error(t, err) - }) - } -} - -func TestUDPMuxUnspecifiedAddr(t *testing.T) { - report := test.CheckRoutines(t) - defer report() - - lim := test.TimeOut(time.Second * 30) - defer lim.Stop() - - conn, err := net.ListenUDP(udp, nil) + connUnspecified, err := net.ListenUDP(udp, nil) require.NoError(t, err) - conn4, err := net.ListenUDP(udp, &net.UDPAddr{IP: net.IPv4zero}) + conn4Unspecified, err := net.ListenUDP(udp, &net.UDPAddr{IP: net.IPv4zero}) require.NoError(t, err) - conn6, err := net.ListenUDP(udp, &net.UDPAddr{IP: net.IPv6unspecified}) + conn6Unspecified, err := net.ListenUDP(udp, &net.UDPAddr{IP: net.IPv6unspecified}) if err != nil { t.Log("IPv6 is not supported on this machine") } - for network, c := range map[string]net.PacketConn{udp: conn, udp4: conn4, udp6: conn6} { - if udpConn, ok := c.(*net.UDPConn); !ok || udpConn == nil { + type testCase struct { + name string + conn net.PacketConn + network string + } + + for _, subTest := range []testCase{ + {name: "IPv4loopback", conn: conn4, network: udp4}, + {name: "IPv6loopback", conn: conn6, network: udp6}, + {name: "Unspecified", conn: connUnspecified, network: udp}, + {name: "IPv4Unspecified", conn: conn4Unspecified, network: udp4}, + {name: "IPv6Unspecified", conn: conn6Unspecified, network: udp6}, + } { + network, conn := subTest.network, subTest.conn + if udpConn, ok := conn.(*net.UDPConn); !ok || udpConn == nil { continue } - conn := c - t.Run(network, func(t *testing.T) { + t.Run(subTest.name, func(t *testing.T) { udpMux, err := NewUDPMuxDefault(UDPMuxParams{ Logger: nil, UDPConn: conn, @@ -124,9 +84,18 @@ func TestUDPMuxUnspecifiedAddr(t *testing.T) { testMuxConnection(t, udpMux, "ufrag1", udp) }() - // skip ipv6 test on i386 const ptrSize = 32 << (^uintptr(0) >> 63) - if ptrSize != 32 || network != udp6 { + if network == udp { + wg.Add(1) + go func() { + defer wg.Done() + testMuxConnection(t, udpMux, "ufrag2", udp4) + }() + // skip ipv6 test on i386 + if ptrSize != 32 { + testMuxConnection(t, udpMux, "ufrag3", udp6) + } + } else if ptrSize != 32 || network != udp6 { testMuxConnection(t, udpMux, "ufrag2", network) }