spec/zk/client_spec.rb in zk-1.5.0 vs spec/zk/client_spec.rb in zk-1.5.1

- old
+ new

@@ -38,7 +38,81 @@ wait_until(5) { @zk.closed? }.should be_true end end end + + describe :retry do + include_context 'connection opts' + + before do + @zk = ZK::Client::Threaded.new(connection_host, :reconect => false, :connect => false) + end + + after do + @zk.close! unless @zk.closed? + end + + it %[should retry a Retryable operation] do + # TODO: this is a terrible test. there is no way to guarantee that this + # has been retried. the join at the end should not raise an error + + @zk.should_not be_connected + + th = Thread.new do + @zk.stat('/path/to/blah', :retry_duration => 30) + end + + th.run + + @zk.connect + th.join(5).should == th + end + + it %[barfs if the connection is closed before the connected event is received] do + @zk.should_not be_connected + + exc = nil + + th = Thread.new do + # this nonsense is because 1.8.7 is psychotic + begin + @zk.stat('/path/to/blah', :retry_duration => 300) + rescue Exception + exc = $! + end + end + + th.run + + @zk.close! + + th.join(5).should == th + + exc.should_not be_nil + exc.should be_kind_of(ZK::Exceptions::Retryable) + end + + it %[should barf if the timeout expires] do + @zk.should_not be_connected + + exc = nil + + th = Thread.new do + # this nonsense is because 1.8.7 is psychotic + begin + @zk.stat('/path/to/blah', :retry_duration => 0.001) + rescue Exception + exc = $! + end + end + + th.run + + th.join(5).should == th + + exc.should_not be_nil + exc.should be_kind_of(ZK::Exceptions::Retryable) + end + end end # ZK::Client::Threaded