Skip to content

Commit

Permalink
Merge 1b3318b into 977c8cc
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtDu committed Apr 3, 2023
2 parents 977c8cc + 1b3318b commit 973dbca
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 41 deletions.
49 changes: 8 additions & 41 deletions test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -272,49 +272,16 @@ init_box()

-- ========================================================================= --
-- TAP TESTS:
-- 1. not expire test,
-- 2. kill zombie test
-- 3. multiple expires test
-- 4. default drop function test
-- 5. restart test
-- 6. complex key test
-- 7. delays and scan callbacks test
-- 8. error callback test
-- 1. kill zombie test
-- 2. multiple expires test
-- 3. default drop function test
-- 4. restart test
-- 5. complex key test
-- 6. delays and scan callbacks test
-- 7. error callback test
-- ========================================================================= --

test:plan(8)

test:test("not expired task", function(test)
test:plan(2)

truncate(space_id)

local tuples_count = 5
local time = fiber.time()
for i = 1, tuples_count do
add_entry(space_id, i, get_email(i), time + 2)
end

expirationd.start(
"test",
space_id,
check_tuple_expire_by_timestamp,
{
process_expired_tuple = put_tuple_to_archive,
args = {
field_no = 3,
archive_space_id = archive_space_id,
},
}
)
local task = expirationd.task("test")
-- after run tuples is not expired
test:is(task.expired_tuples_count, 0, 'checking expired tuples empty')
-- wait 3 seconds and check: all tuples must be expired
fiber.sleep(3)
test:is(task.expired_tuples_count, tuples_count, 'checking expired tuples count')
expirationd.kill("test")
end)
test:plan(7)

test:test("zombie task kill", function(test)
test:plan(4)
Expand Down
41 changes: 41 additions & 0 deletions test/unit/expiration_process_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -171,3 +171,44 @@ function g.test_broken_process_expired_tuple(cg)
t.assert_ge(full_scan_counter, 3)
end)
end

function g.test_check_tuples_not_expired_by_timestamp(cg)
local space = cg.space
local space_archive = cg.space_archive
local task_name = cg.task_name

local total = 5
for i = 1, total do
local time = fiber.time()
space:insert({i, tostring(i), time + 2})
end

cg.full_scan_counter = 0
cg.task = expirationd.start(task_name, space.id, check_tuple_expire_by_timestamp,
{
process_expired_tuple = put_tuple_to_archive,
args = {
field_no = 3,
archive_space_id = space_archive.id
},
on_full_scan_complete = function()
cg.full_scan_counter = cg.full_scan_counter + 1
end
})
local task = cg.task

-- Tuples are not expired after run.
-- Сheck that after the expiration starts,
-- no tuples will be archived since the timestamp has an advantage of 2 seconds.
helpers.retrying({}, function()
t.assert(cg.full_scan_counter > 0)
t.assert_equals(task.expired_tuples_count, 0)
t.assert_equals(space_archive:count(), 0)
end)

-- Wait and check: all tuples must be expired.
helpers.retrying({}, function()
t.assert_equals(task.expired_tuples_count, total)
t.assert_equals(space_archive:count(), total)
end)
end

0 comments on commit 973dbca

Please sign in to comment.