aboutsummaryrefslogtreecommitdiffstats
path: root/tests/mason-core/installer
diff options
context:
space:
mode:
authorWilliam Boman <william@redwill.se>2023-05-18 17:06:38 +0200
committerGitHub <noreply@github.com>2023-05-18 17:06:38 +0200
commit227f8a9aaae495f481c768f8346edfceaf6d2951 (patch)
tree8b2dad3c6175fac3c02489690304f759f21b3649 /tests/mason-core/installer
parentfix(ui): use vim.cmd("") for nvim-0.7.0 compatibility (#1307) (diff)
downloadmason-227f8a9aaae495f481c768f8346edfceaf6d2951.tar
mason-227f8a9aaae495f481c768f8346edfceaf6d2951.tar.gz
mason-227f8a9aaae495f481c768f8346edfceaf6d2951.tar.bz2
mason-227f8a9aaae495f481c768f8346edfceaf6d2951.tar.lz
mason-227f8a9aaae495f481c768f8346edfceaf6d2951.tar.xz
mason-227f8a9aaae495f481c768f8346edfceaf6d2951.tar.zst
mason-227f8a9aaae495f481c768f8346edfceaf6d2951.zip
feat(installer): lock package installation (#1290)
Diffstat (limited to 'tests/mason-core/installer')
-rw-r--r--tests/mason-core/installer/installer_spec.lua44
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/mason-core/installer/installer_spec.lua b/tests/mason-core/installer/installer_spec.lua
index 4a45e997..23eeb69e 100644
--- a/tests/mason-core/installer/installer_spec.lua
+++ b/tests/mason-core/installer/installer_spec.lua
@@ -167,4 +167,48 @@ describe("installer", function()
assert.equals("spawn: bash failed with exit code 42 and signal 0. ", tostring(result:err_or_nil()))
end)
)
+
+ it(
+ "should lock package",
+ async_test(function()
+ local handle = InstallHandleGenerator "dummy"
+ local callback = spy.new()
+ stub(handle.package.spec, "install", function()
+ a.sleep(3000)
+ end)
+
+ a.run(function()
+ return installer.execute(handle, { debug = true })
+ end, callback)
+
+ assert.wait_for(function()
+ assert.is_true(fs.sync.file_exists(path.package_lock "dummy"))
+ end)
+ handle:terminate()
+ assert.wait_for(function()
+ assert.spy(callback).was_called(1)
+ end)
+ assert.is_false(fs.sync.file_exists(path.package_lock "dummy"))
+ end)
+ )
+
+ it(
+ "should not run installer if package lock exists",
+ async_test(function()
+ local handle = InstallHandleGenerator "dummy"
+ local install = spy.new()
+ stub(handle.package.spec, "install", install)
+
+ fs.sync.write_file(path.package_lock "dummy", "dummypid")
+ local result = installer.execute(handle, { debug = true })
+ assert.is_true(fs.sync.file_exists(path.package_lock "dummy"))
+ fs.sync.unlink(path.package_lock "dummy")
+
+ assert.spy(install).was_not_called()
+ assert.equals(
+ "Lockfile exists, installation is already running in another process (pid: dummypid). Run with :MasonInstall --force to bypass.",
+ result:err_or_nil()
+ )
+ end)
+ )
end)