core: Environment#lock tests
This commit is contained in:
parent
1e50e7aca1
commit
86454ddac9
|
@ -343,6 +343,9 @@ module Vagrant
|
||||||
# method. During this time, any other environment which attempts
|
# method. During this time, any other environment which attempts
|
||||||
# to lock which points to the same lock file will fail.
|
# to lock which points to the same lock file will fail.
|
||||||
def lock
|
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
|
# This allows multiple locks in the same process to be nested
|
||||||
return yield if @lock_acquired
|
return yield if @lock_acquired
|
||||||
|
|
||||||
|
|
|
@ -194,6 +194,39 @@ describe Vagrant::Environment do
|
||||||
end
|
end
|
||||||
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
|
describe "#machine" do
|
||||||
# A helper to register a provider for use in tests.
|
# A helper to register a provider for use in tests.
|
||||||
def register_provider(name, config_class=nil, options=nil)
|
def register_provider(name, config_class=nil, options=nil)
|
||||||
|
|
Loading…
Reference in New Issue