spec/zk/pool_spec.rb in zk-1.9.6 vs spec/zk/pool_spec.rb in zk-1.10.0
- old
+ new
@@ -6,11 +6,11 @@
before do
report_realtime('opening pool') do
@pool_size = 2
@connection_pool = ZK::Pool::Simple.new(connection_host, @pool_size, :watcher => :default)
- @connection_pool.should be_open
+ expect(@connection_pool).to be_open
end
end
after do
report_realtime("close_all!") do
@@ -20,11 +20,11 @@
end
unless th.join(5) == th
logger.warn { "Forcing pool closed!" }
@connection_pool.force_close!
- th.join(5).should == th
+ expect(th.join(5)).to eq(th)
end
end
end
report_realtime("closing") do
@@ -38,26 +38,24 @@
end
it "should allow you to execute commands on a connection" do
@connection_pool.with_connection do |zk|
zk.create("/test_pool", "", :mode => :ephemeral)
- zk.exists?("/test_pool").should be_true
+ expect(zk.exists?("/test_pool")).to be(true)
end
end
describe :method_missing do
it %[should allow you to execute commands on the connection pool itself] do
@connection_pool.create('/test_pool', '', :mode => :persistent)
wait_until(2) { @connection_pool.exists?('/test_pool') }
- @connection_pool.exists?('/test_pool').should be_true
+ expect(@connection_pool.exists?('/test_pool')).to be(true)
end
end
describe :close_all! do
it %[should shutdown gracefully] do
- release_q = Queue.new
-
latch = Latch.new
@about_to_block = false
@mutex = Mutex.new
@@ -74,34 +72,34 @@
@mutex.synchronize do
@cond.wait(@mutex) while @cnx.nil?
end
- @cnx.should_not be_nil
+ expect(@cnx).not_to be_nil
closing_th = Thread.new do
@connection_pool.close_all!
end
wait_until(5) { @connection_pool.closing? }
- @connection_pool.should be_closing
+ expect(@connection_pool).to be_closing
logger.debug { "connection pool is closing" }
- lambda { @connection_pool.with_connection { |c| c } }.should raise_error(ZK::Exceptions::PoolIsShuttingDownException)
+ expect { @connection_pool.with_connection { |c| c } }.to raise_error(ZK::Exceptions::PoolIsShuttingDownException)
latch.release
- open_th.join(5).should == open_th
+ expect(open_th.join(5)).to eq(open_th)
@connection_pool.wait_until_closed
- @connection_pool.should be_closed
+ expect(@connection_pool).to be_closed
- lambda do
- closing_th.join(1).should == closing_th
- open_th.join(1).should == open_th
- end.should_not raise_error
+ expect do
+ expect(closing_th.join(1)).to eq(closing_th)
+ expect(open_th.join(1)).to eq(open_th)
+ end.not_to raise_error
end
end
describe :force_close! do
it %[should raise PoolIsShuttingDownException in a thread blocked waiting for a connection], :mri_187 => :broken do
@@ -109,12 +107,12 @@
until @connection_pool.available_size <= 0
@cnx << @connection_pool.checkout
end
- @cnx.length.should_not be_zero
-
+ expect(@cnx.length).not_to be_zero
+
# this exc nonsense is because 1.8.7's scheduler is broken
@exc = nil
th = Thread.new do
begin
@@ -129,88 +127,84 @@
@connection_pool.force_close!
@connection_pool.wait_until_closed
- th.join(5).should == th
- @exc.should be_kind_of(ZK::Exceptions::PoolIsShuttingDownException)
+ expect(th.join(5)).to eq(th)
+ expect(@exc).to be_kind_of(ZK::Exceptions::PoolIsShuttingDownException)
end
end
it "should allow watchers still" do
@callback_called = false
@path = '/_testWatch'
@connection_pool.with_connection do |zk|
begin
- zk.delete(@path)
+ zk.delete(@path)
rescue ZK::Exceptions::NoNode
end
end
@connection_pool.with_connection do |zk|
zk.watcher.register(@path) do |event|
@callback_called = true
- event.path.should == @path
+ expect(event.path).to eq(@path)
end
- zk.exists?(@path, :watch => true).should be_false
+ expect(zk.exists?(@path, :watch => true)).to be(false)
end
@connection_pool.with_connection do |zk|
- zk.create(@path, "", :mode => :ephemeral).should == @path
+ expect(zk.create(@path, "", :mode => :ephemeral)).to eq(@path)
end
wait_until(1) { @callback_called }
- @callback_called.should be_true
+ expect(@callback_called).to be(true)
end
# These tests are seriously yucky, but they show that when a client is !connected?
# the pool behaves properly and will not return that client to the caller.
-
+
describe 'health checking with disconnected client', :rbx => :broken do
before do
wait_until(2) { @connection_pool.available_size == 2 }
- @connection_pool.available_size.should == 2
+ expect(@connection_pool.available_size).to eq(2)
@connections = @connection_pool.connections
- @connections.length.should == 2
+ expect(@connections.length).to eq(2)
@cnx1 = @connections.shift
- mock_sub = flexmock(:subscription)
+ mock_sub = double(:subscription)
- @mcnx1 = flexmock(@cnx1) do |m|
- m.should_receive(:connected?).at_least.once.and_return(false)
- m.should_receive(:on_connected).with(Proc).at_least.once.and_return(mock_sub)
- end
+ expect(@cnx1).to receive(:connected?).at_least(1).and_return(false)
+ expect(@cnx1).to receive(:on_connected).at_least(1).and_yield.and_return(mock_sub)
- @connections.unshift(@mcnx1)
+ @connections.unshift(@cnx1)
end
after do
- @connections.delete(@mcnx1)
- @connections.unshift(@cnx1)
[@cnx1, @cnx2].each { |c| @connection_pool.checkin(c) }
end
it %[should remove the disconnected client from the pool] do
- @connection_pool.available_size.should == 2
+ expect(@connection_pool.available_size).to eq(2)
@cnx2 = @connection_pool.checkout
-
+
# this is gross and relies on knowing internal state
- @connection_pool.checkout(false).should be_false
+ expect(@connection_pool.checkout(false)).to be(false)
- @cnx2.should_not be_nil
- @cnx2.should_not == @mcnx1
+ expect(@cnx2).not_to be_nil
+ expect(@cnx2).not_to eq(@cnx1)
- @connection_pool.available_size.should == 0
- @connections.should include(@mcnx1)
+ expect(@connection_pool.available_size).to eq(0)
+ expect(@connections).to include(@cnx1)
end
end
end # Simple
describe :Bounded do
@@ -219,22 +213,22 @@
before do
@min_clients = 1
@max_clients = 2
@timeout = 10
@connection_pool = ZK::Pool::Bounded.new(connection_host, :min_clients => @min_clients, :max_clients => @max_clients, :timeout => @timeout)
- @connection_pool.should be_open
+ expect(@connection_pool).to be_open
wait_until(2) { @connection_pool.available_size > 0 }
end
after do
@connection_pool.force_close! unless @connection_pool.closed?
- @connection_pool.should be_closed
+ expect(@connection_pool).to be_closed
end
describe 'initial state' do
it %[should have initialized the minimum number of clients] do
- @connection_pool.size.should == @min_clients
+ expect(@connection_pool.size).to eq(@min_clients)
end
end
describe 'should grow to max_clients' do
# before do
@@ -246,45 +240,42 @@
# Tracer.off
# end
it %[should grow if it can] do
wait_until(2) { @connection_pool.available_size > 0 }
- @connection_pool.available_size.should > 0
+ expect(@connection_pool.available_size > 0).to be(true)
- @connection_pool.size.should == 1
+ expect(@connection_pool.size).to eq(1)
logger.debug { "checking out @cnx1" }
@cnx1 = @connection_pool.checkout
- @cnx1.should_not be_false
+ expect(@cnx1).not_to be(false)
- @connection_pool.can_grow_pool?.should be_true
+ expect(@connection_pool.can_grow_pool?).to be(true)
logger.debug { "checking out @cnx2" }
@cnx2 = @connection_pool.checkout
- @cnx2.should_not be_false
- @cnx2.should be_connected
+ expect(@cnx2).not_to be(false)
+ expect(@cnx2).to be_connected
- @cnx1.object_id.should_not == @cnx2.object_id
+ expect(@cnx1.object_id).not_to eq(@cnx2.object_id)
[@cnx1, @cnx2].each { |c| @connection_pool.checkin(c) }
end
it %[should not grow past max_clients and block] do
- win_q = Queue.new
lose_q = Queue.new
- threads = []
-
@cnx1 = @connection_pool.checkout
- @cnx1.should_not be_false
+ expect(@cnx1).not_to be(false)
- @connection_pool.can_grow_pool?.should be_true
+ expect(@connection_pool.can_grow_pool?).to be(true)
@cnx2 = @connection_pool.checkout
- @cnx2.should_not be_false
+ expect(@cnx2).not_to be(false)
- @connection_pool.can_grow_pool?.should be_false
+ expect(@connection_pool.can_grow_pool?).to be(false)
logger.debug { "spawning losing thread" }
loser = Thread.new do
@connection_pool.with_connection do |cnx|
@@ -297,25 +288,25 @@
# loser.join_until(5) { @connection_pool.count_waiters > 0 }
# logger.debug { "count waiters: #{@connection_pool.count_waiters}" }
# @connection_pool.count_waiters.should == 1
- loser[:cnx].should be_nil
+ expect(loser[:cnx]).to be_nil
[@cnx1, @cnx2].each { |c| @connection_pool.checkin(c) }
loser.join_until(2) { loser[:cnx] }
- loser[:cnx].should_not be_nil
+ expect(loser[:cnx]).not_to be_nil
lose_q.enq(:release)
- lambda { loser.join(2).should == loser }.should_not raise_error
+ expect { expect(loser.join(2)).to eq(loser) }.not_to raise_error
logger.debug { "joined losing thread" }
- @connection_pool.count_waiters.should be_zero
- @connection_pool.available_size.should == 2
- @connection_pool.size.should == 2
+ expect(@connection_pool.count_waiters).to be_zero
+ expect(@connection_pool.available_size).to eq(2)
+ expect(@connection_pool.size).to eq(2)
end
end # should grow to max_clients
end
end