now that the timer interval is used in the selector, make sure that timeouts from selecting are properly reflected as total timeouts when they are

This commit is contained in:
HoneyryderChuck 2020-04-05 17:10:57 +01:00
parent 9d6f31d940
commit f6475009fe
3 changed files with 12 additions and 5 deletions

View File

@ -8,7 +8,7 @@ Metrics/PerceivedComplexity:
Max: 46
Metrics/ClassLength:
Max: 350
Max: 400
Metrics/ModuleLength:
Max: 325

View File

@ -432,12 +432,19 @@ module HTTPX
def handle_error(error)
if error.instance_of?(TimeoutError)
if @timeout
@timeout -= error.timeout
return unless @timeout <= 0
end
error = error.to_connection_error if connecting?
error = if @total_timeout && @total_timeout.fires_in.negative?
ex = TotalTimeoutError.new(@total_timeout.interval, "Timed out after #{@total_timeout.interval} seconds")
ex.set_backtrace(error.backtrace)
ex
elsif connecting?
error.to_connection_error
end
end
parser.handle_error(error) if @parser && parser.respond_to?(:handle_error)
@ -454,8 +461,8 @@ module HTTPX
@total_timeout ||= @timers.after(total) do
ex = TotalTimeoutError.new(total, "Timed out after #{total} seconds")
ex.set_backtrace(caller)
@parser.close if @parser
on_error(ex)
@parser.close if @parser
end
end
end

View File

@ -51,10 +51,10 @@ class SessionTest < Minitest::Test
def test_session_timeouts_total_timeout
uri = build_uri("/delay/3")
session = HTTPX.with_timeout(operation_timeout: 1, total_timeout: 2)
session = HTTPX.with_timeout(total_timeout: 2)
response = session.get(uri)
assert response.is_a?(HTTPX::ErrorResponse), "response should have failed"
assert response.status =~ /timed out after \d+ seconds/i, "response should have timed out (instead, we got \"#{response.status}\")"
assert response.error.is_a?(HTTPX::TotalTimeoutError), "response should have timed out (instead, we got \"#{response.status}\")"
end
def test_session_timeout_connect_timeout