spec/zk/pool_spec.rb in zk-1.4.2 vs spec/zk/pool_spec.rb in zk-1.5.0
- old
+ new
@@ -53,38 +53,47 @@
describe :close_all! do
it %[should shutdown gracefully] do
release_q = Queue.new
+ latch = Latch.new
+
@about_to_block = false
+ @mutex = Mutex.new
+ @cond = ConditionVariable.new
+ @cnx = nil
+
open_th = Thread.new do
- @cnx = @connection_pool.checkout(true)
- @about_to_block = true
- # wait for signal to release our connection
- release_q.pop
+ @mutex.synchronize do
+ @cnx = @connection_pool.checkout(true)
+ @cond.broadcast
+ end
+ latch.await(30) # don't time out
end
- wait_until(5) { @about_to_block }
- @about_to_block.should be_true
+ @mutex.synchronize do
+ @cond.wait(@mutex) while @cnx.nil?
+ end
+ @cnx.should_not be_nil
+
closing_th = Thread.new do
@connection_pool.close_all!
end
wait_until(5) { @connection_pool.closing? }
@connection_pool.should be_closing
logger.debug { "connection pool is closing" }
- lambda { @connection_pool.with_connection { |c| } }.should raise_error(ZK::Exceptions::PoolIsShuttingDownException)
+ lambda { @connection_pool.with_connection { |c| c } }.should raise_error(ZK::Exceptions::PoolIsShuttingDownException)
- release_q << :ok_let_go
+ latch.release
open_th.join(5).should == open_th
- wait_until(5) { @connection_pool.closed? }
-# $stderr.puts "@connection_pool.pool_state: #{@connection_pool.pool_state.inspect}"
+ @connection_pool.wait_until_closed
@connection_pool.should be_closed
lambda do
closing_th.join(1).should == closing_th
@@ -92,29 +101,39 @@
end.should_not raise_error
end
end
describe :force_close! do
- it %[should raise PoolIsShuttingDownException in a thread blocked waiting for a connection] do
+ it %[should raise PoolIsShuttingDownException in a thread blocked waiting for a connection], :mri_187 => :broken do
@cnx = []
until @connection_pool.available_size <= 0
@cnx << @connection_pool.checkout
end
@cnx.length.should_not be_zero
+ # this exc nonsense is because 1.8.7's scheduler is broken
+ @exc = nil
+
th = Thread.new do
- @connection_pool.checkout(true)
+ begin
+ @connection_pool.checkout(true)
+ rescue
+ @exc = $!
+ end
end
# th.join_until { @connection_pool.count_waiters > 0 }
# @connection_pool.count_waiters.should > 0
@connection_pool.force_close!
- lambda { th.join(5) }.should raise_error(ZK::Exceptions::PoolIsShuttingDownException)
+ @connection_pool.wait_until_closed
+
+ th.join(5).should == th
+ @exc.should be_kind_of(ZK::Exceptions::PoolIsShuttingDownException)
end
end
it "should allow watchers still" do
@callback_called = false
@@ -127,24 +146,19 @@
rescue ZK::Exceptions::NoNode
end
end
@connection_pool.with_connection do |zk|
-# $stderr.puts "registering callback"
zk.watcher.register(@path) do |event|
-# $stderr.puts "callback fired! event: #{event.inspect}"
@callback_called = true
event.path.should == @path
-# $stderr.puts "signaling other waiters"
end
-# $stderr.puts "setting up watcher"
zk.exists?(@path, :watch => true).should be_false
end
@connection_pool.with_connection do |zk|
-# $stderr.puts "creating path"
zk.create(@path, "", :mode => :ephemeral).should == @path
end
wait_until(1) { @callback_called }