feat(runner): run test cases in parallel

Problem: test cases were executed sequentially, each waiting for the
previous process to finish before starting the next. On problems with
many test cases this meant wall-clock run time scaled linearly.

Solution: fan out all test case processes simultaneously. A remaining
counter fires on_done once all callbacks have returned. on_each is
called per completion as before; callers that pass on_each ignore its
arguments so the index semantics change is non-breaking.
This commit is contained in:
Barrett Ruth 2026-02-26 22:54:06 -05:00
parent 81f5273840
commit dcb99857ca

View file

@ -276,10 +276,9 @@ function M.run_all_test_cases(indices, debug, on_each, on_done)
end end
end end
local function run_next(pos) if #to_run == 0 then
if pos > #to_run then
logger.log( logger.log(
('Finished %s %d test cases.'):format(debug and 'debugging' or 'running', #to_run), ('Finished %s %d test cases.'):format(debug and 'debugging' or 'running', 0),
vim.log.levels.INFO, vim.log.levels.INFO,
true true
) )
@ -287,15 +286,25 @@ function M.run_all_test_cases(indices, debug, on_each, on_done)
return return
end end
M.run_test_case(to_run[pos], debug, function() local total = #to_run
local remaining = total
for _, idx in ipairs(to_run) do
M.run_test_case(idx, debug, function()
if on_each then if on_each then
on_each(pos, #to_run) on_each(idx, total)
end
remaining = remaining - 1
if remaining == 0 then
logger.log(
('Finished %s %d test cases.'):format(debug and 'debugging' or 'running', total),
vim.log.levels.INFO,
true
)
on_done(panel_state.test_cases)
end end
run_next(pos + 1)
end) end)
end end
run_next(1)
end end
---@return PanelState ---@return PanelState