aprs.me/test/aprsme/packet_pipeline_supervisor_test.exs
Graham McIntire ac51ecaada
Fix multiple TODO bugs: drain handler, callsign dedup, packet pipeline
- Fix drain_connections missing {:noreply, socket} wrapper
- Fix get_callsign_key to match atom keys from Ecto structs
- Add SpatialPubSub.broadcast_packet to PacketDistributor
- Fix pid_alive? treating {:badrpc, _} as truthy
- Fix SpatialPubSub ensure_float crash on integer strings
- Fix inverted memory calculation in ConnectionMonitor
- Remove dead SSL handler from Is module, consolidate into handle_socket_data
- Remove duplicate packet transformation in Is.dispatch
- Remove invalid placeholders option from insert_all calls
- Change PacketPipelineSupervisor to :rest_for_one strategy
- Update TODO.md marking fixed items
2026-02-19 18:27:25 -06:00

126 lines
3.7 KiB
Elixir

defmodule Aprsme.PacketPipelineSupervisorTest do
use ExUnit.Case, async: false
alias Aprsme.PacketPipelineSupervisor
describe "init/1 with default config" do
setup do
original = Application.get_env(:aprsme, :packet_pipeline)
Application.delete_env(:aprsme, :packet_pipeline)
on_exit(fn ->
if original do
Application.put_env(:aprsme, :packet_pipeline, original)
else
Application.delete_env(:aprsme, :packet_pipeline)
end
end)
:ok
end
test "returns :rest_for_one strategy" do
{:ok, {sup_flags, _children}} = PacketPipelineSupervisor.init([])
assert %{strategy: :rest_for_one} = sup_flags
end
test "returns two child specs" do
{:ok, {_sup_flags, children}} = PacketPipelineSupervisor.init([])
assert length(children) == 2
end
test "includes PacketProducer with default max_buffer_size of 1000" do
{:ok, {_sup_flags, children}} = PacketPipelineSupervisor.init([])
producer_spec = Enum.find(children, fn spec -> spec.id == Aprsme.PacketProducer end)
assert producer_spec
assert {Aprsme.PacketProducer, [max_buffer_size: 1000]} = extract_mfa(producer_spec.start)
end
test "includes PacketConsumerPool with default num_consumers of 3" do
{:ok, {_sup_flags, children}} = PacketPipelineSupervisor.init([])
pool_spec = Enum.find(children, fn spec -> spec.id == Aprsme.PacketConsumerPool end)
assert pool_spec
assert {Aprsme.PacketConsumerPool, [num_consumers: 3]} = extract_mfa(pool_spec.start)
end
end
describe "init/1 with custom config" do
setup do
original = Application.get_env(:aprsme, :packet_pipeline)
Application.put_env(:aprsme, :packet_pipeline,
max_buffer_size: 5000,
num_consumers: 10
)
on_exit(fn ->
if original do
Application.put_env(:aprsme, :packet_pipeline, original)
else
Application.delete_env(:aprsme, :packet_pipeline)
end
end)
:ok
end
test "uses custom max_buffer_size from config" do
{:ok, {_sup_flags, children}} = PacketPipelineSupervisor.init([])
producer_spec = Enum.find(children, fn spec -> spec.id == Aprsme.PacketProducer end)
assert {Aprsme.PacketProducer, [max_buffer_size: 5000]} = extract_mfa(producer_spec.start)
end
test "uses custom num_consumers from config" do
{:ok, {_sup_flags, children}} = PacketPipelineSupervisor.init([])
pool_spec = Enum.find(children, fn spec -> spec.id == Aprsme.PacketConsumerPool end)
assert {Aprsme.PacketConsumerPool, [num_consumers: 10]} = extract_mfa(pool_spec.start)
end
end
describe "start_link/0" do
test "is exported as a function" do
Code.ensure_loaded!(PacketPipelineSupervisor)
assert function_exported?(PacketPipelineSupervisor, :start_link, 0)
end
test "starts the supervisor process" do
# Stop existing instance if running
case Process.whereis(PacketPipelineSupervisor) do
nil -> :ok
pid -> Supervisor.stop(pid, :normal, 5000)
end
case PacketPipelineSupervisor.start_link() do
{:ok, pid} ->
assert Process.alive?(pid)
Supervisor.stop(pid, :normal, 5000)
{:error, _reason} ->
# Children may fail to start if dependencies aren't running
:ok
end
end
test "child_spec/1 returns expected spec" do
spec = PacketPipelineSupervisor.child_spec([])
assert spec.id == PacketPipelineSupervisor
assert spec.type == :supervisor
end
end
# Extracts {module, args} from a child spec's start MFA tuple
defp extract_mfa({module, :start_link, [args]}) do
{module, args}
end
end