Skip to content

Commit 0a5bea8

Browse files
authored
Merge pull request #140 from casperisfine/reload-pool
Expose `ConnectionPool#reload`
2 parents fad1632 + 0428107 commit 0a5bea8

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

lib/net/http/persistent.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,8 @@ def request_setup req_or_uri # :nodoc:
996996
end
997997

998998
##
999-
# Shuts down all connections
999+
# Shuts down all connections. Attempting to checkout a connection after
1000+
# shutdown will raise an error.
10001001
#
10011002
# *NOTE*: Calling shutdown for can be dangerous!
10021003
#
@@ -1007,6 +1008,17 @@ def shutdown
10071008
@pool.shutdown { |http| http.finish }
10081009
end
10091010

1011+
##
1012+
# Discard all existing connections. Subsequent checkouts will create
1013+
# new connections as needed.
1014+
#
1015+
# If any thread is still using a connection it may cause an error! Call
1016+
# #reload when you are completely done making requests!
1017+
1018+
def reload
1019+
@pool.reload { |http| http.finish }
1020+
end
1021+
10101022
##
10111023
# Enables SSL on +connection+
10121024

net-http-persistent.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ 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"])
20+
s.add_runtime_dependency(%q<connection_pool>.freeze, ["~> 2.2", ">= 2.2.4"])
2121
end
2222

test/test_net_http_persistent.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,6 +1255,17 @@ def test_shutdown
12551255
refute c2.http.finished?, 'present generation connection must not be finished'
12561256
end
12571257

1258+
def test_reload
1259+
c = connection
1260+
1261+
@http.reload
1262+
1263+
c2 = connection
1264+
1265+
assert c.http.finished?, 'last-generation connection must be finished'
1266+
refute c2.http.finished?, 'present generation connection must not be finished'
1267+
end
1268+
12581269
def test_ssl
12591270
skip 'OpenSSL is missing' unless HAVE_OPENSSL
12601271

test/test_net_http_persistent_timed_stack_multi.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def test_pop_empty
6262
@stack.pop timeout: 0
6363
end
6464

65-
assert_match 'Waited 0 sec', e.message
65+
assert_includes e.message, 'Waited 0 sec'
6666
end
6767

6868
def test_pop_full

0 commit comments

Comments
 (0)