prop/test/microwaveprop/workers/propagation_prune_worker_test.exs
Graham McIntire f9e0331a2c
test: fix three pre-existing test flakes
- MapLiveTest timestamp indicator: earlier tests in the suite leave
  score files in the shared `:propagation_scores_dir` and warm the 5 s
  `list_valid_times` cache; clear both in setup so the "No data"
  assertion sees the state the test documents.
- PropagationPruneWorkerTest: `old = now - 3h` collides with the
  worker's cutoff (also `now - 3h`) once both are truncated to the
  second, so they land equal when test + worker run in the same wall
  clock second. Shift `old` by an extra -1s for unconditional ordering.
- ContactWeatherEnqueueWorkerTest: flip to async: false — perform/1
  runs inline Oban child jobs that upsert rows with a shared conflict
  target, and parallel DataCase siblings hit "ShareLock deadlock_detected"
  intermittently.
2026-04-21 13:07:01 -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.add(-3, :hour) |> DateTime.add(-1, :second) |> DateTime.truncate(:second)
fresh = now |> DateTime.add(-30, :minute) |> DateTime.truncate(:second)
future = now |> DateTime.add(6, :hour) |> 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.add(-30, :minute) |> 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