aprs.me/test/aprsme/signal_handler_test.exs
Graham McIntire a377847122
chore: remove unused deps, replace resend with custom Swoosh adapter, fix test isolation
Remove faker, floki, igniter, ecto_psql_extras (zero usages), exvcr
(zero usages), and resend. Replace resend with Aprsme.Swoosh.ResendAdapter
using the already-present req dependency. Frees 23 packages total from
the lockfile including hackney, certifi, and the tesla dependency chain.

Fix two pre-existing test isolation bugs:
- signal_handler_test called the real ShutdownHandler.shutdown() via SIGTERM
  simulation without restoring state, causing page_controller_test to see
  shutting_down: true and return 503
- page_controller_test setup now resets ShutdownHandler state defensively
2026-04-24 13:04:18 -05:00

43 lines
1.5 KiB
Elixir

defmodule Aprsme.SignalHandlerTest do
use ExUnit.Case, async: true
alias Aprsme.SignalHandler
describe "handle_info/2" do
test "ignores unrecognized messages without changing state" do
state = %{some: :state}
assert SignalHandler.handle_info(:random, state) == {:noreply, state}
assert SignalHandler.handle_info({:other, "msg"}, state) == {:noreply, state}
end
test "sigterm branch spawn_links a shutdown task without crashing the caller" do
# Trap exits so the spawn_link from handle_info doesn't bring the test down.
Process.flag(:trap_exit, true)
assert {:noreply, :state_x} =
SignalHandler.handle_info({:signal, :sigterm}, :state_x)
# Drain any :EXIT messages from the spawned task.
receive do
{:EXIT, _pid, _reason} -> :ok
after
200 -> :ok
end
# The spawned task calls the real ShutdownHandler.shutdown() if the process
# is running. Reset its state so other tests aren't affected.
if pid = Process.whereis(Aprsme.ShutdownHandler) do
:sys.replace_state(pid, fn state -> %{state | shutting_down: false} end)
Application.put_env(:aprsme, :health_status, :healthy)
end
end
end
describe "init/1" do
test "installs a SIGTERM handler and returns an empty state" do
# :os.set_signal is process-global but calling it a second time with
# :handle is idempotent at the VM level. Safe to exercise.
assert {:ok, %{}} = SignalHandler.init([])
end
end
end