diff options
author | John Keiser <john@johnkeiser.com> | 2016-08-17 10:59:52 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-08-17 10:59:52 -0700 |
commit | 5d25c9fdd7830582bd61119890c7961b93600386 (patch) | |
tree | b39f1a19e46041c79b649641491309602c062ddb | |
parent | 87d719302a245d266a43d4445dc9d0cd11d93e20 (diff) | |
parent | f7966385db59e65ce413af13b35f9f2a53647700 (diff) | |
download | chef-5d25c9fdd7830582bd61119890c7961b93600386.tar.gz |
Merge pull request #5212 from chef/jk/runlock-race
Fix race where lockfile can be created but not yet acquired
-rw-r--r-- | spec/functional/run_lock_spec.rb | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/spec/functional/run_lock_spec.rb b/spec/functional/run_lock_spec.rb index 998e77f6b4..d270803698 100644 --- a/spec/functional/run_lock_spec.rb +++ b/spec/functional/run_lock_spec.rb @@ -46,9 +46,9 @@ describe Chef::RunLock do end WAIT_ON_LOCK_TIME = 1.0 - def wait_on_lock + def wait_on_lock(from_fork) Timeout.timeout(WAIT_ON_LOCK_TIME) do - sleep 0.1 until File.exist?(lockfile) + from_fork.readline end rescue Timeout::Error raise "Lockfile never created, abandoning test" @@ -257,14 +257,16 @@ describe Chef::RunLock do it "test returns true and acquires the lock" do run_lock = Chef::RunLock.new(lockfile) from_tests, to_fork = IO.pipe + from_fork, to_tests = IO.pipe p1 = fork do expect(run_lock.test).to eq(true) + to_tests.puts "lock acquired" # Wait for the test to tell us we can exit before exiting from_tests.readline exit! 0 end - wait_on_lock + wait_on_lock(from_fork) p2 = fork do expect(run_lock.test).to eq(false) @@ -281,14 +283,16 @@ describe Chef::RunLock do it "test returns without waiting when the lock is acquired" do run_lock = Chef::RunLock.new(lockfile) from_tests, to_fork = IO.pipe + from_fork, to_tests = IO.pipe p1 = fork do run_lock.acquire + to_tests.puts "lock acquired" # Wait for the test to tell us we can exit before exiting from_tests.readline exit! 0 end - wait_on_lock + wait_on_lock(from_fork) expect(run_lock.test).to eq(false) to_fork.puts "you can exit now" |