mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-08-13 00:02:57 -04:00
moved timeout tests to the session, as they are not supposed to be differentiated in http/https terms
This commit is contained in:
parent
b96eb526a3
commit
066ff44762
@ -13,7 +13,6 @@ class HTTPTest < Minitest::Test
|
||||
include Headers
|
||||
include ResponseBody
|
||||
include IO
|
||||
include Timeouts
|
||||
include Errors
|
||||
include AltSvc if ENV.key?("HTTPBIN_ALTSVC_HOST")
|
||||
|
||||
|
@ -11,7 +11,6 @@ class HTTPSTest < Minitest::Test
|
||||
include Headers
|
||||
include ResponseBody
|
||||
include IO
|
||||
include Timeouts
|
||||
include Errors
|
||||
include Resolvers if ENV.key?("HTTPX_RESOLVER_URI")
|
||||
# TODO: uncomment as soon as nghttpx supports altsvc for HTTP/2
|
||||
|
@ -4,6 +4,7 @@ require_relative "test_helper"
|
||||
|
||||
class SessionTest < Minitest::Test
|
||||
include HTTPX
|
||||
include HTTPHelpers
|
||||
|
||||
def test_session_block
|
||||
yielded = nil
|
||||
@ -48,6 +49,31 @@ class SessionTest < Minitest::Test
|
||||
assert body.foo == "response-body-foo", "response body method is unexpected"
|
||||
end
|
||||
|
||||
def test_session_timeouts_total_timeout
|
||||
uri = build_uri("/delay/3")
|
||||
session = HTTPX.timeout(operation_timeout: 1, 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"
|
||||
end
|
||||
|
||||
def test_session_timeout_connect_timeout
|
||||
uri = build_uri("/", origin("127.0.0.1:9090"))
|
||||
session = HTTPX.timeout(connect_timeout: 0.5, operation_timeout: 30, total_timeout: 2)
|
||||
response = session.get(uri)
|
||||
assert response.is_a?(HTTPX::ErrorResponse), "response should have failed (#{response.class})"
|
||||
assert response.error.is_a?(HTTPX::ConnectTimeoutError),
|
||||
"response should have failed on connection (#{response.error.class}: #{response.error})"
|
||||
end
|
||||
|
||||
# def test_http_timeouts_operation_timeout
|
||||
# uri = build_uri("/delay/2")
|
||||
# session = HTTPX.timeout(operation_timeout: 1)
|
||||
# response = session.get(uri)
|
||||
# assert response.is_a?(HTTPX::ErrorResponse), "response should have failed"
|
||||
# assert response.error =~ /timed out while waiting/, "response should have timed out"
|
||||
# end
|
||||
|
||||
TestPlugin = Module.new do
|
||||
self::ClassMethods = Module.new do
|
||||
def foo
|
||||
@ -138,4 +164,10 @@ class SessionTest < Minitest::Test
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def origin(orig = httpbin)
|
||||
"https://#{orig}"
|
||||
end
|
||||
end
|
||||
|
@ -1,30 +0,0 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Requests
|
||||
module Timeouts
|
||||
# def test_http_timeouts_operation_timeout
|
||||
# uri = build_uri("/delay/2")
|
||||
# session = HTTPX.timeout(operation_timeout: 1)
|
||||
# response = session.get(uri)
|
||||
# assert response.is_a?(HTTPX::ErrorResponse), "response should have failed"
|
||||
# assert response.error =~ /timed out while waiting/, "response should have timed out"
|
||||
# end
|
||||
|
||||
def test_http_timeouts_total_timeout
|
||||
uri = build_uri("/delay/3")
|
||||
session = HTTPX.timeout(operation_timeout: 1, 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"
|
||||
end
|
||||
|
||||
def test_http_timeout_connect_timeout
|
||||
uri = build_uri("/", origin("127.0.0.1:9090"))
|
||||
session = HTTPX.timeout(connect_timeout: 0.5, operation_timeout: 30, total_timeout: 2)
|
||||
response = session.get(uri)
|
||||
assert response.is_a?(HTTPX::ErrorResponse), "response should have failed (#{response.class})"
|
||||
assert response.error.is_a?(HTTPX::ConnectTimeoutError),
|
||||
"response should have failed on connection (#{response.error.class}: #{response.error})"
|
||||
end
|
||||
end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user