- REST API: Fix id type from integer to UUID, add device/equipment fields, correct rate limiting info (100 req/min, not "none"), add 429 status code - Mobile API: Fix search_callsign response field (lon not lng), add path to packet fields, correct rate limiting/timeout docs, clarify update_bounds behavior - Fix flaky pipeline tests (async race on global Application config)
84 lines
2.5 KiB
Elixir
84 lines
2.5 KiB
Elixir
defmodule Aprsme.PacketConsumerPoolTest do
|
|
use ExUnit.Case, async: false
|
|
|
|
alias Aprsme.PacketConsumerPool
|
|
|
|
describe "child_spec/1" do
|
|
test "returns expected spec" do
|
|
spec = PacketConsumerPool.child_spec([])
|
|
|
|
assert spec.id == PacketConsumerPool
|
|
assert spec.type == :supervisor
|
|
end
|
|
end
|
|
|
|
describe "init/1" do
|
|
test "returns supervisor flags with one_for_one strategy and 3 children" do
|
|
{:ok, {sup_flags, children}} = PacketConsumerPool.init(num_consumers: 3)
|
|
|
|
assert sup_flags.strategy == :one_for_one
|
|
assert length(children) == 3
|
|
end
|
|
|
|
test "each child has a unique id of {Aprsme.PacketConsumer, index}" do
|
|
{:ok, {_sup_flags, children}} = PacketConsumerPool.init(num_consumers: 3)
|
|
|
|
ids = Enum.map(children, & &1.id)
|
|
|
|
assert {Aprsme.PacketConsumer, 1} in ids
|
|
assert {Aprsme.PacketConsumer, 2} in ids
|
|
assert {Aprsme.PacketConsumer, 3} in ids
|
|
assert length(ids) == length(Enum.uniq(ids))
|
|
end
|
|
|
|
test "creates 5 children when num_consumers: 5 is passed in opts" do
|
|
{:ok, {_sup_flags, children}} = PacketConsumerPool.init(num_consumers: 5)
|
|
|
|
assert length(children) == 5
|
|
|
|
ids = Enum.map(children, & &1.id)
|
|
|
|
for index <- 1..5 do
|
|
assert {Aprsme.PacketConsumer, index} in ids
|
|
end
|
|
end
|
|
|
|
test "max_demand is divided evenly among consumers" do
|
|
original_config = Application.get_env(:aprsme, :packet_pipeline, [])
|
|
|
|
on_exit(fn ->
|
|
Application.put_env(:aprsme, :packet_pipeline, original_config)
|
|
end)
|
|
|
|
Application.put_env(:aprsme, :packet_pipeline, max_demand: 500)
|
|
|
|
{:ok, {_sup_flags, children}} = PacketConsumerPool.init(num_consumers: 5)
|
|
|
|
expected_demand = div(500, 5)
|
|
|
|
for child <- children do
|
|
{Aprsme.PacketConsumer, :start_link, [opts]} = child.start
|
|
assert opts[:max_demand] == expected_demand
|
|
assert opts[:subscribe_to] == [{Aprsme.PacketProducer, max_demand: expected_demand}]
|
|
end
|
|
end
|
|
|
|
test "uses default max_demand of 250 when not configured" do
|
|
original_config = Application.get_env(:aprsme, :packet_pipeline, [])
|
|
|
|
on_exit(fn ->
|
|
Application.put_env(:aprsme, :packet_pipeline, original_config)
|
|
end)
|
|
|
|
Application.delete_env(:aprsme, :packet_pipeline)
|
|
|
|
{:ok, {_sup_flags, children}} = PacketConsumerPool.init(num_consumers: 3)
|
|
|
|
expected_demand = div(250, 3)
|
|
|
|
child = List.first(children)
|
|
{Aprsme.PacketConsumer, :start_link, [opts]} = child.start
|
|
assert opts[:max_demand] == expected_demand
|
|
end
|
|
end
|
|
end
|