test: PacketsLive.CallsignView overflow + iso8601 broadcast paths
This commit is contained in:
parent
2446f010f8
commit
a9647916fa
1 changed files with 68 additions and 0 deletions
|
|
@ -31,6 +31,74 @@ defmodule AprsmeWeb.PacketsLive.CallsignViewTest do
|
||||||
end
|
end
|
||||||
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
|
describe "live packet broadcast" do
|
||||||
test "handles raw broadcast packet without :data key", %{conn: conn} do
|
test "handles raw broadcast packet without :data key", %{conn: conn} do
|
||||||
{:ok, view, _html} = live(conn, "/packets/DB0WUN-13")
|
{:ok, view, _html} = live(conn, "/packets/DB0WUN-13")
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue