mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-09-01 00:00:35 -04:00
rubocopping
This commit is contained in:
parent
3d305285d5
commit
0a846f05f3
@ -4,7 +4,7 @@ module HTTPX
|
||||
module Plugins
|
||||
module Retries
|
||||
MAX_RETRIES = 3
|
||||
IDEMPOTENT_METHODS = [:get, :options, :head, :put, :delete]
|
||||
IDEMPOTENT_METHODS = %i[get options head put delete].freeze
|
||||
|
||||
module InstanceMethods
|
||||
def max_retries(n)
|
||||
@ -16,8 +16,8 @@ module HTTPX
|
||||
def fetch_response(request)
|
||||
response = super
|
||||
if response.is_a?(ErrorResponse) &&
|
||||
request.retries > 0 &&
|
||||
IDEMPOTENT_METHODS.include?(request.verb)
|
||||
request.retries.positive? &&
|
||||
IDEMPOTENT_METHODS.include?(request.verb)
|
||||
request.retries -= 1
|
||||
channel = find_channel(request)
|
||||
channel.send(request)
|
||||
@ -29,7 +29,7 @@ module HTTPX
|
||||
|
||||
module RequestMethods
|
||||
attr_accessor :retries
|
||||
|
||||
|
||||
def initialize(*args)
|
||||
super
|
||||
@retries = @options.max_retries || MAX_RETRIES
|
||||
@ -47,6 +47,6 @@ module HTTPX
|
||||
end
|
||||
end
|
||||
end
|
||||
register_plugin :retries, Retries
|
||||
register_plugin :retries, Retries
|
||||
end
|
||||
end
|
||||
|
@ -8,27 +8,27 @@ module Requests
|
||||
no_retries_response = no_retries_client.get(build_uri("/delay/10"))
|
||||
assert no_retries_response.is_a?(HTTPX::ErrorResponse)
|
||||
assert no_retries_client.calls == 1, "expect request to be built 1 times (was #{no_retries_client.calls})"
|
||||
retries_client = HTTPX.
|
||||
plugin(RequestInspector).
|
||||
plugin(:retries).
|
||||
timeout(total_timeout: 3)
|
||||
retries_client = HTTPX
|
||||
.plugin(RequestInspector)
|
||||
.plugin(:retries)
|
||||
.timeout(total_timeout: 3)
|
||||
retries_response = retries_client.get(build_uri("/delay/10"))
|
||||
assert retries_response.is_a?(HTTPX::ErrorResponse)
|
||||
# we're comparing against max-retries + 1, because the calls increment will happen
|
||||
# also in the last call, where the request is not going to be retried.
|
||||
# also in the last call, where the request is not going to be retried.
|
||||
assert retries_client.calls == 4, "expect request to be built 4 times (was #{retries_client.calls})"
|
||||
end
|
||||
|
||||
def test_plugin_retries_max_retries
|
||||
retries_client = HTTPX.
|
||||
plugin(RequestInspector).
|
||||
plugin(:retries).
|
||||
timeout(total_timeout: 3).
|
||||
max_retries(2)
|
||||
retries_client = HTTPX
|
||||
.plugin(RequestInspector)
|
||||
.plugin(:retries)
|
||||
.timeout(total_timeout: 3)
|
||||
.max_retries(2)
|
||||
retries_response = retries_client.get(build_uri("/delay/10"))
|
||||
assert retries_response.is_a?(HTTPX::ErrorResponse)
|
||||
# we're comparing against max-retries + 1, because the calls increment will happen
|
||||
# also in the last call, where the request is not going to be retried.
|
||||
# also in the last call, where the request is not going to be retried.
|
||||
assert retries_client.calls == 3, "expect request to be built 3 times (was #{retries_client.calls})"
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user