test: cover PacketDistributor GenServer callbacks
This commit is contained in:
parent
b98ecd5432
commit
32d4b6daff
1 changed files with 27 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue