Skip to content

Commit

Permalink
fix(tests): failures emerged running the scheduler
Browse files Browse the repository at this point in the history
after fixing the test scheduler helper, new failures emerged. This
commit fixes them.

fix(test-scheduler): pass github token to gh-storage
  • Loading branch information
samugi committed Feb 14, 2024
1 parent 7c29cec commit b0bce58
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 22 deletions.
13 changes: 2 additions & 11 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ jobs:

- name: Download runtimes file
uses: Kong/gh-storage/download@v1
env:
GITHUB_TOKEN: ${{ secrets.PAT }}
with:
repo-path: Kong/gateway-action-storage/main/.ci/runtimes.json

Expand Down Expand Up @@ -206,7 +208,6 @@ jobs:
docker logs kong_redis
- name: Run OpenTelemetry Collector
if: ${{ matrix.suite == 'plugins' }}
run: |
mkdir -p ${{ github.workspace }}/tmp/otel
touch ${{ github.workspace }}/tmp/otel/file_exporter.json
Expand Down Expand Up @@ -244,16 +245,6 @@ jobs:
luarocks --version
luarocks config
- name: Create kong_ro user in Postgres
run: |
psql -v ON_ERROR_STOP=1 -h localhost --username kong <<\EOD
CREATE user kong_ro;
GRANT CONNECT ON DATABASE kong TO kong_ro;
\c kong;
GRANT USAGE ON SCHEMA public TO kong_ro;
ALTER DEFAULT PRIVILEGES FOR ROLE kong IN SCHEMA public GRANT SELECT ON TABLES TO kong_ro;
EOD
- name: Tune up postgres max_connections
run: |
# arm64 runners may use more connections due to more worker cores
Expand Down
1 change: 1 addition & 0 deletions spec/01-unit/09-balancer/03-consistent_hashing_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ assert:set_parameter("TableFormatLevel", 5) -- when displaying tables, set a big
local client
local targets, balancers

require "spec.helpers" -- initialize db
local dns_utils = require "kong.resty.dns.utils"
local mocker = require "spec.fixtures.mocker"
local utils = require "kong.tools.utils"
Expand Down
7 changes: 5 additions & 2 deletions spec/02-integration/02-cmd/03-reload_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,9 @@ describe("key-auth plugin invalidation on dbless reload #off", function()
nginx_conf = "spec/fixtures/custom_nginx.template",
}))

-- wait for the worker to be ready
helpers.get_kong_workers(1)

proxy_client = helpers.proxy_client()
local res = assert(proxy_client:send {
method = "GET",
Expand Down Expand Up @@ -653,6 +656,7 @@ describe("key-auth plugin invalidation on dbless reload #off", function()
- key: my-new-key
]], yaml_file)
assert(helpers.reload_kong("off", "reload --prefix " .. helpers.test_conf.prefix, {
database = "off",
declarative_config = yaml_file,
}))

Expand All @@ -669,8 +673,7 @@ describe("key-auth plugin invalidation on dbless reload #off", function()
local body = assert.res_status(200, res)
local json = cjson.decode(body)
admin_client:close()
assert.same(1, #json.data)
return "my-new-key" == json.data[1].key
return #json.data == 1 and "my-new-key" == json.data[1].key
end, 5)

helpers.wait_until(function()
Expand Down
1 change: 1 addition & 0 deletions spec/02-integration/02-cmd/07-health_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ end
for _, health_cmd in ipairs({"health", "bin/kong-health"}) do
describe("kong health-check: " .. health_cmd, function()
lazy_setup(function()
helpers.get_db_utils(nil, {}) -- runs migrations
helpers.prepare_prefix()
end)
lazy_teardown(function()
Expand Down
33 changes: 25 additions & 8 deletions spec/02-integration/03-db/01-db_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,26 @@ local utils = require "kong.tools.utils"


for _, strategy in helpers.each_strategy() do
local postgres_only = strategy == "postgres" and it or pending

local postgres_only = strategy == "postgres" and it or pending


describe("db_spec [#" .. strategy .. "]", function()
lazy_setup(function()
local _, db = helpers.get_db_utils(strategy, {})
-- db RO permissions setup
local pg_ro_user = helpers.test_conf.pg_ro_user
local pg_db = helpers.test_conf.pg_database
db:schema_reset()
db.connector:query(string.format("CREATE user %s;", pg_ro_user))
db.connector:query(string.format([[
GRANT CONNECT ON DATABASE %s TO %s;
GRANT USAGE ON SCHEMA public TO %s;
ALTER DEFAULT PRIVILEGES FOR ROLE kong IN SCHEMA public GRANT SELECT ON TABLES TO %s;
]], pg_db, pg_ro_user, pg_ro_user, pg_ro_user))
helpers.bootstrap_database(db)
end)

describe("kong.db.init [#" .. strategy .. "]", function()
describe("kong.db.init", function()
describe(".new()", function()
it("errors on invalid arg", function()
assert.has_error(function()
Expand Down Expand Up @@ -103,7 +119,7 @@ for _, strategy in helpers.each_strategy() do
end)
end)

describe(":init_connector() [#" .. strategy .. "]", function()
describe(":init_connector()", function()
it("initializes infos", function()
local db, err = DB.new(helpers.test_conf, strategy)

Expand Down Expand Up @@ -177,7 +193,7 @@ for _, strategy in helpers.each_strategy() do
end)


describe(":connect() [#" .. strategy .. "]", function()
describe(":connect()", function()
lazy_setup(function()
helpers.get_db_utils(strategy, {})
end)
Expand Down Expand Up @@ -396,7 +412,7 @@ for _, strategy in helpers.each_strategy() do
end)
end)

describe("#testme :query() [#" .. strategy .. "]", function()
describe("#testme :query()", function()
lazy_setup(function()
helpers.get_db_utils(strategy, {})
end)
Expand Down Expand Up @@ -441,7 +457,7 @@ for _, strategy in helpers.each_strategy() do
end)
end)

describe(":setkeepalive() [#" .. strategy .. "]", function()
describe(":setkeepalive()", function()
lazy_setup(function()
helpers.get_db_utils(strategy, {})
end)
Expand Down Expand Up @@ -654,7 +670,7 @@ for _, strategy in helpers.each_strategy() do
end)


describe(":close() [#" .. strategy .. "]", function()
describe(":close()", function()
lazy_setup(function()
helpers.get_db_utils(strategy, {})
end)
Expand Down Expand Up @@ -855,4 +871,5 @@ for _, strategy in helpers.each_strategy() do
db:close()
end)
end)
end)
end
14 changes: 13 additions & 1 deletion spec/02-integration/03-db/11-postgres-ro_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,23 @@ for _, strategy in helpers.each_strategy() do
local proxy_client, admin_client

lazy_setup(function()
helpers.get_db_utils(strategy, {
local _, db = helpers.get_db_utils(strategy, {
"routes",
"services",
}) -- runs migrations

-- db RO permissions setup
local pg_ro_user = helpers.test_conf.pg_ro_user
local pg_db = helpers.test_conf.pg_database
db:schema_reset()
db.connector:query(string.format("CREATE user %s;", pg_ro_user))
db.connector:query(string.format([[
GRANT CONNECT ON DATABASE %s TO %s;
GRANT USAGE ON SCHEMA public TO %s;
ALTER DEFAULT PRIVILEGES FOR ROLE kong IN SCHEMA public GRANT SELECT ON TABLES TO %s;
]], pg_db, pg_ro_user, pg_ro_user, pg_ro_user))
helpers.bootstrap_database(db)

assert(helpers.start_kong({
database = strategy,
pg_ro_host = helpers.test_conf.pg_host,
Expand Down
4 changes: 4 additions & 0 deletions spec/02-integration/08-status_api/04-config_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ local cjson = require "cjson"

for _, strategy in helpers.all_strategies() do
describe("Status API - with strategy #" .. strategy, function()
lazy_setup(function()
helpers.get_db_utils(nil, {}) -- runs migrations
end)

it("default enable", function()
assert.truthy(helpers.kong_exec("start -c spec/fixtures/default_status_listen.conf"))
local client = helpers.http_client("127.0.0.1", 8007, 20000)
Expand Down

0 comments on commit b0bce58

Please sign in to comment.