Browse files

Fix faraday middleware so that it plays back parallel requests properly.

  • Loading branch information...
1 parent a936557 commit 2098a952e00d8f11f9701d705608c913a24b9ac1 @myronmarston committed Mar 28, 2012
Showing with 24 additions and 3 deletions.
  1. +3 −0 CHANGELOG.md
  2. +1 −1 lib/vcr/middleware/faraday.rb
  3. +20 −2 spec/vcr/middleware/faraday_spec.rb
View
3 CHANGELOG.md
@@ -20,6 +20,9 @@
* Fix Excon adapter to fix a bug with Excon 0.11 and greater. When you
passed a block to an excon request, the response body would not be
recorded.
+* Fix Faraday middleware so that it plays back parallel requests
+ properly. Thanks to [Dave Weiser](https://github.com/davidann) for
+ reporting this bug.
## 2.0.0 (March 2, 2012)
View
2 lib/vcr/middleware/faraday.rb
@@ -83,7 +83,7 @@ def on_stubbed_request
env.update :status => stubbed_response.status.code, :body => stubbed_response.body
faraday_response = ::Faraday::Response.new
- faraday_response.finish(env) unless env[:parallel_manager]
+ faraday_response.finish(env)
env[:response] = faraday_response
end
View
22 spec/vcr/middleware/faraday_spec.rb
@@ -13,10 +13,28 @@
include VCRStubHelpers
let(:parallel_manager) { ::Faraday::Adapter::Typhoeus.setup_parallel_manager }
let(:connection) { ::Faraday.new { |b| b.adapter :typhoeus } }
+ let(:request_url) { "http://localhost:#{VCR::SinatraApp.port}/" }
- shared_examples_for "exclusive library hook" do
- let(:request_url) { "http://localhost:#{VCR::SinatraApp.port}/" }
+ it 'works correctly with multiple parallel requests' do
+ recorded, played_back = [1, 2].map do
+ responses = []
+
+ VCR.use_cassette("multiple_parallel") do
+ connection.in_parallel(parallel_manager) do
+ responses << connection.get(request_url)
+ responses << connection.get(request_url)
+ end
+ end
+
+ responses.map(&:body)
+ end
+
+ # there should be no blanks
+ recorded.select { |r| r.to_s == '' }.should eq([])
+ played_back.should eq(recorded)
+ end
+ shared_examples_for "exclusive library hook" do
def make_request
connection.in_parallel(parallel_manager) { connection.get(request_url) }
end

0 comments on commit 2098a95

Please sign in to comment.