Skip to content

Commit

Permalink
Fix udp multicast test when no exernal interfaces are available
Browse files Browse the repository at this point in the history
Fixes luvit#539
  • Loading branch information
squeek502 committed Apr 20, 2021
1 parent b85b9ef commit aa4acf2
Showing 1 changed file with 27 additions and 14 deletions.
41 changes: 27 additions & 14 deletions tests/test-udp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ return require('lib/tap')(function (test)
assert(uv.udp_bind(server, bind_addr, TEST_PORT))
local _, err, errname = uv.udp_set_membership(server, multicast_addr, interface_addr, "join")
if errname == "ENODEV" then
print("no ipv6 multicast route, skipping")
print("no multicast route, skipping")
server:close()
return
elseif errname == "EADDRNOTAVAIL" and multicast_addr == "ff02::1" then
Expand Down Expand Up @@ -240,26 +240,39 @@ return require('lib/tap')(function (test)
end
end

test("udp multicast join ipv4", multicast_join_test("0.0.0.0", "239.255.0.1", nil))

test("udp multicast join ipv6", function(print, p, expect, uv)
local function can_ipv6_external()
local addresses = assert(uv.interface_addresses())
for _, vals in pairs(addresses) do
for _, info in ipairs(vals) do
if info.family == "inet6" and not info.internal then
return true
end
-- TODO This might be overkill, but the multicast
-- tests seem to rely on external interfaces being
-- available on some platforms. So, we use this to skip
-- the tests when there are no relevant exernal interfaces
-- available. Note: The Libuv multicast join test does use this
-- same check for skipping the ipv6 test; we just expanded it to
-- the ipv4 test as well.
local function has_external_interface(uv, family)
local addresses = assert(uv.interface_addresses())
for _, vals in pairs(addresses) do
for _, info in ipairs(vals) do
if (not family or info.family == family) and not info.internal then
return true
end
end
return false
end
return false
end

if not can_ipv6_external() then
print("no ipv6 support, skipping")
test("udp multicast join ipv4", function(print, p, expect, uv)
if not has_external_interface(uv, "inet") then
print("no external ipv4 interface, skipping")
return
end
local testfn = multicast_join_test("0.0.0.0", "239.255.0.1", nil)
return testfn(print, p, expect, uv)
end)

test("udp multicast join ipv6", function(print, p, expect, uv)
if not has_external_interface(uv, "inet6") then
print("no external ipv6 interface, skipping")
return
end
local testfn = multicast_join_test("::", "ff02::1", nil)
return testfn(print, p, expect, uv)
end)
Expand Down

0 comments on commit aa4acf2

Please sign in to comment.