Skip to content

Commit 64851fe

Browse files
committed
Patch ConnectionPool to carry semian_resource
1 parent 15ea01c commit 64851fe

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

lib/semian/connection_pool.rb

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# frozen_string_literal: true
2+
3+
require "connection_pool"
4+
5+
# This is not a real Semian adapter, but a shim to make
6+
# ConnectionPool instance carry semian_resource reference.
7+
# Example:
8+
#
9+
# semian_resource = ::Redis.new(...).semian_resource
10+
# ConnectionPool.new(size: 5, timeout: 0, semian_resource: semian_resource) do
11+
# ::Redis.new(...)
12+
# end
13+
14+
class ConnectionPool
15+
module WithSemianResource
16+
def initialize(options = {}, &block)
17+
super
18+
@semian_resource = options[:semian_resource]
19+
end
20+
21+
attr_reader :semian_resource
22+
end
23+
end
24+
25+
ConnectionPool.prepend(ConnectionPool::WithSemianResource)

test/adapters/connection_pool_test.rb

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# frozen_string_literal: true
2+
3+
require "test_helper"
4+
require "semian/connection_pool"
5+
6+
class TestConnectionPool < Minitest::Test
7+
def test_with_semian_resource
8+
pool = ConnectionPool.new(
9+
size: 1,
10+
timeout: 0,
11+
semian_resource: Semian::Resource.new("blah"),
12+
) do
13+
Object.new
14+
end
15+
16+
refute_nil(pool.semian_resource)
17+
assert_equal("blah", pool.semian_resource.name)
18+
end
19+
end

0 commit comments

Comments
 (0)