summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Keiser <john@johnkeiser.com>2016-08-05 12:48:28 -0700
committerJohn Keiser <john@johnkeiser.com>2016-08-05 15:01:02 -0700
commitc6b4eb990e17021a47579e31fe85f83df827fffd (patch)
treea76d5bc92cd40ac9faf97b8f3a2778c2f5536a11
parent81a47cccbaf7ad71e735abccde10b78144b00fe2 (diff)
downloadchef-c6b4eb990e17021a47579e31fe85f83df827fffd.tar.gz
Remove race conditions from run_lock_specjk/run_lock_spec_race
-rw-r--r--spec/functional/run_lock_spec.rb27
1 files changed, 17 insertions, 10 deletions
diff --git a/spec/functional/run_lock_spec.rb b/spec/functional/run_lock_spec.rb
index f1e480c917..19d45d3e7d 100644
--- a/spec/functional/run_lock_spec.rb
+++ b/spec/functional/run_lock_spec.rb
@@ -258,11 +258,12 @@ 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
p1 = fork do
expect(run_lock.test).to eq(true)
- run_lock.save_pid
- sleep 2
- exit! 1
+ # Wait for the test to tell us we can exit before exiting
+ from_tests.readline
+ exit! 0
end
wait_on_lock
@@ -272,23 +273,29 @@ describe Chef::RunLock do
exit! 0
end
- Process.waitpid2(p2)
- Process.waitpid2(p1)
+ pid, exit_status = Process.waitpid2(p2)
+ expect(exit_status).to eq(0)
+ to_fork.puts "you can exit now"
+ pid, exit_status = Process.waitpid2(p1)
+ expect(exit_status).to eq(0)
end
it "test returns without waiting when the lock is acquired" do
run_lock = Chef::RunLock.new(lockfile)
+ from_tests, to_fork = IO.pipe
p1 = fork do
run_lock.acquire
- run_lock.save_pid
- sleep 2
- exit! 1
+ # Wait for the test to tell us we can exit before exiting
+ from_tests.readline
+ exit! 0
end
wait_on_lock
-
expect(run_lock.test).to eq(false)
- Process.waitpid2(p1)
+
+ to_fork.puts "you can exit now"
+ pid, exit_status = Process.waitpid2(p1)
+ expect(exit_status).to eq(0)
end
end