1
0
Fork 0
mirror of https://github.com/mperham/connection_pool synced 2023-03-27 23:22:21 -04:00
connection_pool/test/test_connection_pool_timed_stack.rb

131 lines
2 KiB
Ruby
Raw Normal View History

2014-03-13 21:56:16 -04:00
require_relative 'helper'
2014-02-06 21:05:45 -05:00
class TestConnectionPoolTimedStack < Minitest::Test
def setup
@stack = ConnectionPool::TimedStack.new { Object.new }
end
2014-02-06 21:10:29 -05:00
def test_empty_eh
stack = ConnectionPool::TimedStack.new(1) { Object.new }
2014-02-06 21:10:29 -05:00
refute_empty stack
2014-02-06 21:10:29 -05:00
popped = stack.pop
2014-02-06 21:10:29 -05:00
assert_empty stack
stack.push popped
refute_empty stack
end
2014-02-06 21:10:58 -05:00
def test_length
stack = ConnectionPool::TimedStack.new(1) { Object.new }
2014-02-06 21:10:58 -05:00
assert_equal 1, stack.length
2014-02-06 21:10:58 -05:00
popped = stack.pop
2014-02-06 21:10:58 -05:00
assert_equal 0, stack.length
stack.push popped
assert_equal 1, stack.length
end
2014-02-06 21:07:58 -05:00
def test_pop
2014-02-06 21:20:23 -05:00
object = Object.new
@stack.push object
popped = @stack.pop
assert_same object, popped
end
def test_pop_empty
2014-02-06 21:07:58 -05:00
e = assert_raises Timeout::Error do
@stack.pop timeout: 0
2014-02-06 21:07:58 -05:00
end
2014-02-06 22:02:06 -05:00
assert_equal 'Waited 0 sec', e.message
2014-02-06 21:07:58 -05:00
end
def test_pop_empty_2_0_compatibility
e = assert_raises Timeout::Error do
@stack.pop 0
end
assert_equal 'Waited 0 sec', e.message
end
def test_pop_full
stack = ConnectionPool::TimedStack.new(1) { Object.new }
popped = stack.pop
refute_nil popped
assert_empty stack
end
def test_pop_wait
thread = Thread.start do
@stack.pop
end
Thread.pass while thread.status == 'run'
object = Object.new
@stack.push object
assert_same object, thread.value
end
2014-02-06 21:21:28 -05:00
def test_pop_shutdown
@stack.shutdown { }
2014-02-06 21:21:28 -05:00
assert_raises ConnectionPool::PoolShuttingDownError do
@stack.pop
end
end
2014-02-06 21:09:45 -05:00
def test_push
stack = ConnectionPool::TimedStack.new(1) { Object.new }
2014-02-06 21:09:45 -05:00
conn = stack.pop
2014-02-06 21:09:45 -05:00
stack.push conn
refute_empty stack
2014-02-06 21:09:45 -05:00
end
def test_push_shutdown
2014-02-06 21:16:25 -05:00
called = []
@stack.shutdown do |object|
called << object
end
@stack.push Object.new
2014-02-06 21:16:25 -05:00
refute_empty called
assert_empty @stack
end
2014-02-06 21:16:25 -05:00
def test_shutdown
2014-02-06 21:16:25 -05:00
@stack.push Object.new
called = []
@stack.shutdown do |object|
called << object
end
refute_empty called
2014-02-06 21:16:25 -05:00
assert_empty @stack
end
2014-02-06 21:05:45 -05:00
end