Skip to content

Commit 4f4ea9c

Browse files
committed
fix(test): detect dead child jobs during waits
1 parent 27e4f0a commit 4f4ea9c

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

‎tests/helpers.lua‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,10 @@ function M.wait_until(child, expression, description, timeout)
318318
if ok and value == true then return true end
319319
if not ok then
320320
last_error = value
321+
local job_id = child_job_id(child)
322+
local dead_job = job_id and not job_is_alive(job_id)
321323
local running_ok, running = pcall(child.is_running)
322-
if running_ok and not running then
324+
if dead_job or (running_ok and not running) then
323325
error(("Child Neovim exited while waiting for %s: %s"):format(description, cleanup_error_message(value)), 0)
324326
end
325327
end

‎tests/unit/e2e_helpers_spec.lua‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ local function with_helpers(options, callback)
2626
clock = 0,
2727
}
2828
local root = options.root or "/fixture-root"
29-
if options.job_id then state.jobs_alive[options.job_id] = true end
29+
if options.job_id then state.jobs_alive[options.job_id] = options.job_alive ~= false end
3030
for _, channel in ipairs(options.channels or {}) do
3131
if options.channel_alive ~= false then state.jobs_alive[channel.id] = true end
3232
end
@@ -195,6 +195,19 @@ T["WAIT-03 retains the final RPC error when a live child never becomes ready"] =
195195
end)
196196
end
197197

198+
T["WAIT-04 detects a dead child job even when the child wrapper still reports running"] = function()
199+
with_helpers({ job_id = 42, job_alive = false, wait_values = { "error" } }, function(helpers, state)
200+
local child = helpers.start_child()
201+
local ok, err = pcall(helpers.wait_until, child, "ready", "child readiness", 100)
202+
203+
assert.is_false(ok)
204+
assert_contains(err, "Child Neovim exited while waiting for child readiness")
205+
assert_contains(err, "child RPC failed")
206+
assert.is_true(#state.jobwait_ids >= 1)
207+
helpers.stop_child(child)
208+
end)
209+
end
210+
198211
T["CHILD-01 starts a ready child and loads requested plugins"] = function()
199212
with_helpers({ wait_values = { true } }, function(helpers, state, root)
200213
local child = helpers.start_ready_child { "astrolsp" }

0 commit comments

Comments
 (0)