Merge pull request #48961 from skipkayhil/hm-rack-lint-cable-health

Add Rack::Lint to ActionCable::Server health tests
This commit is contained in:
Guillermo Iguaran 2023-08-17 16:51:41 -07:00 committed by GitHub
commit 1e824aa8e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 7 deletions

View File

@ -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.

View File

@ -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

View File

@ -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