mirror of
https://github.com/mperham/connection_pool
synced 2023-03-27 23:22:21 -04:00
Raise Error when there is nothing to checkin
Now an Error is raised regardless of prior #checkout (to create a stack of connections). This required updating Wrapper#with to not attempt to #checkin after a failed #checkout.
This commit is contained in:
parent
88bea998e3
commit
4607cb2eb6
2 changed files with 20 additions and 5 deletions
|
@ -77,7 +77,8 @@ class ConnectionPool
|
|||
|
||||
def checkin
|
||||
stack = ::Thread.current[@key]
|
||||
raise ConnectionPool::Error, 'no connections are checked out' unless stack
|
||||
raise ConnectionPool::Error, 'no connections are checked out' unless
|
||||
stack and not stack.empty?
|
||||
|
||||
conn = stack.pop
|
||||
if stack.empty?
|
||||
|
@ -98,9 +99,12 @@ class ConnectionPool
|
|||
end
|
||||
|
||||
def with
|
||||
yield @pool.checkout
|
||||
ensure
|
||||
@pool.checkin
|
||||
conn = @pool.checkout
|
||||
begin
|
||||
yield conn
|
||||
ensure
|
||||
@pool.checkin
|
||||
end
|
||||
end
|
||||
|
||||
def pool_shutdown(&block)
|
||||
|
|
|
@ -128,7 +128,7 @@ class TestConnectionPool < Minitest::Test
|
|||
assert_same conn, t2.value
|
||||
end
|
||||
|
||||
def test_checkin_no_checkout
|
||||
def test_checkin_never_checkout
|
||||
pool = ConnectionPool.new(:timeout => 0, :size => 1) { Object.new }
|
||||
|
||||
e = assert_raises ConnectionPool::Error do
|
||||
|
@ -138,6 +138,17 @@ class TestConnectionPool < Minitest::Test
|
|||
assert_equal 'no connections are checked out', e.message
|
||||
end
|
||||
|
||||
def test_checkin_no_current_checkout
|
||||
pool = ConnectionPool.new(:timeout => 0, :size => 1) { Object.new }
|
||||
|
||||
pool.checkout
|
||||
pool.checkin
|
||||
|
||||
assert_raises ConnectionPool::Error do
|
||||
pool.checkin
|
||||
end
|
||||
end
|
||||
|
||||
def test_checkin_twice
|
||||
pool = ConnectionPool.new(:timeout => 0, :size => 1) { Object.new }
|
||||
|
||||
|
|
Loading…
Reference in a new issue