prop/test/microwaveprop/workers/propagation_prune_worker_test.exs
Graham McIntire 664f1353db Decouple propagation_scores pruning from the compute worker
Pruning used to only run at the end of a successful PropagationGridWorker
pass, so a stretch of failed compute jobs (k8s OOM kills, SIGTERM)
stopped prune from running and let the table accumulate ~5h of stale
rows. A dedicated PropagationPruneWorker now runs every 15 minutes on
its own Oban cron, and PropagationGridWorker also calls prune_old_scores
at the start of each run as a second safety net. Bumped the delete
timeout from 2m to 5m so the first catch-up pass has enough headroom.
2026-04-09 12:30:10 -05:00

51 lines
1.6 KiB
Elixir

defmodule Microwaveprop.Workers.PropagationPruneWorkerTest do
use Microwaveprop.DataCase, async: true
alias Microwaveprop.Propagation.GridScore
alias Microwaveprop.Repo
alias Microwaveprop.Workers.PropagationPruneWorker
@factors %{
"humidity" => 85,
"time_of_day" => 60,
"td_depression" => 70,
"refractivity" => 55,
"sky" => 80,
"season" => 65,
"wind" => 50,
"rain" => 90,
"pressure" => 75
}
defp insert_score!(valid_time, lat \\ 32.875, lon \\ -97.0) do
Repo.insert!(%GridScore{lat: lat, lon: lon, valid_time: valid_time, band_mhz: 10_000, score: 72, factors: @factors})
end
describe "perform/1" do
test "deletes scores with valid_time older than 2 hours" do
now = DateTime.truncate(DateTime.utc_now(), :second)
old = DateTime.add(now, -3, :hour)
fresh = DateTime.add(now, -30, :minute)
future = DateTime.add(now, 6, :hour)
old_score = insert_score!(old, 32.0, -97.0)
fresh_score = insert_score!(fresh, 32.1, -97.1)
future_score = insert_score!(future, 32.2, -97.2)
assert :ok = PropagationPruneWorker.perform(%Oban.Job{})
refute Repo.get(GridScore, old_score.id)
assert Repo.get(GridScore, fresh_score.id)
assert Repo.get(GridScore, future_score.id)
end
test "is a no-op when nothing is stale" do
now = DateTime.truncate(DateTime.utc_now(), :second)
fresh = DateTime.add(now, -30, :minute)
score = insert_score!(fresh)
assert :ok = PropagationPruneWorker.perform(%Oban.Job{})
assert Repo.get(GridScore, score.id)
end
end
end