Skip to content

Commit

Permalink
feat(state): update on partial results
Browse files Browse the repository at this point in the history
  • Loading branch information
rcarriga committed Mar 13, 2023
1 parent ef2af39 commit 631a7cc
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 36 deletions.
14 changes: 8 additions & 6 deletions lua/neotest/consumers/state/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ local function init(client)
if not pending_update then
updated_cond:wait()
end
tracker:update_positions()
for _, adapter_id in ipairs(tracker.adapter_ids) do
tracker:update_positions(adapter_id)
tracker:update_counts(adapter_id)
end
pending_update = false
async.util.sleep(50)
end
Expand Down Expand Up @@ -51,11 +54,10 @@ local function init(client)
tracker:update_running(adapter_id, position_ids)
end

client.listeners.results = function(adapter_id, results, partial)
if partial then
return
end
tracker:update_results(adapter_id, results)
client.listeners.results = function(adapter_id, results)
tracker:decrement_running(adapter_id, results)
pending_update = true
updated_cond:notify_all()
end
end

Expand Down
58 changes: 28 additions & 30 deletions lua/neotest/consumers/state/tracker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -89,37 +89,36 @@ function StateTracker:update_counts(adapter_id)
end
end

function StateTracker:update_positions()
for adapter_id, state in pairs(self.adapter_states) do
state.positions = assert(self.client:get_position(nil, { adapter = adapter_id }))
state.status.total = self:count_tests(state.positions)
for _, node in state.positions:iter_nodes() do
local pos = node:data()
if pos.type == "file" and self.path_buffers[pos.path] then
if not state.buffers[pos.path] then
state.buffers[pos.path] = {
positions = node,
running = {},
status = {
failed = 0,
passed = 0,
skipped = 0,
total = 0,
running = 0,
},
}
end
function StateTracker:update_positions(adapter_id)
local state = self.adapter_states[adapter_id]
state.positions = assert(self.client:get_position(nil, { adapter = adapter_id }))
state.status.total = self:count_tests(state.positions)
for _, node in state.positions:iter_nodes() do
local pos = node:data()
if pos.type == "file" and self.path_buffers[pos.path] then
if not state.buffers[pos.path] then
state.buffers[pos.path] = {
positions = node,
running = {},
status = {
failed = 0,
passed = 0,
skipped = 0,
total = 0,
running = 0,
},
}
end
end
end

for path, buf_state in pairs(state.buffers) do
local new_tree = state.positions:get_key(path)
if not new_tree then
state.buffers[path] = nil
else
buf_state.positions = new_tree
buf_state.status.total = self:count_tests(new_tree)
end
for path, buf_state in pairs(state.buffers) do
local new_tree = state.positions:get_key(path)
if not new_tree then
state.buffers[path] = nil
else
buf_state.positions = new_tree
buf_state.status.total = self:count_tests(new_tree)
end
end
end
Expand Down Expand Up @@ -165,7 +164,7 @@ function StateTracker:update_running(adapter_id, position_ids)
self:update_counts(adapter_id)
end

function StateTracker:update_results(adapter_id, results)
function StateTracker:decrement_running(adapter_id, results)
local state = self:adapter_state(adapter_id)
local running = state.running

Expand All @@ -185,7 +184,6 @@ function StateTracker:update_results(adapter_id, results)
end
end
end
self:update_counts(adapter_id)
end

return StateTracker

0 comments on commit 631a7cc

Please sign in to comment.