diff --git a/lib/net/http/persistent/pool.rb b/lib/net/http/persistent/pool.rb index 220c70e..db63822 100644 --- a/lib/net/http/persistent/pool.rb +++ b/lib/net/http/persistent/pool.rb @@ -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}" diff --git a/lib/net/http/persistent/timed_stack_multi.rb b/lib/net/http/persistent/timed_stack_multi.rb index 9924a0a..ac7fdf8 100644 --- a/lib/net/http/persistent/timed_stack_multi.rb +++ b/lib/net/http/persistent/timed_stack_multi.rb @@ -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 # @@ -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 diff --git a/net-http-persistent.gemspec b/net-http-persistent.gemspec index 58ac1db..1c6b794 100644 --- a/net-http-persistent.gemspec +++ b/net-http-persistent.gemspec @@ -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.freeze, ["~> 2.2", ">= 2.2.4"]) + s.add_runtime_dependency(%q.freeze, [">= 2.2.4", "< 4"]) s.add_runtime_dependency(%q.freeze, "~> 0.5.1") end diff --git a/test/test_net_http_persistent_timed_stack_multi.rb b/test/test_net_http_persistent_timed_stack_multi.rb index 38e191c..9288f92 100644 --- a/test/test_net_http_persistent_timed_stack_multi.rb +++ b/test/test_net_http_persistent_timed_stack_multi.rb @@ -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 @@ -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 @@ -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 @@ -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 = []