Skip to content

Commit

Permalink
exclude the test for reopeneing a socket. On unix, the socket can onl…
Browse files Browse the repository at this point in the history
…y be

reopened/reused this way if is was abandonned and is currently in a TIME_WAIT state.
This specific situation cannot be reliably recreated in a test setup, hence skip this test.
(test contains three cases, and the second is the one that cannot be tested)
  • Loading branch information
Tieske committed Dec 6, 2015
1 parent 52b43fd commit cafeeb2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
10 changes: 5 additions & 5 deletions kong/cli/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,17 @@ end

-- Checks if a port is available to bind a server to on localhost
-- @param `port` The port to check
-- @return `open` Truthy if available, falsy otherwise
-- @return `open` Truthy if available, falsy + error otherwise
local function is_port_bindable(port)
local server, success
local server, success, err
server = require("socket").tcp()
server:setoption('reuseaddr', true)
success = server:bind("*", port)
success, err = server:bind("*", port)
if success then
success = server:listen()
success, err = server:listen()
end
server:close()
return success
return success, err
end

return {
Expand Down
14 changes: 7 additions & 7 deletions spec/unit/cli/utils_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ local cutils = require "kong.cli.utils"
local socket = require "socket"

describe("CLI Utils", function()
it("should check if a port is open", function()
pending("should check if a port is open", function()
local PORT = 30000
local server, success
local server, success, err

-- Check a currently closed port
assert.truthy(cutils.is_port_bindable(PORT))

Expand All @@ -14,17 +14,17 @@ describe("CLI Utils", function()
assert(server:setoption('reuseaddr', true))
assert(server:bind("*", PORT))
assert(server:listen())
success = cutils.is_port_bindable(PORT)
success, err = cutils.is_port_bindable(PORT)
server:close()
assert.truthy(success)
assert.truthy(success, err)

-- Check an open port, without SO_REUSEADDR set
server = socket.tcp()
assert(server:bind("*", PORT))
assert(server:listen())
success = cutils.is_port_bindable(PORT)
success, err = cutils.is_port_bindable(PORT)
server:close()
assert.falsy(success)
assert.falsy(success, err)

end)
end)

0 comments on commit cafeeb2

Please sign in to comment.