fix: make spatial packet tests robust against :process_batch mailbox pollution
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:
parent
b93d4904a3
commit
9111e6355a
1 changed files with 15 additions and 4 deletions
|
|
@ -533,7 +533,7 @@ defmodule Aprsme.PacketConsumerTest do
|
||||||
Process.sleep(50)
|
Process.sleep(50)
|
||||||
|
|
||||||
# Should receive the packet via PubSub with object_name as sender
|
# 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.sender == "CALGRY", "Expected sender to be object name CALGRY, got #{packet.sender}"
|
||||||
assert packet.latitude == 51.044733
|
assert packet.latitude == 51.044733
|
||||||
assert packet.longitude == -114.062019
|
assert packet.longitude == -114.062019
|
||||||
|
|
@ -573,7 +573,7 @@ defmodule Aprsme.PacketConsumerTest do
|
||||||
Process.sleep(50)
|
Process.sleep(50)
|
||||||
|
|
||||||
# Should receive the packet via PubSub with item_name as sender
|
# 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.sender == "MyItem", "Expected sender to be item name MyItem, got #{packet.sender}"
|
||||||
assert packet.latitude == 35.0
|
assert packet.latitude == 35.0
|
||||||
assert packet.longitude == -75.0
|
assert packet.longitude == -75.0
|
||||||
|
|
@ -807,7 +807,7 @@ defmodule Aprsme.PacketConsumerTest do
|
||||||
Process.sleep(50)
|
Process.sleep(50)
|
||||||
|
|
||||||
# Should receive the packet via PubSub
|
# Should receive the packet via PubSub
|
||||||
assert_receive {:spatial_packet, packet}, 1000
|
packet = receive_spatial_packet()
|
||||||
assert packet.sender == "BROADCAST1"
|
assert packet.sender == "BROADCAST1"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -940,7 +940,7 @@ defmodule Aprsme.PacketConsumerTest do
|
||||||
# Wait for async broadcast task to complete
|
# Wait for async broadcast task to complete
|
||||||
Process.sleep(50)
|
Process.sleep(50)
|
||||||
|
|
||||||
assert_receive {:spatial_packet, packet}, 1000
|
packet = receive_spatial_packet()
|
||||||
assert packet.sender == "FALLBACK1"
|
assert packet.sender == "FALLBACK1"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -1003,4 +1003,15 @@ defmodule Aprsme.PacketConsumerTest do
|
||||||
on_exit(fn -> SpatialPubSub.unregister_client(client_id) end)
|
on_exit(fn -> SpatialPubSub.unregister_client(client_id) end)
|
||||||
:ok
|
:ok
|
||||||
end
|
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
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue