spec/zk/client_spec.rb in zk-1.2.0 vs spec/zk/client_spec.rb in zk-1.3.0
- old
+ new
@@ -29,7 +29,92 @@
wait_until(5) { @zk.closed? }.should be_true
end
end
end
-end
+
+ unless defined?(::JRUBY_VERSION)
+ describe :forked do
+ include_context 'connection opts'
+
+ before do
+ @base_path = '/zktests'
+ @pids_root = "#{@base_path}/pid"
+
+ ZK.open(*connection_args) do |z|
+ z.rm_rf(@base_path)
+ z.mkdir_p(@pids_root)
+ end
+ end
+
+ after do
+ if @pid
+ begin
+ Process.kill('TERM', @pid)
+ pid, st = Process.wait2(@pid)
+ logger.debug { "child #{@pid} exited with status: #{st.inspect}" }
+ rescue Errno::ESRCH
+ end
+ end
+
+ @zk.close! if @zk
+ ZK.open(*connection_args) { |z| z.rm_rf(@base_path) }
+ end
+
+ it %[should deliver callbacks in the child] do
+ pending_in_travis "skip this test, flaky in travis"
+ pending_rbx('fails in rubinius') do
+
+ logger.debug { "Process.pid of parent: #{Process.pid}" }
+
+ @zk = ZK.new do |z|
+ z.on_connected do
+ logger.debug { "on_connected fired, writing pid to path #{@pids_root}/#{$$}" }
+ begin
+ z.create("#{@pids_root}/#{Process.pid}", Process.pid.to_s)
+ rescue ZK::Exceptions::NodeExists
+ end
+ end
+ end
+
+ @parent_pid = $$
+
+ @zk.create("#{@pids_root}/#{$$}", $$.to_s)
+
+ event_catcher = EventCatcher.new
+
+ @zk.register(@pids_root, :only => :child) do |event|
+ event_catcher << event
+ end
+
+ @pid = fork do
+ @zk.reopen
+ @zk.wait_until_connected
+
+ wait_until(3) { @zk.exists?("#{@pids_root}/#{$$}") }
+
+ logger.debug { "in child: child pid path exists?: %p" % [@zk.exists?("#{@pids_root}/#{$$}")] }
+
+ exit! 0
+ end
+
+ _, stat = Process.wait2(@pid)
+
+ stat.should_not be_signaled
+ stat.should be_exited
+ stat.should be_success
+
+ event_catcher.synchronize do
+ unless event_catcher.child.empty?
+ event_catcher.wait_for_child
+ event_catcher.child.should_not be_empty
+ end
+ end
+
+ @zk.should be_exists("#{@pids_root}/#{@pid}")
+
+ end
+ end # should deliver callbacks in the child
+ end # forked
+ end # # jruby guard
+end # ZK::Client::Threaded