@@ -228,6 +228,17 @@ local function init_box()
228
228
if_not_exists = true
229
229
})
230
230
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 )
231
242
end
232
243
233
244
local space_id = ' origin'
@@ -246,8 +257,9 @@ init_box()
246
257
-- 7. restart test
247
258
-- 8. complex key test
248
259
-- 9. delays and scan callbacks test
260
+ -- 10. error callback test
249
261
-- ========================================================================= --
250
- test :plan (9 )
262
+ test :plan (10 )
251
263
252
264
test :test (' simple expires test' , function (test )
253
265
test :plan (4 )
@@ -619,4 +631,55 @@ test:test('delays and scan callbacks test', function(test)
619
631
expirationd .kill_task (task_name )
620
632
end )
621
633
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
+
622
685
os.exit (test :check () and 0 or 1 )
0 commit comments