Skip to content

Commit

Permalink
Fixing specs for both Cassandra and Postgres
Browse files Browse the repository at this point in the history
  • Loading branch information
subnetmarco authored and thibaultcha committed Mar 9, 2016
1 parent f141eb7 commit ae4bc10
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .luacheckrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
redefined = false
unused_args = false
globals = {"ngx", "dao", "app", "configuration", "events", "serf"}
globals = {"ngx", "app"}

files["kong/"] = {
std = "luajit"
Expand Down
1 change: 0 additions & 1 deletion kong/api/routes/cluster.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
local singletons = require "kong.singletons"
local responses = require "kong.tools.responses"
local utils = require "kong.tools.utils"

local pairs = pairs
local table_insert = table.insert
Expand Down
2 changes: 1 addition & 1 deletion kong/api/routes/kong.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ return {
pending = ngx.timer.pending_count()
},
plugins = {
available_on_server = configuration.plugins,
available_on_server = singletons.configuration.plugins,
enabled_in_cluster = distinct_plugins
},
lua_version = jit and jit.version or _VERSION,
Expand Down
6 changes: 5 additions & 1 deletion kong/cli/utils/services.lua
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ end
function _M.stop_all(configuration, configuration_path)
-- Backwards
for i=#services, 1, -1 do
services[i](configuration, configuration_path):stop()
local service = services[i](configuration, configuration_path)
service:stop()
while service:is_running() do
-- Wait
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion kong/core/cluster.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ local function async_autojoin(premature)
ngx.log(ngx.ERR, tostring(err))
elseif #members < 2 then
-- Trigger auto-join
local _, err = serf:_autojoin(cluster_utils.get_node_name(singletons.configuration))
local _, err = singletons.serf:_autojoin(cluster_utils.get_node_name(singletons.configuration))
if err then
ngx.log(ngx.ERR, tostring(err))
end
Expand Down
4 changes: 2 additions & 2 deletions kong/kong.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ end
-- @treturn table Array of plugins to execute in context handlers.
local function load_node_plugins(configuration)
ngx.log(ngx.DEBUG, "Discovering used plugins")
local rows, err = dao.plugins:find_all()
local rows, err = singletons.dao.plugins:find_all()
if err then
error(err)
end
Expand Down Expand Up @@ -159,7 +159,7 @@ end
function Kong.init_worker()
core.init_worker.before()

dao:init() -- Executes any initialization by the DB
singletons.dao:init() -- Executes any initialization by the DB

for _, plugin in ipairs(singletons.loaded_plugins) do
plugin.handler:init_worker()
Expand Down
2 changes: 1 addition & 1 deletion kong/plugins/rate-limiting/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ end
local function increment_async(premature, api_id, identifier, current_timestamp, value)
if premature then return end

local _, stmt_err = dao.ratelimiting_metrics:increment(api_id, identifier, current_timestamp, value)
local _, stmt_err = singletons.dao.ratelimiting_metrics:increment(api_id, identifier, current_timestamp, value)
if stmt_err then
ngx.log(ngx.ERR, "failed to increment: ", tostring(stmt_err))
end
Expand Down
4 changes: 3 additions & 1 deletion spec/integration/cli/cmds/start_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ describe("CLI", function()
assert.are.same(0, exit_code)
end)

it("should not work when a plugin is being used in the DB but it's not in the configuration", function()
it("#ci should not work when a plugin is being used in the DB but it's not in the configuration", function()
spec_helper.prepare_db()

local cassandra = require "cassandra"
local UUID = "d7dcf800-f155-417e-a282-b6189d7d901b"

Expand Down
2 changes: 1 addition & 1 deletion spec/integration/proxy/dns_resolver_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe("DNS", function()

thread:join()
end)
it("should work when calling local hostname #ci", function()
it("should work when calling local hostname", function()
local thread = spec_helper.start_http_server(TCP_PORT) -- Starting the mock TCP server
local _, status = http_client.get(spec_helper.STUB_GET_URL, nil, { host = "dns2.com" })
assert.are.equal(200, status)
Expand Down
12 changes: 8 additions & 4 deletions spec/plugins/acl/access_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ describe("ACL Plugin", function()
end)

describe("Real-world usage", function()
it("should not fail", function()
it("#ci should not fail", function()
-- Create consumer
local response, status = http_client.post(API_URL.."/consumers/", {username="acl_consumer"})
assert.equals(201, status)
Expand Down Expand Up @@ -170,10 +170,14 @@ describe("ACL Plugin", function()
local _, status = http_client.post(API_URL.."/consumers/acl_consumer/acls/", {group="admin"..i})
assert.equals(201, status)

-- Wait for cache to be invalidate
repeat
-- Wait for cache to be invalidated
local exists = true
while(exists) do
local _, status = http_client.get(API_URL.."/cache/"..cache.acls_key(consumer_id))
until(status ~= 200)
if status ~= 200 then
exists = false
end
end

-- Make the request, and it should work
local _, status = http_client.get(STUB_GET_URL, {apikey = "secret123"}, {host = "acl_test"..i..".com"})
Expand Down
2 changes: 1 addition & 1 deletion spec/plugins/logging_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ end
local mock_bin_http = create_mock_bin()
local mock_bin_https = create_mock_bin()

describe("Logging Plugins #ci", function()
describe("Logging Plugins", function()

setup(function()
spec_helper.prepare_db()
Expand Down
14 changes: 8 additions & 6 deletions spec/spec_helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ local function kong_bin(signal, conf_file)
wait_process(env.configuration.nginx_working_dir.."/nginx.pid")
wait_process(env.configuration.nginx_working_dir.."/serf.pid")
wait_process(env.configuration.nginx_working_dir.."/dnsmasq.pid")
elseif signal == "quit" then
wait_process(env.configuration.nginx_working_dir.."/nginx.pid")
end

return result, exit_code
Expand Down Expand Up @@ -195,12 +197,12 @@ end
function _M.start_udp_server(port, ...)
local thread = Threads.new({
function(port)
local socket = require("socket")
local udp = socket.udp()
udp:setoption('reuseaddr', true)
udp:setsockname("*", port)
local data = udp:receivefrom()
udp:close()
local socket = require "socket"
local server = assert(socket.udp())
server:setoption('reuseaddr', true)
server:setsockname("*", port)
local data = server:receivefrom()
server:close()
return data
end;
}, port)
Expand Down

0 comments on commit ae4bc10

Please sign in to comment.