Skip to content

Commit

Permalink
Add timeout to udp multicast join tests
Browse files Browse the repository at this point in the history
This is one way to close luvit#539.

With the default settings of firewalld (used by Fedora, RHEL, etc), incoming messages from multicast IPs are dropped, meaning that the multicast test will hang forever. This introduces a 1 second timeout, after which the test will fail.
  • Loading branch information
squeek502 committed May 8, 2021
1 parent b04b0de commit 118bb89
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tests/test-udp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,16 @@ return require('lib/tap')(function (test)
local function multicast_join_test(bind_addr, multicast_addr, interface_addr)
return function(print, p, expect, uv)
local uvVersionGEQ = require('lib/utils').uvVersionGEQ
local timeout = uv.new_timer()
local TIMEOUT_TIME = 1000

local server = assert(uv.new_udp())
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 multicast route, skipping")
server:close()
timeout:close()
return
elseif errname == "EADDRNOTAVAIL" and multicast_addr == "ff02::1" then
-- OSX, BSDs, and some other platforms need %lo in their multicast/interface addr
Expand Down Expand Up @@ -212,6 +215,7 @@ return require('lib/tap')(function (test)
-- note: because of this conditional close, the test will fail with an unclosed handle if recv_cb_called
-- doesn't hit 2, so we don't need to expect(recv_cb) or assert recv_cb_called == 2
server:close()
timeout:close()
else
-- udp_set_source_membership added in 1.32.0
if uvVersionGEQ("1.32.0") then
Expand Down Expand Up @@ -247,10 +251,20 @@ return require('lib/tap')(function (test)
print("send to multicast ip was likely denied by firewall, skipping")
client:close()
server:close()
timeout:close()
return
end
assert(not err, err)
end)))

-- some firewalls might reject incoming messages from multicast IPs,
-- so we need a timeout to avoid hanging forever in that scenario
timeout:start(TIMEOUT_TIME, 0, expect(function()
print("timeout (could be caused by firewall settings)")
client:close()
server:close()
timeout:close()
end, 0))
end
end

Expand Down

0 comments on commit 118bb89

Please sign in to comment.