test: cover PacketDistributor GenServer callbacks

This commit is contained in:
Graham McIntire 2026-04-23 17:08:54 -05:00
parent b98ecd5432
commit 32d4b6daff
No known key found for this signature in database
GPG key ID: F4ABF488E6029E59

View file

@ -88,4 +88,31 @@ defmodule Aprsme.Cluster.PacketDistributorTest do
assert result == :ok
end
end
describe "GenServer callbacks" do
test "init/1 subscribes to the topic and returns empty state" do
assert {:ok, %{}} = PacketDistributor.init([])
# Callback subscribes the caller to cluster:packets.
Phoenix.PubSub.broadcast(Aprsme.PubSub, "cluster:packets", :ping)
assert_receive :ping, 100
end
test "handle_info forwards distributed packets" do
state = %{}
assert {:noreply, ^state} =
PacketDistributor.handle_info({:distributed_packet, @test_packet}, state)
end
test "terminate/2 unsubscribes from the topic and returns :ok" do
# Subscribe first so we have something to unsubscribe.
PacketDistributor.subscribe()
assert :ok = PacketDistributor.terminate(:shutdown, %{})
# After terminate, this process should no longer receive cluster:packets
# broadcasts.
Phoenix.PubSub.broadcast(Aprsme.PubSub, "cluster:packets", :should_not_arrive)
refute_receive :should_not_arrive, 100
end
end
end