From dc39ce90f99a77699317bd31d95ce970690a4624 Mon Sep 17 00:00:00 2001 From: William Boman Date: Sun, 6 Mar 2022 21:48:29 +0100 Subject: run server installation in async execution context (#525) --- tests/server_spec.lua | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'tests/server_spec.lua') diff --git a/tests/server_spec.lua b/tests/server_spec.lua index 744b4cf8..81ae83b0 100644 --- a/tests/server_spec.lua +++ b/tests/server_spec.lua @@ -2,6 +2,13 @@ local spy = require "luassert.spy" local lsp_installer = require "nvim-lsp-installer" local server = require "nvim-lsp-installer.server" local a = require "nvim-lsp-installer.core.async" +local context = require "nvim-lsp-installer.installers.context" +local fs = require "nvim-lsp-installer.fs" + +local function timestamp() + local seconds, microseconds = vim.loop.gettimeofday() + return (seconds * 1000) + math.floor(microseconds / 1000) +end describe("server", function() it( @@ -47,4 +54,43 @@ describe("server", function() assert.is_false(srv:is_installed()) end) ) + + it( + "should remove directories upon installation failure", + async_test(function() + local srv = FailingServerGenerator { + name = "remove_dirs_failure", + root_dir = server.get_server_root_path "remove_dirs_failure", + installer = { + -- 1. sleep 500ms + function(_, callback) + vim.defer_fn(function() + callback(true) + end, 500) + end, + -- 2. promote install dir + context.promote_install_dir(), + -- 3. fail + function(_, callback) + callback(false) + end, + }, + } + srv:install() + + -- 1. installation started + a.sleep(50) + assert.is_true(fs.dir_exists(srv:get_tmp_install_dir())) + + -- 2. install dir promoted + a.sleep(500) + assert.is_false(fs.dir_exists(srv:get_tmp_install_dir())) + + -- 3. installation failed + a.sleep(200) + + assert.is_false(srv:is_installed()) + assert.is_false(fs.dir_exists(srv:get_tmp_install_dir())) + end) + ) end) -- cgit v1.2.3-70-g09d2