Skip to content

Commit

Permalink
Merge pull request #401 from spikex/max_retries
Browse files Browse the repository at this point in the history
Allow overriding Net::HTTP max_retries
  • Loading branch information
bobbrodie authored Apr 27, 2024
2 parents af3f3a4 + 69c41de commit c6e31d2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/jira/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ module JIRA
# :default_headers => {},
# :use_client_cert => false,
# :read_timeout => nil,
# :max_retries => nil,
# :http_debug => false,
# :shared_secret => nil,
# :cert_path => nil,
Expand Down Expand Up @@ -86,6 +87,7 @@ class Client
:default_headers,
:use_client_cert,
:read_timeout,
:max_retries,
:http_debug,
:issuer,
:base_url,
Expand Down
1 change: 1 addition & 0 deletions lib/jira/http_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def http_conn(uri)
http_conn.verify_mode = @options[:ssl_verify_mode]
http_conn.ssl_version = @options[:ssl_version] if @options[:ssl_version]
http_conn.read_timeout = @options[:read_timeout]
http_conn.max_retries = @options[:max_retries] if @options[:max_retries]
http_conn.ca_file = @options[:ca_file] if @options[:ca_file]
http_conn
end
Expand Down
22 changes: 22 additions & 0 deletions spec/jira/http_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@
JIRA::HttpClient.new(options)
end

let(:basic_client_with_max_retries) do
options = JIRA::Client::DEFAULT_OPTIONS.merge(JIRA::HttpClient::DEFAULT_OPTIONS).merge(
max_retries: 2
)
JIRA::HttpClient.new(options)
end

let(:response) do
response = double('response')
allow(response).to receive(:kind_of?).with(Net::HTTPSuccess).and_return(true)
Expand Down Expand Up @@ -331,6 +338,21 @@
expect(client.http_conn(client.uri).ca_file).to eql('/opt/custom.ca.pem')
end

it 'allows overriding max_retries' do
http_conn = double
uri = double
host = double
port = double
expect(uri).to receive(:host).and_return(host)
expect(uri).to receive(:port).and_return(port)
expect(Net::HTTP).to receive(:new).with(host, port).and_return(http_conn)
expect(http_conn).to receive(:use_ssl=).with(basic_client.options[:use_ssl]).and_return(http_conn)
expect(http_conn).to receive(:verify_mode=).with(basic_client.options[:ssl_verify_mode]).and_return(http_conn)
expect(http_conn).to receive(:read_timeout=).with(basic_client.options[:read_timeout]).and_return(http_conn)
expect(http_conn).to receive(:max_retries=).with(basic_client_with_max_retries.options[:max_retries]).and_return(http_conn)
expect(basic_client_with_max_retries.http_conn(uri)).to eq(http_conn)
end

it 'returns a http connection' do
http_conn = double
uri = double
Expand Down

0 comments on commit c6e31d2

Please sign in to comment.