-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Kong#777 from Tieske/fix/reuseaddr
Tests: Fix socket in use error, and move a 'missing' file
- Loading branch information
Showing
7 changed files
with
58 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,30 @@ | ||
local cutils = require "kong.cli.utils" | ||
local spec_helper = require "spec.spec_helpers" | ||
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 | ||
assert.falsy(cutils.is_port_open(PORT)) | ||
spec_helper.start_tcp_server(PORT, true, true) | ||
os.execute("sleep 0") -- Wait for the server to start | ||
assert.truthy(cutils.is_port_open(PORT)) | ||
local server, success, err | ||
|
||
-- Check a currently closed port | ||
assert.truthy(cutils.is_port_bindable(PORT)) | ||
|
||
-- Check an open port, with SO_REUSEADDR set | ||
server = socket.tcp() | ||
assert(server:setoption('reuseaddr', true)) | ||
assert(server:bind("*", PORT)) | ||
assert(server:listen()) | ||
success, err = cutils.is_port_bindable(PORT) | ||
server:close() | ||
assert.truthy(success, err) | ||
|
||
-- Check an open port, without SO_REUSEADDR set | ||
server = socket.tcp() | ||
assert(server:bind("*", PORT)) | ||
assert(server:listen()) | ||
success, err = cutils.is_port_bindable(PORT) | ||
server:close() | ||
assert.falsy(success, err) | ||
|
||
end) | ||
end) |