fix: make spatial packet tests robust against :process_batch mailbox pollution
Some checks failed
Elixir CI / Build and test (push) Failing after 3m27s
Elixir CI / Dialyzer (push) Successful in 3m54s
Elixir CI / Build and Push Docker Image (push) Has been skipped

Replace assert_receive with a receive_spatial_packet helper that ignores
:process_batch messages. These are scheduled by handle_events via
Process.send_after and can pollute the test process mailbox when tests
run in the full test suite.
This commit is contained in:
Graham McIntire 2026-08-06 17:57:07 -05:00
parent b93d4904a3
commit 9111e6355a
No known key found for this signature in database
GPG key ID: F4ABF488E6029E59

View file

@ -533,7 +533,7 @@ defmodule Aprsme.PacketConsumerTest do
Process.sleep(50)
# Should receive the packet via PubSub with object_name as sender
assert_receive {:spatial_packet, packet}, 1000
packet = receive_spatial_packet()
assert packet.sender == "CALGRY", "Expected sender to be object name CALGRY, got #{packet.sender}"
assert packet.latitude == 51.044733
assert packet.longitude == -114.062019
@ -573,7 +573,7 @@ defmodule Aprsme.PacketConsumerTest do
Process.sleep(50)
# Should receive the packet via PubSub with item_name as sender
assert_receive {:spatial_packet, packet}, 1000
packet = receive_spatial_packet()
assert packet.sender == "MyItem", "Expected sender to be item name MyItem, got #{packet.sender}"
assert packet.latitude == 35.0
assert packet.longitude == -75.0
@ -807,7 +807,7 @@ defmodule Aprsme.PacketConsumerTest do
Process.sleep(50)
# Should receive the packet via PubSub
assert_receive {:spatial_packet, packet}, 1000
packet = receive_spatial_packet()
assert packet.sender == "BROADCAST1"
end
@ -940,7 +940,7 @@ defmodule Aprsme.PacketConsumerTest do
# Wait for async broadcast task to complete
Process.sleep(50)
assert_receive {:spatial_packet, packet}, 1000
packet = receive_spatial_packet()
assert packet.sender == "FALLBACK1"
end
end
@ -1003,4 +1003,15 @@ defmodule Aprsme.PacketConsumerTest do
on_exit(fn -> SpatialPubSub.unregister_client(client_id) end)
:ok
end
# Receives a spatial packet, ignoring :process_batch messages
# that may be in the mailbox from handle_events scheduling.
defp receive_spatial_packet(timeout \\ 2000) do
receive do
{:spatial_packet, packet} -> packet
:process_batch -> receive_spatial_packet(timeout)
after
timeout -> flunk("Expected {:spatial_packet, _} but did not receive one within #{timeout}ms")
end
end
end