mirror of https://github.com/rails/rails
Merge pull request #48961 from skipkayhil/hm-rack-lint-cable-health
Add Rack::Lint to ActionCable::Server health tests
This commit is contained in:
commit
1e824aa8e0
|
@ -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