Skip to content

Commit f5c3969

Browse files
committed
test: add test on error callback
1 parent b459927 commit f5c3969

File tree

1 file changed

+64
-1
lines changed

1 file changed

+64
-1
lines changed

test.lua

+64-1
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,17 @@ local function init_box()
228228
if_not_exists = true
229229
})
230230
truncate(g.id)
231+
232+
local h = box.schema.create_space('error_callback_test', {
233+
engine = space_type,
234+
if_not_exists = true
235+
})
236+
h:create_index('first', {
237+
type = index_type,
238+
parts = {1, 'NUM'},
239+
if_not_exists = true
240+
})
241+
truncate(h.id)
231242
end
232243

233244
local space_id = 'origin'
@@ -246,8 +257,9 @@ init_box()
246257
-- 7. restart test
247258
-- 8. complex key test
248259
-- 9. delays and scan callbacks test
260+
-- 10. error callback test
249261
-- ========================================================================= --
250-
test:plan(9)
262+
test:plan(10)
251263

252264
test:test('simple expires test', function(test)
253265
test:plan(4)
@@ -619,4 +631,55 @@ test:test('delays and scan callbacks test', function(test)
619631
expirationd.kill_task(task_name)
620632
end)
621633

634+
test:test('error callback test', function(test)
635+
test:plan(2)
636+
637+
-- Prepare the space.
638+
local tuples_count = 1
639+
local time = fiber.time()
640+
local space_name = 'error_callback_test'
641+
local expire_delta = 10
642+
643+
for i = 1, tuples_count do
644+
box.space[space_name]:insert{i, time + expire_delta}
645+
end
646+
647+
local task_name = 'error_callback_task'
648+
local cond = fiber.cond()
649+
650+
local error_cb_called = false
651+
local complete_cb_called = false
652+
local err_msg = 'The error is occured'
653+
654+
expirationd.start(
655+
task_name,
656+
space_name,
657+
function(args, tuple)
658+
error(err_msg)
659+
end,
660+
{
661+
args = {
662+
field_no = 2
663+
},
664+
-- The callbacks can be called multiple times because guardian_loop
665+
-- will restart the task.
666+
on_full_scan_error = function(task, err)
667+
if err:find(err_msg) then
668+
error_cb_called = true
669+
end
670+
end,
671+
on_full_scan_complete = function(task)
672+
complete_cb_called = true
673+
cond:signal()
674+
end
675+
}
676+
)
677+
678+
cond:wait()
679+
expirationd.kill_task(task_name)
680+
681+
test:ok(error_cb_called, 'the "error" callback has been invoked')
682+
test:ok(complete_cb_called, 'the "complete" callback has been invoked')
683+
end)
684+
622685
os.exit(test:check() and 0 or 1)

0 commit comments

Comments
 (0)