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:
parent
81f5273840
commit
dcb99857ca
1 changed files with 27 additions and 18 deletions
|
|
@ -276,26 +276,35 @@ function M.run_all_test_cases(indices, debug, on_each, on_done)
|
|||
end
|
||||
end
|
||||
|
||||
local function run_next(pos)
|
||||
if pos > #to_run then
|
||||
logger.log(
|
||||
('Finished %s %d test cases.'):format(debug and 'debugging' or 'running', #to_run),
|
||||
vim.log.levels.INFO,
|
||||
true
|
||||
)
|
||||
on_done(panel_state.test_cases)
|
||||
return
|
||||
end
|
||||
|
||||
M.run_test_case(to_run[pos], debug, function()
|
||||
if on_each then
|
||||
on_each(pos, #to_run)
|
||||
end
|
||||
run_next(pos + 1)
|
||||
end)
|
||||
if #to_run == 0 then
|
||||
logger.log(
|
||||
('Finished %s %d test cases.'):format(debug and 'debugging' or 'running', 0),
|
||||
vim.log.levels.INFO,
|
||||
true
|
||||
)
|
||||
on_done(panel_state.test_cases)
|
||||
return
|
||||
end
|
||||
|
||||
run_next(1)
|
||||
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
|
||||
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)
|
||||
end
|
||||
end
|
||||
|
||||
---@return PanelState
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue