test: PacketsLive.CallsignView overflow + iso8601 broadcast paths

This commit is contained in:
Graham McIntire 2026-04-24 08:46:34 -05:00
parent 2446f010f8
commit a9647916fa
No known key found for this signature in database
GPG key ID: F4ABF488E6029E59

View file

@ -31,6 +31,74 @@ defmodule AprsmeWeb.PacketsLive.CallsignViewTest do
end
end
describe "live packet broadcast edge cases" do
test "broadcasts exceeding 100 packets carry the oldest out of live buffer", %{conn: conn} do
# Pre-seed a packet so stored=[packet], live=[].
_p =
packet_fixture(%{
sender: "OVERFLOW-1",
base_callsign: "OVERFLOW",
ssid: "1",
received_at: DateTime.utc_now(),
lat: Decimal.new("33.0"),
lon: Decimal.new("-96.0")
})
{:ok, view, _html} = live(conn, "/packets/OVERFLOW-1", on_error: :warn)
# Broadcast enough live packets to overflow the 100-packet total.
for i <- 1..110 do
payload = %{
sender: "OVERFLOW-1",
base_callsign: "OVERFLOW",
ssid: "1",
received_at: DateTime.add(DateTime.utc_now(), i, :second),
data_type: :position,
destination: "APRS",
path: "",
device_identifier: "APRS",
data_extended: %{symbol_table_id: "/", symbol_code: ">"}
}
Phoenix.PubSub.broadcast(
Aprsme.PubSub,
"packets:OVERFLOW-1",
{:postgres_packet, payload}
)
end
Process.sleep(100)
html = render(view)
assert html =~ "OVERFLOW-1"
end
test "handles broadcast with iso8601 string timestamp", %{conn: conn} do
{:ok, view, _html} = live(conn, "/packets/STRTIME-1", on_error: :warn)
payload = %{
sender: "STRTIME-1",
base_callsign: "STRTIME",
ssid: "1",
received_at: DateTime.to_iso8601(DateTime.utc_now()),
data_type: :position,
destination: "APRS",
path: "",
data_extended: %{symbol_table_id: "/", symbol_code: ">"}
}
Phoenix.PubSub.broadcast(Aprsme.PubSub, "packets:STRTIME-1", {:postgres_packet, payload})
Process.sleep(30)
assert render(view) =~ "STRTIME-1"
end
test "ignores unknown messages without crashing", %{conn: conn} do
{:ok, view, _html} = live(conn, "/packets/UNKMSG-1", on_error: :warn)
send(view.pid, :some_random)
Process.sleep(20)
assert Process.alive?(view.pid)
end
end
describe "live packet broadcast" do
test "handles raw broadcast packet without :data key", %{conn: conn} do
{:ok, view, _html} = live(conn, "/packets/DB0WUN-13")