Compare commits

..

No commits in common. "9a16831147676bfeb3aabe3cfc169a9cb99e8024" and "3ee9c81335b078d93df8a40e49040a445de6daf1" have entirely different histories.

3 changed files with 5 additions and 46 deletions

View File

@ -78,7 +78,8 @@ module Faraday
# @param type [Symbol] Describes which timeout setting to get: :read,
# :write, or :open.
# @param options [Hash] Hash containing Symbol keys like :timeout,
# :read_timeout, :write_timeout, or :open_timeout
# :read_timeout, :write_timeout, :open_timeout, or
# :timeout
#
# @return [Integer, nil] Timeout duration in seconds, or nil if no timeout
# has been set.

View File

@ -1,7 +1,5 @@
# frozen_string_literal: true
require 'timeout'
module Faraday
class Adapter
# @example
@ -279,22 +277,11 @@ module Faraday
end
block_arity = stub.block.arity
params = if block_arity >= 0
[env, meta].take(block_arity)
else
[env, meta]
end
timeout = request_timeout(:open, env[:request])
timeout ||= request_timeout(:read, env[:request])
status, headers, body =
if timeout
::Timeout.timeout(timeout, Faraday::TimeoutError) do
stub.block.call(*params)
end
if block_arity >= 0
stub.block.call(*[env, meta].take(block_arity))
else
stub.block.call(*params)
stub.block.call(env, meta)
end
# We need to explicitly pass `reason_phrase = nil` here to avoid keyword args conflicts.

View File

@ -410,33 +410,4 @@ RSpec.describe Faraday::Adapter::Test do
end
end
end
describe 'request timeout' do
subject(:request) do
connection.get('/sleep') do |req|
req.options.timeout = timeout
end
end
before do
stubs.get('/sleep') do
sleep(0.01)
[200, {}, '']
end
end
context 'when request is within timeout' do
let(:timeout) { 1 }
it { expect(request.status).to eq 200 }
end
context 'when request is too slow' do
let(:timeout) { 0.001 }
it 'raises an exception' do
expect { request }.to raise_error(Faraday::TimeoutError)
end
end
end
end