Skip to content

Commit

Permalink
CI fixes, cassandra setup, closes #784
Browse files Browse the repository at this point in the history
  • Loading branch information
Tieske committed Dec 11, 2015
1 parent a523dda commit ab908b3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .ci/setup_cassandra.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ n=0
until [ $n -ge 5 ]
do
sudo rm -rf /var/lib/cassandra/*
curl http://apache.arvixe.com/cassandra/$CASSANDRA_VERSION/$CASSANDRA_BASE-bin.tar.gz | tar xz && break
curl http://archive.apache.org/dist/cassandra/$CASSANDRA_VERSION/$CASSANDRA_BASE-bin.tar.gz | tar xz && break
n=$[$n+1]
sleep 5
done
Expand Down
37 changes: 29 additions & 8 deletions kong/cli/utils/signal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,25 @@ function _M.prepare_kong(args_config, signal)
prepare_nginx_working_dir(args_config, signal)
end

local function check_port(port)
if not cutils.is_port_bindable(port) then
cutils.logger:error_exit("Port "..tostring(port).." is being blocked by another process.")
-- Checks whether a port is available. Exits the application if not available.
-- @param port The port to check
-- @param name Functional name the port is used for (display name)
-- @param timeout (optional) Timeout in seconds after which a failure is logged
-- and application exit is performed, if not provided then it will fail at once without retries.
local function check_port(port, name, timeout)
local expire = socket.gettime() + (timeout or 0)
local msg = tostring(port) .. (name and " ("..tostring(name)..")")
local warned
while not cutils.is_port_bindable(port) do
if expire <= socket.gettime() then
cutils.logger:error_exit("Port "..msg.." is being blocked by another process.")
else
if not warned then
cutils.logger:warn("Port "..msg.." is unavailable, retrying for "..tostring(timeout).." seconds")
warned = true
end
end
socket.sleep(0.5)
end
end

Expand All @@ -241,6 +257,7 @@ end
-- @return A boolean: true for success, false otherwise
function _M.send_signal(args_config, signal)
-- Make sure nginx is there and is openresty
local port_timeout = 0 --Default 0 to not change current behaviour. TODO: make timeout configurable (note: this is a blocking timeout!)
local nginx_path = find_nginx()
if not nginx_path then
cutils.logger:error_exit(string.format("Kong cannot find an 'nginx' executable.\nMake sure it is in your $PATH or in one of the following directories:\n%s", table.concat(NGINX_SEARCH_PATHS, "\n")))
Expand All @@ -250,9 +267,13 @@ function _M.send_signal(args_config, signal)
if not signal then signal = START end

if signal == START then
local ports = { kong_config.proxy_port, kong_config.proxy_ssl_port, kong_config.admin_api_port }
for _,port in ipairs(ports) do
check_port(port)
local ports = {
["Kong proxy"] = kong_config.proxy_port,
["Kong proxy ssl"] = kong_config.proxy_ssl_port,
["Kong admin api"] = kong_config.admin_api_port
}
for name, port in pairs(ports) do
check_port(port, name, port_timeout)
end
end

Expand All @@ -270,7 +291,7 @@ function _M.send_signal(args_config, signal)
dnsmasq.stop(kong_config)
if kong_config.dns_resolver.dnsmasq then
local dnsmasq_port = kong_config.dns_resolver.port
check_port(dnsmasq_port)
check_port(dnsmasq_port, "dnsmasq", port_timeout)
dnsmasq.start(kong_config.nginx_working_dir, dnsmasq_port)
end
elseif signal == STOP or signal == QUIT then
Expand All @@ -281,7 +302,7 @@ function _M.send_signal(args_config, signal)
if signal == START or signal == RESTART or signal == RELOAD then
local res, code = IO.os_execute("ulimit -n")
if code == 0 and tonumber(res) < 4096 then
cutils.logger:warn("ulimit is currently set to \""..res.."\". For better performance set it to at least \"4096\" using \"ulimit -n\"")
cutils.logger:warn('ulimit is currently set to "'..res..'". For better performance set it to at least "4096" using "ulimit -n"')
end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/plugins/oauth2/access_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ describe("Authentication Plugin", function()
assert.are.equal(401, status)
assert.are.equal('Bearer realm="service" error="invalid_token" error_description="The access token is invalid"', headers['www-authenticate'])
assert.are.equal("invalid_token", body.error)
assert.are.equal("The access token invalid", body.error_description)
assert.are.equal("The access token is invalid", body.error_description)
end)

it("should return 401 Unauthorized when an invalid access token is being sent via the Authorization header", function()
Expand All @@ -705,7 +705,7 @@ describe("Authentication Plugin", function()
assert.are.equal(401, status)
assert.are.equal('Bearer realm="service" error="invalid_token" error_description="The access token is invalid"', headers['www-authenticate'])
assert.are.equal("invalid_token", body.error)
assert.are.equal("The access token invalid", body.error_description)
assert.are.equal("The access token is invalid", body.error_description)
end)

it("should return 401 Unauthorized when token has expired", function()
Expand Down

0 comments on commit ab908b3

Please sign in to comment.