local lu = require('luaunit')
local log = require('mc.logging')
TestTasks = {}
function TestTasks:setUp()
self._orig_log_error = log.error
package.loaded['tasks'] = nil
end
function TestTasks:tearDown()
if self._orig_log_error then
log.error = self._orig_log_error
end
package.loaded['tasks'] = nil
end
function TestTasks:test_loop_task_error_log()
local logged = false
log.error = function()
logged = true
end
local tasks = require('tasks')
local inst = tasks.new()
local t = inst:new_task('error_task')
local ok, err = t:run_task(function(_task)
error('task error')
end)
lu.assertFalse(ok)
if not ok then
log:error('[tasks] task [%s] error: %s', t.name, err)
end
lu.assertTrue(logged)
end
function TestTasks:test_process_next_tick_error_log()
local logged = false
log.error = function()
logged = true
end
local tasks = require('tasks')
local inst = tasks.new()
inst:next_tick(function()
error('next_tick error')
end)
inst:process_next_tick()
lu.assertTrue(logged)
end