test: expand Is backpressure, PacketReplay, CleanupScheduler coverage
This commit is contained in:
parent
2867224aad
commit
c8c20add1f
3 changed files with 93 additions and 0 deletions
|
|
@ -48,5 +48,20 @@ defmodule Aprsme.CleanupSchedulerTest do
|
|||
state = %{interval: nil}
|
||||
assert CleanupScheduler.handle_info(:schedule_cleanup, state) == {:noreply, state}
|
||||
end
|
||||
|
||||
test "runs cleanup and reschedules when interval is an integer" do
|
||||
# Ensure BroadcastTaskSupervisor is up — it wraps Task.Supervisor.
|
||||
_ =
|
||||
case Process.whereis(Aprsme.BroadcastTaskSupervisor) do
|
||||
nil -> start_supervised({Task.Supervisor, name: Aprsme.BroadcastTaskSupervisor})
|
||||
_ -> :ok
|
||||
end
|
||||
|
||||
state = %{interval: 100}
|
||||
|
||||
assert {:noreply, ^state} = CleanupScheduler.handle_info(:schedule_cleanup, state)
|
||||
# Next cleanup scheduled.
|
||||
assert_receive :schedule_cleanup, 300
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -498,6 +498,56 @@ defmodule Aprsme.IsTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "backpressure handling" do
|
||||
test "activate with nil socket is a no-op" do
|
||||
state = build_state(%{socket: nil, backpressure_active: false})
|
||||
|
||||
assert {:noreply, ^state} =
|
||||
Aprsme.Is.handle_info({:backpressure, :activate}, state)
|
||||
end
|
||||
|
||||
test "activate when already active is a no-op" do
|
||||
state = build_state(%{socket: nil, backpressure_active: true})
|
||||
|
||||
assert {:noreply, ^state} =
|
||||
Aprsme.Is.handle_info({:backpressure, :activate}, state)
|
||||
end
|
||||
|
||||
test "deactivate when already inactive is a no-op" do
|
||||
state = build_state(%{socket: nil, backpressure_active: false})
|
||||
|
||||
assert {:noreply, ^state} =
|
||||
Aprsme.Is.handle_info({:backpressure, :deactivate}, state)
|
||||
end
|
||||
|
||||
test "deactivate with nil socket clears flag but doesn't touch socket" do
|
||||
state = build_state(%{socket: nil, backpressure_active: true})
|
||||
|
||||
assert {:noreply, new_state} =
|
||||
Aprsme.Is.handle_info({:backpressure, :deactivate}, state)
|
||||
|
||||
refute new_state.backpressure_active
|
||||
assert is_nil(new_state.safety_valve_timer)
|
||||
end
|
||||
|
||||
test "safety_valve when not active is a no-op" do
|
||||
state = build_state(%{backpressure_active: false})
|
||||
|
||||
assert {:noreply, ^state} =
|
||||
Aprsme.Is.handle_info(:backpressure_safety_valve, state)
|
||||
end
|
||||
|
||||
test "safety_valve with nil socket clears flag" do
|
||||
state = build_state(%{socket: nil, backpressure_active: true, safety_valve_timer: nil})
|
||||
|
||||
assert {:noreply, new_state} =
|
||||
Aprsme.Is.handle_info(:backpressure_safety_valve, state)
|
||||
|
||||
refute new_state.backpressure_active
|
||||
assert is_nil(new_state.safety_valve_timer)
|
||||
end
|
||||
end
|
||||
|
||||
describe "APRS-IS mock functionality" do
|
||||
setup do
|
||||
case GenServer.start_link(AprsIsMock, [], name: AprsIsMock) do
|
||||
|
|
|
|||
|
|
@ -265,5 +265,33 @@ defmodule Aprsme.PacketReplayTest do
|
|||
# Timer should have been cancelled.
|
||||
assert Process.read_timer(timer_ref) == false
|
||||
end
|
||||
|
||||
test "terminate is idempotent with no pending timer" do
|
||||
{:ok, state} = PacketReplay.init(user_id: "noterm", bounds: [0, 0, 1, 1])
|
||||
|
||||
receive do
|
||||
:start_replay -> :ok
|
||||
after
|
||||
0 -> :ok
|
||||
end
|
||||
|
||||
assert :ok = PacketReplay.terminate(:normal, state)
|
||||
end
|
||||
end
|
||||
|
||||
describe "handle_info(:start_replay, ...)" do
|
||||
test "broadcasts replay_started then stops when no matching packets" do
|
||||
{:ok, state} = PacketReplay.init(user_id: "empty_stream", bounds: [0, 0, 1, 1])
|
||||
|
||||
receive do
|
||||
:start_replay -> :ok
|
||||
after
|
||||
0 -> :ok
|
||||
end
|
||||
|
||||
# With no seeded packets in the DB, stream_packets_for_replay returns an
|
||||
# empty stream and handle_info :start_replay should stop the server.
|
||||
assert {:stop, :normal, _state} = PacketReplay.handle_info(:start_replay, state)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue