core: Environment#lock tests

This commit is contained in:
Mitchell Hashimoto 2014-02-08 14:50:52 -08:00
parent 1e50e7aca1
commit 86454ddac9
2 changed files with 36 additions and 0 deletions

View File

@ -343,6 +343,9 @@ module Vagrant
# method. During this time, any other environment which attempts
# to lock which points to the same lock file will fail.
def lock
# If we don't have a block, then locking is useless, so ignore it
return if !block_given?
# This allows multiple locks in the same process to be nested
return yield if @lock_acquired

View File

@ -194,6 +194,39 @@ describe Vagrant::Environment do
end
end
describe "#lock" do
it "does nothing if no block is given" do
subject.lock
end
it "locks the environment" do
another = env.create_vagrant_env
raised = false
subject.lock do
begin
another.lock
rescue Vagrant::Errors::EnvironmentLockedError
raised = true
end
end
expect(raised).to be_true
end
it "allows nested locks on the same environment" do
success = false
subject.lock do
subject.lock do
success = true
end
end
expect(success).to be_true
end
end
describe "#machine" do
# A helper to register a provider for use in tests.
def register_provider(name, config_class=nil, options=nil)