Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support Faraday persistent connection closing #793

Merged
merged 3 commits into from
Feb 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/vcr/middleware/faraday.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ def call(env)
RequestHandler.new(@app, env).handle
end

# Close any persistent connections.
def close
@app.close if @app.respond_to?(:close)
end

# @private
class RequestHandler < ::VCR::RequestHandler
attr_reader :app, :env
Expand Down
21 changes: 21 additions & 0 deletions spec/lib/vcr/middleware/faraday_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,25 @@ def make_request(disabled = false)
end
end
end if defined?(::Typhoeus)

describe '#close' do
let(:faraday_app) { double }

def close
described_class.new(faraday_app).close
end

context 'when adapter supports persistent connections' do
it 'calls adapter close method' do
expect(faraday_app).to receive(:close)
close
end
end

context 'when adapter does not support persistent connections' do
it 'does not raise error' do
expect { close }.not_to raise_error
end
end
end
end