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:
commit
337bb91529
2 changed files with 11 additions and 1 deletions
|
@ -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)
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue