Do not run duplicate instances of inventory check for a pool

This commit updates check_pool inventory check to prevent multiple instances from running at once. Without this change the inventory check may run in multiple threads simultaneously.
This commit is contained in:
kirby@puppetlabs.com 2018-06-28 20:32:44 -07:00
parent 8be578493a
commit df89617fdc
2 changed files with 37 additions and 12 deletions

View file

@ -2685,6 +2685,7 @@ EOT
let(:pool_object) { config[:pools][0] }
let(:new_vm) { 'newvm'}
let(:pool_name) { pool_object['name'] }
let(:mutex) { Mutex.new }
before do
expect(subject).not_to be_nil
@ -2790,6 +2791,27 @@ EOT
end
end
end
it 'should get the pool mutex' do
expect(subject).to receive(:pool_mutex).and_return(mutex).at_least(:once)
subject._check_pool(pool_object,provider)
end
it 'should run synchronize' do
expect(subject).to receive(:pool_mutex).and_return(mutex).at_least(:once)
expect(mutex).to receive(:synchronize).at_least(:once)
subject._check_pool(pool_object,provider)
end
it 'should yield when locked' do
expect(subject).to receive(:pool_mutex).and_return(mutex).at_least(:once)
mutex.lock
expect(mutex).to receive(:synchronize).and_yield
subject._check_pool(pool_object,provider)
end
end
# RUNNING