Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/net/http/persistent/pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Net::HTTP::Persistent::Pool < ConnectionPool # :nodoc:
attr_reader :key # :nodoc:

def initialize(options = {}, &block)
super
super(**options, &block)

@available = Net::HTTP::Persistent::TimedStackMulti.new(@size, &block)
@key = "current-#{@available.object_id}"
Expand Down
11 changes: 10 additions & 1 deletion lib/net/http/persistent/timed_stack_multi.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
class Net::HTTP::Persistent::TimedStackMulti < ConnectionPool::TimedStack # :nodoc:

##
# Detects if ConnectionPool 3.0+ is being used (needed for TimedStack subclass compatibility)

CP_USES_KEYWORD_ARGS = Gem::Version.new(ConnectionPool::VERSION) >= Gem::Version.new('3.0.0') # :nodoc:

##
# Returns a new hash that has arrays for keys
#
Expand All @@ -11,7 +16,11 @@ def self.hash_of_arrays # :nodoc:
end

def initialize(size = 0, &block)
super
if CP_USES_KEYWORD_ARGS
super(size: size, &block)
else
super(size, &block)
end

@enqueued = 0
@ques = self.class.hash_of_arrays
Expand Down
2 changes: 1 addition & 1 deletion net-http-persistent.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Gem::Specification.new do |s|
s.required_ruby_version = ">= 2.4".freeze
s.summary = "Manages persistent connections using Net::HTTP including a thread pool for connecting to multiple hosts".freeze

s.add_runtime_dependency(%q<connection_pool>.freeze, ["~> 2.2", ">= 2.2.4"])
s.add_runtime_dependency(%q<connection_pool>.freeze, [">= 2.2.4", "< 4"])
s.add_runtime_dependency(%q<cgi>.freeze, "~> 0.5.1")
end

12 changes: 7 additions & 5 deletions test/test_net_http_persistent_timed_stack_multi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_empty_eh

assert_empty stack

stack.push connection_args: popped
stack.push popped, connection_args: 'default'

refute_empty stack
end
Expand All @@ -43,7 +43,7 @@ def test_length

assert_equal 0, stack.length

stack.push connection_args: popped
stack.push popped, connection_args: 'default'

assert_equal 1, stack.length
end
Expand Down Expand Up @@ -113,7 +113,7 @@ def test_push

conn = stack.pop

stack.push connection_args: conn
stack.push conn, connection_args: 'default'

refute_empty stack
end
Expand All @@ -125,14 +125,16 @@ def test_push_shutdown
called << object
end

@stack.push connection_args: Object.new
obj = Object.new
@stack.push obj, connection_args: 'default'

refute_empty called
assert_empty @stack
end

def test_shutdown
@stack.push connection_args: Object.new
obj = Object.new
@stack.push obj, connection_args: 'default'

called = []

Expand Down