From 9d4d0475bc82a35671e4f6f720d9b7ff3ae0be81 Mon Sep 17 00:00:00 2001 From: John Keiser Date: Tue, 29 Sep 2015 13:54:10 -0700 Subject: Simplify kill loop with WNOHANG --- spec/functional/run_lock_spec.rb | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/spec/functional/run_lock_spec.rb b/spec/functional/run_lock_spec.rb index c559ee3421..78b3847d19 100644 --- a/spec/functional/run_lock_spec.rb +++ b/spec/functional/run_lock_spec.rb @@ -383,19 +383,12 @@ describe Chef::RunLock do example.log_event("#{name}.stop (pid #{pid})") begin # Send it the kill signal over and over until it dies - start_time = Time.now - dead = false - while Time.now - start_time < CLIENT_PROCESS_TIMEOUT + Timeout::timeout(CLIENT_PROCESS_TIMEOUT) do Process.kill(:KILL, pid) - Timeout::timeout(0.2) do - begin - Process.waitpid2(pid) - dead = true - rescue Timeout::Error - end + while !Process.waitpid2(pid, Process::WNOHANG) + sleep(0.05) end end - raise Timeout::Error, "took more than 10s to kill process #{pid}" if !dead example.log_event("#{name}.stop finished (stopped pid #{pid})") # Process not found is perfectly fine when we're trying to kill a process :) rescue Errno::ESRCH -- cgit v1.2.1