From 459f84263b21c6915cb5534bfd03bd184608c176 Mon Sep 17 00:00:00 2001 From: thefosk Date: Fri, 31 Jul 2015 19:39:42 -0700 Subject: [PATCH] Different way of checking for an open port in tests --- spec/spec_helpers.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/spec_helpers.lua b/spec/spec_helpers.lua index b044d3fd1361..1bba8bd30c51 100644 --- a/spec/spec_helpers.lua +++ b/spec/spec_helpers.lua @@ -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