mirror of
https://github.com/jnunemaker/httparty
synced 2023-03-27 23:23:07 -04:00
Add max_retries support (#660)
* max_retries added to connection_adapter * unit tests for max_retries support
This commit is contained in:
parent
99751ac98a
commit
b9a54d8f73
2 changed files with 62 additions and 0 deletions
|
@ -137,6 +137,12 @@ module HTTParty
|
|||
end
|
||||
end
|
||||
|
||||
if add_max_retries?(options[:max_retries])
|
||||
from_ruby_version('2.5.0', option: :max_retries) do
|
||||
http.max_retries = options[:max_retries]
|
||||
end
|
||||
end
|
||||
|
||||
if options[:debug_output]
|
||||
http.set_debug_output(options[:debug_output])
|
||||
end
|
||||
|
@ -177,6 +183,10 @@ module HTTParty
|
|||
timeout && (timeout.is_a?(Integer) || timeout.is_a?(Float))
|
||||
end
|
||||
|
||||
def add_max_retries?(max_retries)
|
||||
max_retries && max_retries.is_a?(Integer) && max_retries >= 0
|
||||
end
|
||||
|
||||
def clean_host(host)
|
||||
strip_ipv6_brackets(host)
|
||||
end
|
||||
|
|
|
@ -399,6 +399,58 @@ RSpec.describe HTTParty::ConnectionAdapter do
|
|||
end
|
||||
end
|
||||
|
||||
context "when max_retries is not set" do
|
||||
it "doesn't set the max_retries" do
|
||||
http = double(
|
||||
"http",
|
||||
:null_object => true,
|
||||
:use_ssl= => false,
|
||||
:use_ssl? => false
|
||||
)
|
||||
expect(http).not_to receive(:max_retries=)
|
||||
allow(Net::HTTP).to receive_messages(new: http)
|
||||
|
||||
adapter.connection
|
||||
end
|
||||
end
|
||||
|
||||
context "when setting max_retries" do
|
||||
if RUBY_VERSION >= '2.5.0'
|
||||
context "to 5 times" do
|
||||
let(:options) { {max_retries: 5} }
|
||||
describe '#max_retries' do
|
||||
subject { super().max_retries }
|
||||
it { is_expected.to eq(5) }
|
||||
end
|
||||
end
|
||||
|
||||
context "to 0 times" do
|
||||
let(:options) { {max_retries: 0} }
|
||||
describe '#max_retries' do
|
||||
subject { super().max_retries }
|
||||
it { is_expected.to eq(0) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "and max_retries is a string" do
|
||||
let(:options) { {max_retries: "five times"} }
|
||||
|
||||
it "doesn't set the max_retries" do
|
||||
http = double(
|
||||
"http",
|
||||
:null_object => true,
|
||||
:use_ssl= => false,
|
||||
:use_ssl? => false
|
||||
)
|
||||
expect(http).not_to receive(:max_retries=)
|
||||
allow(Net::HTTP).to receive_messages(new: http)
|
||||
|
||||
adapter.connection
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "when debug_output" do
|
||||
let(:http) { Net::HTTP.new(uri) }
|
||||
before do
|
||||
|
|
Loading…
Add table
Reference in a new issue