mirror of
https://github.com/mperham/connection_pool
synced 2023-03-27 23:22:21 -04:00
Allow us to shutdown pool within a wrapper
This commit is contained in:
parent
27b00a74c2
commit
1e0d14ecd8
2 changed files with 17 additions and 6 deletions
|
@ -79,9 +79,7 @@ class ConnectionPool
|
|||
end
|
||||
|
||||
class Wrapper < ::BasicObject
|
||||
METHODS = [:with]
|
||||
|
||||
attr_reader :pool
|
||||
METHODS = [:with, :pool_shutdown]
|
||||
|
||||
def initialize(options = {}, &block)
|
||||
@pool = ::ConnectionPool.new(options, &block)
|
||||
|
@ -93,6 +91,10 @@ class ConnectionPool
|
|||
@pool.checkin
|
||||
end
|
||||
|
||||
def pool_shutdown(&block)
|
||||
@pool.shutdown(&block)
|
||||
end
|
||||
|
||||
def respond_to?(id, *args)
|
||||
METHODS.include?(id) || @pool.with { |c| c.respond_to?(id, *args) }
|
||||
end
|
||||
|
|
|
@ -200,8 +200,17 @@ class TestConnectionPool < Minitest::Test
|
|||
end
|
||||
end
|
||||
|
||||
def test_wrapper_provides_access_to_pool
|
||||
wrapper = ConnectionPool::Wrapper.new(:size => 1) { true }
|
||||
assert_equal ConnectionPool, wrapper.pool.class
|
||||
def test_shutdown_is_executed_for_all_connections_in_wrapped_pool
|
||||
recorders = []
|
||||
|
||||
wrapper = ConnectionPool::Wrapper.new(:size => 3) do
|
||||
Recorder.new.tap { |r| recorders << r }
|
||||
end
|
||||
|
||||
wrapper.pool_shutdown do |recorder|
|
||||
recorder.do_work("shutdown")
|
||||
end
|
||||
|
||||
assert_equal [["shutdown"]] * 3, recorders.map { |r| r.calls }
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue