spec/support/client_forker.rb in zk-1.5.0 vs spec/support/client_forker.rb in zk-1.5.1

- old
+ new

@@ -10,10 +10,11 @@ def initialize(cnx_args, base_path) @cnx_args = cnx_args @base_path = base_path @pids_root = "#{@base_path}/pid" + @child_latch = Latch.new end LBORDER = ('-' * 35) << '< ' RBORDER = ' >' << ('-' * 35) @@ -61,10 +62,17 @@ proc do |s,dt,pn,msg| "#{CLEAR}#{YELLOW}#{orig_formatter.call(s,dt,pn,msg)}#{CLEAR}" end end + def start_child_exit_thread(pid) + @child_exit_thread ||= Thread.new do + _, @stat = Process.wait2(pid) + @child_latch.release + end + end + def run before mark 'BEGIN TEST' logger.debug { "Process.pid of parent: #{Process.pid}" } @@ -100,11 +108,10 @@ mark 'FORK' @pid = fork do Thread.abort_on_exception = true - ::Logging.reopen @zk.wait_until_connected child_pid_path = "#{@pids_root}/#{$$}" @@ -167,10 +174,12 @@ else exit! 1 end end # forked child + start_child_exit_thread(@pid) + # replicates deletion watcher inside child child_pid_path = "#{@pids_root}/#{@pid}" delete_latch = Latch.new @@ -186,12 +195,13 @@ end end delete_latch.await if @zk.exists?(child_pid_path, :watch => true) - _, @stat = Process.wait2(@pid) + @child_latch.await(30) # if we don't get a response in 30 seconds, then we're *definately* hosed + + raise "Child did not exit after 30 seconds of waiting, something is very wrong" unless @stat -# $stderr.puts "#{@pid} exited with status: #{stat.inspect}" ensure mark "END TEST" kill_child! tear_down end