Skip to content

Commit

Permalink
test: check_tuples_not_expired_by_timestamp
Browse files Browse the repository at this point in the history
Transferring the taptest to the luatest testing system with renaming the
tests and using the existing spaces in helpers.

Check that after run tuples is not expired. Let's make sure that after
the expiration starts, no tuples will be archived since the timestamp
has an advantage of 2 seconds.

Updated test's name:

- not expired task -> test_check_tuples_not_expired_by_timestamp

Part of #61
  • Loading branch information
ArtDu committed Apr 2, 2023
1 parent 8edc009 commit 3139dc8
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 75 deletions.
83 changes: 8 additions & 75 deletions test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -282,82 +282,15 @@ init_box()

-- ========================================================================= --
-- TAP TESTS:
-- 1. errors test,
-- 2. not expire test,
-- 3. kill zombie test
-- 4. multiple expires test
-- 5. default drop function test
-- 6. restart test
-- 7. complex key test
-- 8. delays and scan callbacks test
-- 9. 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(9)

test:test("execution error test", function (test)
test:plan(2)
expirationd.start(
"test",
space_id,
check_tuple_expire_by_timestamp_error,
{
process_expired_tuple = put_tuple_to_archive,
args = {
field_no = 3,
archive_space_id = archive_space_id,
},
}
)
test:is(expirationd.task("test").restarts, 1, 'checking restart count')

expirationd.start("test",
space_id,
check_tuple_expire_by_timestamp,
{
process_expired_tuple = put_tuple_to_archive_error,
args = {
field_no = 3,
archive_space_id = archive_space_id,
},
}
)
local task = expirationd.task("test")
test:is(task.restarts, 1, 'Error task executed')
expirationd.kill("test")
end)

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 @@ -109,3 +109,44 @@ function g.test_archive_by_timestamp(cg)
t.assert_equals(task.expired_tuples_count, #deleted)
t.assert_items_include(space:select(nil, {limit = 1000}), nondeleted)
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 3139dc8

Please sign in to comment.