The three BackfillEnqueueWorkerTest cases were timing out because the default types list includes :era5, which cascades through inline Oban into Era5Client.poll_and_download where Process.sleep blocks for the full 60s test timeout. Era5Client uses bare Req.get with no plug hook, so it can't be stubbed via Req.Test the way the other clients are. Pass explicit non-ERA5 types in the three affected cases — ERA5 has its own coverage and these tests don't assert anything era5-specific. Also replace two `length(results) > 0` checks in asos_nudge_test with `results != []` to silence credo warnings.
117 lines
3.3 KiB
Elixir
117 lines
3.3 KiB
Elixir
defmodule Microwaveprop.Workers.BackfillEnqueueWorkerTest do
|
|
use Microwaveprop.DataCase, async: true
|
|
|
|
alias Microwaveprop.Radio.Contact
|
|
alias Microwaveprop.Terrain.ElevationClient
|
|
alias Microwaveprop.Weather.HrrrClient
|
|
alias Microwaveprop.Weather.IemClient
|
|
alias Microwaveprop.Workers.BackfillEnqueueWorker
|
|
|
|
defp create_contact(attrs \\ %{}) do
|
|
default = %{
|
|
station1: "W5XD",
|
|
station2: "K5TR",
|
|
qso_timestamp: ~U[2026-03-28 18:00:00Z],
|
|
mode: "CW",
|
|
band: Decimal.new("1296"),
|
|
grid1: "EM12",
|
|
grid2: "EM00",
|
|
pos1: %{"lat" => 32.9, "lon" => -97.0},
|
|
pos2: %{"lat" => 30.3, "lon" => -97.7},
|
|
distance_km: Decimal.new("295")
|
|
}
|
|
|
|
{:ok, contact} =
|
|
%Contact{}
|
|
|> Contact.changeset(Map.merge(default, attrs))
|
|
|> Repo.insert()
|
|
|
|
contact
|
|
end
|
|
|
|
setup do
|
|
Req.Test.stub(IemClient, fn conn ->
|
|
case conn.request_path do
|
|
"/cgi-bin/request/asos.py" ->
|
|
Req.Test.text(conn, "#DEBUG,\nstation,valid,tmpf\n")
|
|
|
|
"/iemre/" <> _ ->
|
|
Req.Test.json(conn, %{"data" => [%{"utc_hour" => 0, "p01m_mm" => 0.0}]})
|
|
|
|
_ ->
|
|
Req.Test.json(conn, %{"profiles" => []})
|
|
end
|
|
end)
|
|
|
|
Req.Test.stub(HrrrClient, fn conn ->
|
|
Plug.Conn.send_resp(conn, 404, "not found")
|
|
end)
|
|
|
|
Req.Test.stub(ElevationClient, fn conn ->
|
|
params = Plug.Conn.fetch_query_params(conn).query_params
|
|
lat_count = params["latitude"] |> String.split(",") |> length()
|
|
Req.Test.json(conn, %{"elevation" => List.duplicate(200.0, lat_count)})
|
|
end)
|
|
|
|
:ok
|
|
end
|
|
|
|
# ERA5 goes through Copernicus CDS API which is async (submit → poll → download)
|
|
# and has no Req.Test plug hook, so inline Oban would block on Process.sleep.
|
|
# These tests exercise the non-ERA5 enrichment path; ERA5 has its own coverage.
|
|
@non_era5_types ["hrrr", "weather", "terrain", "iemre"]
|
|
|
|
describe "perform/1" do
|
|
test "enqueues enrichment jobs for pending contacts" do
|
|
create_contact()
|
|
|
|
assert :ok =
|
|
BackfillEnqueueWorker.perform(%Oban.Job{
|
|
args: %{"limit" => 10, "types" => @non_era5_types}
|
|
})
|
|
end
|
|
|
|
test "does not enqueue for already-complete contacts" do
|
|
contact = create_contact()
|
|
|
|
contact
|
|
|> Ecto.Changeset.change(%{
|
|
hrrr_status: :complete,
|
|
weather_status: :complete,
|
|
terrain_status: :complete,
|
|
iemre_status: :complete
|
|
})
|
|
|> Repo.update!()
|
|
|
|
assert :ok =
|
|
BackfillEnqueueWorker.perform(%Oban.Job{
|
|
args: %{"limit" => 10, "types" => @non_era5_types}
|
|
})
|
|
end
|
|
|
|
test "respects limit parameter" do
|
|
for i <- 1..5 do
|
|
ts = DateTime.add(~U[2026-01-01 00:00:00Z], i * 3600, :second)
|
|
create_contact(%{qso_timestamp: ts})
|
|
end
|
|
|
|
assert :ok =
|
|
BackfillEnqueueWorker.perform(%Oban.Job{
|
|
args: %{"limit" => 2, "types" => @non_era5_types}
|
|
})
|
|
end
|
|
|
|
test "broadcasts enqueue_complete with count" do
|
|
Phoenix.PubSub.subscribe(Microwaveprop.PubSub, "backfill:enqueue_complete")
|
|
|
|
create_contact()
|
|
|
|
assert :ok =
|
|
BackfillEnqueueWorker.perform(%Oban.Job{
|
|
args: %{"limit" => 10, "types" => @non_era5_types}
|
|
})
|
|
|
|
assert_receive {:enqueue_complete, 1}
|
|
end
|
|
end
|
|
end
|