Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fixed a Rack::Lock bug around failing to close the response body #152

Merged
merged 1 commit into from

2 participants

Tammer Saleh Bartosz Blimke
Tammer Saleh

Looks like my last patch (#150) introduced a bug where the Rack::Lock mutex wasn't being released. We believe this is fixed in Rack 1.4.1, but as Rails 3.1 is still on Rack 1.3.x, we figured we should handle it here as well.

Bartosz Blimke bblimke merged commit 265b249 into from
Bartosz Blimke
Owner

Thank you. It will go in Webmock 1.8.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 23, 2012
This page is out of date. Refresh to see the latest.
1  lib/webmock/rack_response.rb
View
@@ -19,6 +19,7 @@ def evaluate(request)
def body_from_rack_response(response)
body = ""
response.each { |line| body << line }
+ response.close if response.respond_to?(:close)
return body
end
11 spec/support/my_rack_app.rb
View
@@ -21,6 +21,8 @@ def self.call(env)
[200, {}, ["Hello, #{name}"]]
when ['GET', '/non_array_response']
[200, {}, NonArrayResponse.new]
+ when ['GET', '/locked']
+ [200, {}, ["Single threaded response."]]
when ['POST', '/greet']
name = env["rack.input"].read[/name=([^&]*)/, 1] || "World"
[200, {}, ["Good to meet you, #{name}!"]]
@@ -29,3 +31,12 @@ def self.call(env)
end
end
end
+
+class MyLockedRackApp
+ MUTEX = Mutex.new
+
+ def self.call(env)
+ lock = Rack::Lock.new(MyRackApp, MUTEX)
+ lock.call(env)
+ end
+end
10 spec/unit/rack_response_spec.rb
View
@@ -3,6 +3,7 @@
describe WebMock::RackResponse do
before :each do
@rack_response = WebMock::RackResponse.new(MyRackApp)
+ @locked_rack_response = WebMock::RackResponse.new(MyLockedRackApp)
end
it "should hook up to a rack appliance" do
@@ -21,6 +22,15 @@
response.body.should include('This is not in an array!')
end
+ it "should shouldn't blow up when hitting a locked resource twice" do
+ request = WebMock::RequestSignature.new(:get, 'www.example.com/locked')
+ response = @locked_rack_response.evaluate(request)
+ response2 = @locked_rack_response.evaluate(request)
+
+ response2.body.should include('Single threaded response.')
+ response2.status.first.should == 200
+ end
+
it "should send along params" do
request = WebMock::RequestSignature.new(:get, 'www.example.com/greet?name=Johnny')
Something went wrong with that request. Please try again.