core: clean up the lock cleanup code, tests
This commit is contained in:
parent
0ed3c5174b
commit
4fb9832589
|
@ -358,18 +358,13 @@ module Vagrant
|
|||
return if !block_given?
|
||||
|
||||
# This allows multiple locks in the same process to be nested
|
||||
return yield if @locks[name]
|
||||
return yield if @locks[name] || opts[:noop]
|
||||
|
||||
# The path to this lock
|
||||
lock_path = data_dir.join("lock.#{name}.lock")
|
||||
|
||||
@logger.debug("Attempting to acquire process-lock: #{name}")
|
||||
|
||||
if name != "dotlock"
|
||||
lock("dotlock", no_clean: true) do
|
||||
f = File.open(lock_path, "w+")
|
||||
end
|
||||
else
|
||||
lock("dotlock", noop: name == "dotlock") do
|
||||
f = File.open(lock_path, "w+")
|
||||
end
|
||||
|
||||
|
@ -398,8 +393,8 @@ module Vagrant
|
|||
end
|
||||
|
||||
# Clean up the lock file, this requires another lock
|
||||
if !opts[:no_clean]
|
||||
lock("dotlock", no_clean: true) do
|
||||
if name != "dotlock"
|
||||
lock("dotlock") do
|
||||
f.close
|
||||
File.delete(lock_path)
|
||||
end
|
||||
|
|
|
@ -198,6 +198,13 @@ describe Vagrant::Environment do
|
|||
end
|
||||
|
||||
describe "#lock" do
|
||||
def lock_count
|
||||
subject.data_dir.
|
||||
children.
|
||||
find_all { |c| c.to_s.end_with?("lock") }.
|
||||
length
|
||||
end
|
||||
|
||||
it "does nothing if no block is given" do
|
||||
subject.lock
|
||||
end
|
||||
|
@ -228,6 +235,19 @@ describe Vagrant::Environment do
|
|||
|
||||
expect(success).to be_true
|
||||
end
|
||||
|
||||
it "cleans up all lock files" do
|
||||
inner_count = nil
|
||||
|
||||
expect(lock_count).to eq(0)
|
||||
subject.lock do
|
||||
inner_count = lock_count
|
||||
end
|
||||
|
||||
expect(inner_count).to_not be_nil
|
||||
expect(inner_count).to eq(2)
|
||||
expect(lock_count).to eq(1)
|
||||
end
|
||||
end
|
||||
|
||||
describe "#machine" do
|
||||
|
|
Loading…
Reference in New Issue