Skip to content

Commit

Permalink
tests: re-enable and fix flaky tests in spec/02-integration/03-db/07-…
Browse files Browse the repository at this point in the history
…tags_spec.lua (#10715)
  • Loading branch information
ADD-SP committed Jun 26, 2023
1 parent 41a7643 commit 04d637b
Showing 1 changed file with 37 additions and 29 deletions.
66 changes: 37 additions & 29 deletions spec/02-integration/03-db/07-tags_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -219,23 +219,6 @@ for _, strategy in helpers.each_strategy() do
describe("page() by tag", function()
local single_tag_count = 5
local total_entities_count = 100
for i = 1, total_entities_count do
local service = {
host = "anotherexample-" .. i .. ".org",
name = "service-paging" .. i,
tags = { "paging", "team_paging_" .. fmod(i, 5), "irrelevant_tag" }
}
local row, err, err_t = bp.services:insert(service)
assert.is_nil(err)
assert.is_nil(err_t)
assert.same(service.tags, row.tags)
end

if strategy == "off" then
local entities = assert(bp.done())
local dc = assert(declarative_config.load(helpers.test_conf.loaded_plugins))
declarative.load_into_cache(dc:flatten(entities))
end

local scenarios = { -- { tags[], expected_result_count }
{
Expand All @@ -262,6 +245,26 @@ for _, strategy in helpers.each_strategy() do

local paging_size = { total_entities_count/single_tag_count, }

lazy_setup(function()
for i = 1, total_entities_count do
local service = {
host = "anotherexample-" .. i .. ".org",
name = "service-paging" .. i,
tags = { "paging", "team_paging_" .. fmod(i, 5), "irrelevant_tag" }
}
local row, err, err_t = bp.services:insert(service)
assert.is_nil(err)
assert.is_nil(err_t)
assert.same(service.tags, row.tags)
end

if strategy == "off" then
local entities = assert(bp.done())
local dc = assert(declarative_config.load(helpers.test_conf.loaded_plugins))
declarative.load_into_cache(dc:flatten(entities))
end
end)

for s_idx, scenario in ipairs(scenarios) do

local opts, expected_count = unpack(scenario)
Expand Down Expand Up @@ -342,20 +345,25 @@ for _, strategy in helpers.each_strategy() do
assert.stub(ngx.log).was_not_called()
end)

it("#flaky and returns as normal if page size is large enough", function()
it("and returns as normal if page size is large enough", function()
stub(ngx, "log")

local rows, err, err_t, offset = db.services:page(enough_page_size, nil,
{ tags = { "paging", "team_paging_1" }, tags_cond = 'and' })
assert(is_valid_page(rows, err, err_t))
assert.equal(enough_page_size, #rows)
if offset then
rows, err, err_t, offset = db.services:page(enough_page_size, offset,
{ tags = { "paging", "team_paging_1" }, tags_cond = 'and' })
assert(is_valid_page(rows, err, err_t))
assert.equal(0, #rows)
assert.is_nil(offset)
end
-- cassandra is a bit slow on CI, so we need to wait a bit
assert
.with_timeout(15)
.eventually(function()
local rows, err, err_t, offset = db.services:page(enough_page_size, nil,
{ tags = { "paging", "team_paging_1" }, tags_cond = 'and' })
assert(is_valid_page(rows, err, err_t))
assert.equal(enough_page_size, #rows)
if offset then
rows, err, err_t, offset = db.services:page(enough_page_size, offset,
{ tags = { "paging", "team_paging_1" }, tags_cond = 'and' })
assert(is_valid_page(rows, err, err_t))
assert.equal(0, #rows)
assert.is_nil(offset)
end
end)

assert.stub(ngx.log).was_not_called()
end)
Expand Down

0 comments on commit 04d637b

Please sign in to comment.