From 231908da78dd2f69958605062e2e5e26f54645d0 Mon Sep 17 00:00:00 2001 From: Itai Bohadana Date: Mon, 6 Oct 2025 11:44:19 +0300 Subject: [PATCH] fix(lua): add wait to socket connect --- lua/neotest-python/pytest.lua | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/lua/neotest-python/pytest.lua b/lua/neotest-python/pytest.lua index ad24278..1cbfe04 100644 --- a/lua/neotest-python/pytest.lua +++ b/lua/neotest-python/pytest.lua @@ -4,6 +4,19 @@ local logger = require("neotest.logging") local M = {} +---@async +---Calls callback after a certain time using uv.timer +---@param sleep_ms integer +---@param callback function +local function async_sleep(sleep_ms, callback) + local timer = assert(vim.uv.new_timer()) + timer:start(sleep_ms, 0, function() + timer:stop() + timer:close() + callback() + end) +end + ---@async ---Add test instances for path in root to positions ---@param positions neotest.Tree @@ -71,10 +84,12 @@ local function get_socket_path(cmd, messages, callback) -- 2. Connect to the unix socket local client = assert(vim.uv.new_pipe(false)) - - client:connect(socket_path, function(err) + local function _handle_tests(err) if err ~= nil then vim.print("Error", err) + async_sleep(500, function() + client:connect(socket_path, _handle_tests) + end) end -- 3. Send message(s) if type(messages) == "string" then @@ -92,7 +107,9 @@ local function get_socket_path(cmd, messages, callback) end) end) end - end) + end + + client:connect(socket_path, _handle_tests) end ---@async