Skip to content

Commit

Permalink
Different way of checking for an open port in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
subnetmarco committed Aug 1, 2015
1 parent 9373ce0 commit 459f842
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions spec/spec_helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,16 @@ function _M.find_port(exclude)
end

-- Finding an available port
local server = assert(socket.bind("*", 0))
local _, port = server:getsockname()
server:close()
local handle = io.popen([[(netstat -atn | awk '{printf "%s\n%s\n", $4, $4}' | grep -oE '[0-9]*$'; seq 32768 61000) | sort -n | uniq -u | head -n 1]])
local result = handle:read("*a")
handle:close()

-- Closing the opened servers
for _, v in ipairs(servers) do
v:close()
end

return port
return tonumber(result)
end

-- Starts a TCP server
Expand Down

0 comments on commit 459f842

Please # to comment.