prop/test/microwaveprop/workers/propagation_prune_worker_test.exs
Graham McIntire 581955bd69
Some checks failed
Build and Push / Build and Push Docker Image (push) Has been cancelled
fix: prevent contacts_dedup_idx collisions in parallel async tests
Create shared ContactsFixtures module with globally-unique qso_timestamp
seconds to prevent unique-constraint violations when async test modules
run in parallel and insert contacts with identical dedup-key columns.
The qso_timestamp column is timestamp(0), so microsecond offsets were
truncated — use System.unique_integer monotonic seconds instead.

Also make count-asserting tests resilient to sandbox-leaked contacts
from prior tests by using >= assertions or status-based checks rather
than exact counts.

Includes automated DateTime.add → DateTime.shift migration from
mix format.
2026-08-04 17:05:16 -05:00

38 lines
1.7 KiB
Elixir

defmodule Microwaveprop.Workers.PropagationPruneWorkerTest do
use Microwaveprop.DataCase, async: false
alias Microwaveprop.Propagation.ScoresFile
alias Microwaveprop.Workers.PropagationPruneWorker
describe "perform/1" do
test "deletes ScoresFile binaries with valid_time older than 3 hours" do
# `old` needs to sit strictly before the worker's computed cutoff
# (`now - 3h`). Both are truncated to the second when compared, so
# picking exactly -3h flakes whenever the test + worker wall-clock
# land in the same second. -3h - 1s gives unconditional ordering.
now = DateTime.utc_now()
old = now |> DateTime.shift(hour: -3, second: -1) |> DateTime.truncate(:second)
fresh = now |> DateTime.shift(minute: -30) |> DateTime.truncate(:second)
future = now |> DateTime.shift(hour: 6) |> DateTime.truncate(:second)
ScoresFile.write!(10_000, old, [%{lat: 25.0, lon: -125.0, score: 10}])
ScoresFile.write!(10_000, fresh, [%{lat: 25.0, lon: -125.0, score: 20}])
ScoresFile.write!(10_000, future, [%{lat: 25.0, lon: -125.0, score: 30}])
assert :ok = PropagationPruneWorker.perform(%Oban.Job{})
assert {:error, :enoent} = ScoresFile.read(10_000, old)
assert {:ok, _} = ScoresFile.read(10_000, fresh)
assert {:ok, _} = ScoresFile.read(10_000, future)
end
test "is a no-op when nothing is stale" do
now = DateTime.utc_now()
fresh = now |> DateTime.shift(minute: -30) |> DateTime.truncate(:second)
ScoresFile.write!(10_000, fresh, [%{lat: 25.0, lon: -125.0, score: 42}])
assert :ok = PropagationPruneWorker.perform(%Oban.Job{})
assert {:ok, _} = ScoresFile.read(10_000, fresh)
end
end
end