Skip to content

Commit 7730c15

Browse files
committed
fix(strategies): avoid concurrent writes
See #488
1 parent 36bb392 commit 7730c15

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

lua/neotest/client/strategies/integrated/init.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ return function(spec)
2929
assert(not open_err, open_err)
3030

3131
output_accum:subscribe(function(data)
32-
vim.loop.fs_write(output_fd, data, nil, function(write_err)
32+
vim.uv.fs_write(output_fd, data, nil, function(write_err)
3333
assert(not write_err, write_err)
3434
end)
3535
end)
@@ -45,7 +45,7 @@ return function(spec)
4545
output_finish_future.set()
4646
return
4747
end
48-
output_accum:push(table.concat(data, "\n"))
48+
nio.run(function() output_accum:push(table.concat(data, "\n")) end)
4949
end,
5050
on_exit = function(_, code)
5151
result_code = code

lua/neotest/types/fanout_accum.lua

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
local nio = require("nio")
12
local logger = require("neotest.logging")
23
local neotest = {}
34

@@ -7,6 +8,7 @@ local neotest = {}
78
---@field consumers fun(data: T)[]
89
---@field data? T
910
---@field accum fun(prev: T, new: any): T A function to combine previous data and new data
11+
---@field semaphore nio.control.Semaphore
1012
neotest.FanoutAccum = {}
1113

1214
---@generic T
@@ -19,6 +21,7 @@ function neotest.FanoutAccum:new(accum, init)
1921
data = init,
2022
accum = accum,
2123
consumers = {},
24+
semaphore = nio.control.semaphore(1)
2225
}, self)
2326
end
2427

@@ -40,12 +43,15 @@ function neotest.FanoutAccum:subscribe(cb)
4043
end
4144
end
4245

46+
---@async
4347
---@param data T
4448
function neotest.FanoutAccum:push(data)
45-
self.data = self.accum(self.data, data)
46-
for _, cb in ipairs(self.consumers) do
47-
cb(data)
48-
end
49+
self.semaphore.with(function()
50+
self.data = self.accum(self.data, data)
51+
for _, cb in ipairs(self.consumers) do
52+
cb(data)
53+
end
54+
end)
4955
end
5056

5157
---@private

0 commit comments

Comments
 (0)