mirror of
https://github.com/lostisland/faraday.git
synced 2025-08-29 00:03:58 -04:00
test patron and net/http timeouts
This commit is contained in:
parent
49e47274d5
commit
ed64a91de4
@ -72,6 +72,8 @@ module Faraday
|
||||
end
|
||||
|
||||
@app.call env
|
||||
rescue Timeout::Error => err
|
||||
raise Faraday::Error::TimeoutError, err
|
||||
end
|
||||
|
||||
def net_http_class(env)
|
||||
|
@ -26,6 +26,8 @@ module Faraday
|
||||
save_response(env, response.status, response.body, response.headers)
|
||||
|
||||
@app.call env
|
||||
rescue ::Patron::TimeoutError => err
|
||||
raise Faraday::Error::TimeoutError, err
|
||||
end
|
||||
|
||||
if loaded? && defined?(::Patron::Request::VALID_ACTIONS)
|
||||
|
@ -3,9 +3,9 @@ module Faraday
|
||||
class ClientError < StandardError
|
||||
attr_reader :response
|
||||
|
||||
def initialize(ex)
|
||||
def initialize(ex, response = nil)
|
||||
@wrapped_exception = nil
|
||||
@response = nil
|
||||
@response = response
|
||||
|
||||
if ex.respond_to?(:backtrace)
|
||||
super(ex.message)
|
||||
@ -34,7 +34,7 @@ module Faraday
|
||||
class ConnectionFailed < ClientError; end
|
||||
class ResourceNotFound < ClientError; end
|
||||
class ParsingError < ClientError; end
|
||||
|
||||
class TimeoutError < ClientError; end
|
||||
class MissingDependency < StandardError; end
|
||||
end
|
||||
end
|
||||
|
@ -173,9 +173,18 @@ else
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if %w[Faraday::Adapter::Patron Faraday::Adapter::NetHttp].include?(adapter.to_s)
|
||||
define_method "test_patron_timeout" do
|
||||
conn = create_connection(adapter, :request => {:timeout => 1, :read_timeout => 1})
|
||||
assert_raise Faraday::Error::TimeoutError do
|
||||
conn.get '/slow'
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def create_connection(adapter)
|
||||
def create_connection(adapter, options = {})
|
||||
if adapter == :default
|
||||
builder_block = nil
|
||||
else
|
||||
@ -186,7 +195,7 @@ else
|
||||
end
|
||||
end
|
||||
|
||||
Faraday::Connection.new(LIVE_SERVER, &builder_block).tap do |conn|
|
||||
Faraday::Connection.new(LIVE_SERVER, options, &builder_block).tap do |conn|
|
||||
conn.headers['X-Faraday-Adapter'] = adapter.to_s
|
||||
adapter_handler = conn.builder.handlers.last
|
||||
conn.builder.insert_before adapter_handler, Faraday::Response::RaiseError
|
||||
|
@ -43,3 +43,8 @@ end
|
||||
get '/multi' do
|
||||
[200, { 'Set-Cookie' => 'one, two' }, '']
|
||||
end
|
||||
|
||||
get '/slow' do
|
||||
sleep 10
|
||||
[200, {}, 'ok']
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user