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

Merge pull request #87 from etiennebarrie/wrapper-pool

Create wrapper with existing pool
This commit is contained in:
Mike Perham 2016-05-18 08:51:44 -07:00
commit 337bb91529
2 changed files with 11 additions and 1 deletions

View file

@ -124,7 +124,7 @@ end
METHODS = [:with, :pool_shutdown] METHODS = [:with, :pool_shutdown]
def initialize(options = {}, &block) def initialize(options = {}, &block)
@pool = ::ConnectionPool.new(options, &block) @pool = options.fetch(:pool) { ::ConnectionPool.new(options, &block) }
end end
def with(&block) def with(&block)

View file

@ -488,4 +488,14 @@ class TestConnectionPool < Minitest::Test
assert_equal "eval'ed 1", wrapper.eval(1) assert_equal "eval'ed 1", wrapper.eval(1)
end end
def test_wrapper_with_connection_pool
recorder = Recorder.new
pool = ConnectionPool.new(size: 1) { recorder }
wrapper = ConnectionPool::Wrapper.new(pool: pool)
pool.with { |r| r.do_work('with') }
wrapper.do_work('wrapped')
assert_equal ['with', 'wrapped'], recorder.calls
end
end end