Skip to content

Commit 260647b

Browse files
authored
Merge pull request #163 from jukra/connection_pool_3
Add support for connection_pool >= 3.0
2 parents a51e58f + 338622f commit 260647b

4 files changed

Lines changed: 19 additions & 8 deletions

File tree

lib/net/http/persistent/pool.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ class Net::HTTP::Persistent::Pool < ConnectionPool # :nodoc:
44
attr_reader :key # :nodoc:
55

66
def initialize(options = {}, &block)
7-
super
7+
super(**options, &block)
88

99
@available = Net::HTTP::Persistent::TimedStackMulti.new(@size, &block)
1010
@key = "current-#{@available.object_id}"

lib/net/http/persistent/timed_stack_multi.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
class Net::HTTP::Persistent::TimedStackMulti < ConnectionPool::TimedStack # :nodoc:
22

3+
##
4+
# Detects if ConnectionPool 3.0+ is being used (needed for TimedStack subclass compatibility)
5+
6+
CP_USES_KEYWORD_ARGS = Gem::Version.new(ConnectionPool::VERSION) >= Gem::Version.new('3.0.0') # :nodoc:
7+
38
##
49
# Returns a new hash that has arrays for keys
510
#
@@ -11,7 +16,11 @@ def self.hash_of_arrays # :nodoc:
1116
end
1217

1318
def initialize(size = 0, &block)
14-
super
19+
if CP_USES_KEYWORD_ARGS
20+
super(size: size, &block)
21+
else
22+
super(size, &block)
23+
end
1524

1625
@enqueued = 0
1726
@ques = self.class.hash_of_arrays

net-http-persistent.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
1717
s.required_ruby_version = ">= 2.4".freeze
1818
s.summary = "Manages persistent connections using Net::HTTP including a thread pool for connecting to multiple hosts".freeze
1919

20-
s.add_runtime_dependency(%q<connection_pool>.freeze, ["~> 2.2", ">= 2.2.4"])
20+
s.add_runtime_dependency(%q<connection_pool>.freeze, [">= 2.2.4", "< 4"])
2121
s.add_runtime_dependency(%q<cgi>.freeze, "~> 0.5.1")
2222
end
2323

test/test_net_http_persistent_timed_stack_multi.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def test_empty_eh
2929

3030
assert_empty stack
3131

32-
stack.push connection_args: popped
32+
stack.push popped, connection_args: 'default'
3333

3434
refute_empty stack
3535
end
@@ -43,7 +43,7 @@ def test_length
4343

4444
assert_equal 0, stack.length
4545

46-
stack.push connection_args: popped
46+
stack.push popped, connection_args: 'default'
4747

4848
assert_equal 1, stack.length
4949
end
@@ -113,7 +113,7 @@ def test_push
113113

114114
conn = stack.pop
115115

116-
stack.push connection_args: conn
116+
stack.push conn, connection_args: 'default'
117117

118118
refute_empty stack
119119
end
@@ -125,14 +125,16 @@ def test_push_shutdown
125125
called << object
126126
end
127127

128-
@stack.push connection_args: Object.new
128+
obj = Object.new
129+
@stack.push obj, connection_args: 'default'
129130

130131
refute_empty called
131132
assert_empty @stack
132133
end
133134

134135
def test_shutdown
135-
@stack.push connection_args: Object.new
136+
obj = Object.new
137+
@stack.push obj, connection_args: 'default'
136138

137139
called = []
138140

0 commit comments

Comments
 (0)