Skip to content

Commit

Permalink
Merge pull request #140 from casperisfine/reload-pool
Browse files Browse the repository at this point in the history
Expose `ConnectionPool#reload`
  • Loading branch information
tenderlove authored Dec 4, 2024
2 parents fad1632 + 0428107 commit 0a5bea8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
14 changes: 13 additions & 1 deletion lib/net/http/persistent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,8 @@ def request_setup req_or_uri # :nodoc:
end

##
# Shuts down all connections
# Shuts down all connections. Attempting to checkout a connection after
# shutdown will raise an error.
#
# *NOTE*: Calling shutdown for can be dangerous!
#
Expand All @@ -1007,6 +1008,17 @@ def shutdown
@pool.shutdown { |http| http.finish }
end

##
# Discard all existing connections. Subsequent checkouts will create
# new connections as needed.
#
# If any thread is still using a connection it may cause an error! Call
# #reload when you are completely done making requests!

def reload
@pool.reload { |http| http.finish }
end

##
# Enables SSL on +connection+

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,6 +17,6 @@ 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"])
s.add_runtime_dependency(%q<connection_pool>.freeze, ["~> 2.2", ">= 2.2.4"])
end

11 changes: 11 additions & 0 deletions test/test_net_http_persistent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1255,6 +1255,17 @@ def test_shutdown
refute c2.http.finished?, 'present generation connection must not be finished'
end

def test_reload
c = connection

@http.reload

c2 = connection

assert c.http.finished?, 'last-generation connection must be finished'
refute c2.http.finished?, 'present generation connection must not be finished'
end

def test_ssl
skip 'OpenSSL is missing' unless HAVE_OPENSSL

Expand Down
2 changes: 1 addition & 1 deletion test/test_net_http_persistent_timed_stack_multi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def test_pop_empty
@stack.pop timeout: 0
end

assert_match 'Waited 0 sec', e.message
assert_includes e.message, 'Waited 0 sec'
end

def test_pop_full
Expand Down

0 comments on commit 0a5bea8

Please sign in to comment.