Skip to content

Commit 5cb828f

Browse files
kpumukJens-G
authored andcommitted
Rack response needs to be finished when returned from the Rack application
This merge request addresses the following test failures: ``` 1) Thrift::ThinHTTPServer::RackApplication 404 response receives a non-POST Failure/Error: expect(last_response.status).to be 404 expected #<Integer:809> => 404 got #<Integer:1001> => 500 Compared using equal?, which compares object identity, but expected and actual are not the same object. Use `expect(actual).to eq(expected)` if you don't care about object identity in this example. # ./spec/thin_http_server_spec.rb:102:in 'block (3 levels) in <top (required)>' 2) Thrift::ThinHTTPServer::RackApplication 404 response receives a header other than application/x-thrift Failure/Error: expect(last_response.status).to be 404 expected #<Integer:809> => 404 got #<Integer:1001> => 500 Compared using equal?, which compares object identity, but expected and actual are not the same object. Use `expect(actual).to eq(expected)` if you don't care about object identity in this example. # ./spec/thin_http_server_spec.rb:108:in 'block (3 levels) in <top (required)>' 3) Thrift::ThinHTTPServer::RackApplication 200 response status code 200 Failure/Error: expect(last_response.ok?).to be_truthy expected: truthy value got: false # ./spec/thin_http_server_spec.rb:135:in 'block (3 levels) in <top (required)>' ``` From the [Rack documentation](https://rack.github.io/rack/2.2/Rack/Response.html), > Your application’s call should end returning [Response#finish](https://rack.github.io/rack/2.2/Rack/Response.html#method-i-finish). Additionally: * using identity checks on integers produces weird expectation "expected #<Integer:809> => 404", which is not necessary. Switched to using `eq` matcher * `be_truthy` matcher is overly generic and identity matching on `true`/`false` is preferred: "expected true" output will be displayed on failure
1 parent 5c2183d commit 5cb828f

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

lib/rb/lib/thrift/server/thin_http_server.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ def self.for(path, processor, protocol_factory)
6060
run lambda { |env|
6161
request = Rack::Request.new(env)
6262
if RackApplication.valid_thrift_request?(request)
63-
RackApplication.successful_request(request, processor, protocol_factory)
63+
RackApplication.successful_request(request, processor, protocol_factory).finish
6464
else
65-
RackApplication.failed_request
65+
RackApplication.failed_request.finish
6666
end
6767
}
6868
end

lib/rb/spec/thin_http_server_spec.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,13 @@ def app
9999
it 'receives a non-POST' do
100100
header('Content-Type', "application/x-thrift")
101101
get "/"
102-
expect(last_response.status).to be 404
102+
expect(last_response.status).to eq 404
103103
end
104104

105105
it 'receives a header other than application/x-thrift' do
106106
header('Content-Type', "application/json")
107107
post "/"
108-
expect(last_response.status).to be 404
108+
expect(last_response.status).to eq 404
109109
end
110110

111111
end
@@ -132,10 +132,9 @@ def app
132132
it 'status code 200' do
133133
header('Content-Type', "application/x-thrift")
134134
post "/"
135-
expect(last_response.ok?).to be_truthy
135+
expect(last_response.ok?).to be true
136136
end
137137

138138
end
139139

140140
end
141-

0 commit comments

Comments
 (0)