Skip to content

Commit b459927

Browse files
committed
test: add test task delays and callbacks
Added test delays (iteration and full scan) and full scan iteration callbacks.
1 parent af43c2e commit b459927

File tree

1 file changed

+80
-1
lines changed

1 file changed

+80
-1
lines changed

test.lua

+80-1
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,17 @@ local function init_box()
217217
if_not_exists = true
218218
})
219219
truncate(f.id)
220+
221+
local g = box.schema.create_space('delays_test', {
222+
engine = space_type,
223+
if_not_exists = true
224+
})
225+
g:create_index('first', {
226+
type = index_type,
227+
parts = {1, 'NUM'},
228+
if_not_exists = true
229+
})
230+
truncate(g.id)
220231
end
221232

222233
local space_id = 'origin'
@@ -234,8 +245,9 @@ init_box()
234245
-- 6. default drop function test
235246
-- 7. restart test
236247
-- 8. complex key test
248+
-- 9. delays and scan callbacks test
237249
-- ========================================================================= --
238-
test:plan(8)
250+
test:plan(9)
239251

240252
test:test('simple expires test', function(test)
241253
test:plan(4)
@@ -540,4 +552,71 @@ test:test("complex key test", function(test)
540552
expirationd.kill_task("test")
541553
end)
542554

555+
test:test('delays and scan callbacks test', function(test)
556+
test:plan(4)
557+
558+
-- Prepare the space.
559+
local tuples_count = 10
560+
local time = fiber.time()
561+
local space_name = 'delays_test'
562+
local expire_delta = 10
563+
564+
for i = 1, tuples_count do
565+
box.space[space_name]:insert{i, time + expire_delta}
566+
end
567+
568+
-- To check all delays (iteration and full scan), two full scan
569+
-- iterations will be performed.
570+
local first_iteration_done = false
571+
local task_name = 'delays_task'
572+
local cond = fiber.cond()
573+
local start_time = 0
574+
local complete_time = 0
575+
576+
local iteration_delay = 1
577+
local full_scan_delay = 2
578+
579+
expirationd.start(
580+
task_name,
581+
space_name,
582+
check_tuple_expire_by_timestamp,
583+
{
584+
args = {
585+
field_no = 2
586+
},
587+
tuples_per_iteration = 10,
588+
iteration_delay = iteration_delay,
589+
full_scan_delay = full_scan_delay,
590+
on_full_scan_start = function(task)
591+
start_time = fiber.time()
592+
if first_iteration_done then
593+
-- Check the full scan delay with an accuracy
594+
-- of 0.1 seconds.
595+
test:ok(math.abs(start_time - complete_time -
596+
full_scan_delay) < 0.1, 'test full scan delay')
597+
end
598+
end,
599+
on_full_scan_success = function(task)
600+
-- Must be called twice.
601+
test:ok(true, 'test success callback invoke')
602+
end,
603+
on_full_scan_complete = function(task)
604+
complete_time = fiber.time()
605+
if first_iteration_done then
606+
cond:signal()
607+
else
608+
-- Check the iteration delay with an accuracy
609+
-- of 0.1 seconds.
610+
test:ok(math.abs(complete_time - start_time -
611+
iteration_delay) < 0.1, 'test iteration delay')
612+
first_iteration_done = true
613+
end
614+
end
615+
}
616+
)
617+
618+
cond:wait()
619+
expirationd.kill_task(task_name)
620+
end)
621+
543622
os.exit(test:check() and 0 or 1)

0 commit comments

Comments
 (0)