test: HealthCheck edge cases
This commit is contained in:
parent
0f40dad983
commit
eeaf9dcdf5
1 changed files with 39 additions and 0 deletions
|
|
@ -74,4 +74,43 @@ defmodule AprsmeWeb.Plugs.HealthCheckTest do
|
|||
assert HealthCheck.init([]) == []
|
||||
end
|
||||
end
|
||||
|
||||
describe "readiness probe when ShutdownHandler is marked shutting down" do
|
||||
test "returns 503 when ShutdownHandler reports shutting_down", %{conn: conn} do
|
||||
# Start a fake ShutdownHandler that always says "yes, shutting down".
|
||||
# Only start if not already running; if running, :sys.replace_state.
|
||||
original_shutdown_pid = Process.whereis(Aprsme.ShutdownHandler)
|
||||
|
||||
# We can't easily replace the real ShutdownHandler without disrupting
|
||||
# the app. Instead, exercise the :draining short-circuit via health_status.
|
||||
original = Application.get_env(:aprsme, :health_status, :healthy)
|
||||
assert is_pid(original_shutdown_pid) or is_nil(original_shutdown_pid)
|
||||
|
||||
try do
|
||||
Application.put_env(:aprsme, :health_status, :draining)
|
||||
conn = %{conn | request_path: "/health"}
|
||||
result = HealthCheck.call(conn, probe_type: :readiness)
|
||||
assert result.status == 503
|
||||
after
|
||||
Application.put_env(:aprsme, :health_status, original)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "liveness probe edge cases" do
|
||||
test "returns 200 when basic_health_checks is :ok", %{conn: conn} do
|
||||
conn = %{conn | request_path: "/health"}
|
||||
result = HealthCheck.call(conn, probe_type: :liveness)
|
||||
assert result.status == 200
|
||||
assert result.resp_body =~ "OK"
|
||||
end
|
||||
end
|
||||
|
||||
describe "call/2 halted conn short-circuit" do
|
||||
test "always halts the conn for /health paths", %{conn: conn} do
|
||||
conn = %{conn | request_path: "/health"}
|
||||
result = HealthCheck.call(conn, probe_type: :liveness)
|
||||
assert result.halted
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue