mirror of https://github.com/rails/rails
Add Rack::Lint to ActionCable::Server health tests
This adds additional coverage to ActionCable::Server to validate that its output follow the Rack SPEC. In addition to using Rack::CONTENT_TYPE for the Content-Type header, there was another change required: the Content-Type header cannot be specified when the Response status is 204, so the default health check status was updated to 200
This commit is contained in:
parent
5cf742ef51
commit
c3c844ef3a
|
@ -235,7 +235,7 @@ module ActionCable
|
|||
|
||||
logger.error invalid_request_message
|
||||
logger.info finished_request_message
|
||||
[ 404, { "Content-Type" => "text/plain; charset=utf-8" }, [ "Page not found" ] ]
|
||||
[ 404, { Rack::CONTENT_TYPE => "text/plain; charset=utf-8" }, [ "Page not found" ] ]
|
||||
end
|
||||
|
||||
# Tags are declared in the server but computed in the connection. This allows us per-connection tailored tags.
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "rack"
|
||||
|
||||
module ActionCable
|
||||
module Server
|
||||
# = Action Cable \Server \Configuration
|
||||
|
@ -25,7 +27,7 @@ module ActionCable
|
|||
@filter_parameters = []
|
||||
|
||||
@health_check_application = ->(env) {
|
||||
[204, { "Content-Type" => "text/html", "date" => Time.now.httpdate }, []]
|
||||
[200, { Rack::CONTENT_TYPE => "text/html", "date" => Time.now.httpdate }, []]
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
@ -9,7 +9,8 @@ class HealthCheckTest < ActionCable::TestCase
|
|||
@config.logger = Logger.new(nil)
|
||||
@server = ActionCable::Server::Base.new config: @config
|
||||
@server.config.cable = { adapter: "async" }.with_indifferent_access
|
||||
@server.config.health_check_application = health_check_application
|
||||
|
||||
@app = Rack::Lint.new(@server)
|
||||
end
|
||||
|
||||
|
||||
|
@ -23,14 +24,23 @@ class HealthCheckTest < ActionCable::TestCase
|
|||
get "/up"
|
||||
|
||||
assert_equal 200, response.first
|
||||
assert_equal "Hello world!", response.last
|
||||
assert_equal [], response.last.enum_for.to_a
|
||||
end
|
||||
|
||||
test "health_check_application_can_be_customized" do
|
||||
@server.config.health_check_path = "/up"
|
||||
@server.config.health_check_application = health_check_application
|
||||
get "/up"
|
||||
|
||||
assert_equal 200, response.first
|
||||
assert_equal ["Hello world!"], response.last.enum_for.to_a
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
def get(path)
|
||||
env = Rack::MockRequest.env_for "/up", "HTTP_HOST" => "localhost"
|
||||
@response = @server.call env
|
||||
@response = @app.call env
|
||||
end
|
||||
|
||||
attr_reader :response
|
||||
|
@ -39,8 +49,8 @@ class HealthCheckTest < ActionCable::TestCase
|
|||
->(env) {
|
||||
[
|
||||
200,
|
||||
{ "Content-Type" => "text/html" },
|
||||
"Hello world!"
|
||||
{ Rack::CONTENT_TYPE => "text/html" },
|
||||
["Hello world!"],
|
||||
]
|
||||
}
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue