Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add timeout to udp multicast join tests #543

Merged
merged 1 commit into from
May 10, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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