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

87 lines
1.3 KiB
Ruby
Raw Normal View History

2014-02-06 21:05:45 -05:00
Thread.abort_on_exception = true
require 'helper'
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
assert_empty @stack
@stack.push Object.new
refute_empty @stack
end
2014-02-06 21:10:58 -05:00
def test_length
assert_equal 0, @stack.length
@stack.push Object.new
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 0.0000001
end
assert_match %r%Waited [\de.-]+ sec%, e.message
end
2014-02-06 21:21:28 -05:00
def test_pop_shutdown
@stack.shutdown do end
assert_raises ConnectionPool::PoolShuttingDownError do
@stack.pop
end
end
2014-02-06 21:09:45 -05:00
def test_push
assert_empty @stack
@stack.push Object.new
refute_empty @stack
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