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.
This commit is contained in:
Graham McIntire 2026-04-21 13:07:01 -05:00
parent 1400c38f44
commit f9e0331a2c
No known key found for this signature in database
GPG key ID: F4ABF488E6029E59
3 changed files with 22 additions and 3 deletions

View file

@ -1,5 +1,9 @@
defmodule Microwaveprop.Workers.ContactWeatherEnqueueWorkerTest do
use Microwaveprop.DataCase, async: true
# async: false — perform/1 runs inline Oban child jobs that upsert
# rows (iemre_observations, terrain_profiles) with a shared conflict
# target. Running concurrently with sibling DataCase tests produced
# intermittent "ShareLock deadlock_detected" failures in Postgres.
use Microwaveprop.DataCase, async: false
alias Microwaveprop.Radio.Contact
alias Microwaveprop.Terrain.ElevationClient

View file

@ -5,9 +5,13 @@ defmodule Microwaveprop.Workers.PropagationPruneWorkerTest do
alias Microwaveprop.Workers.PropagationPruneWorker
describe "perform/1" do
test "deletes ScoresFile binaries with valid_time older than 2 hours" 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.truncate(:second)
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)

View file

@ -120,6 +120,17 @@ defmodule MicrowavepropWeb.MapLiveTest do
end
describe "data timestamp indicator" do
setup do
# Earlier tests in the suite may have written score files into the
# shared `:propagation_scores_dir` and warmed the 5 s
# `list_valid_times` cache. Reset both so this test starts from the
# "no data" state its assertion describes.
scores_dir = Application.fetch_env!(:microwaveprop, :propagation_scores_dir)
_ = File.rm_rf(scores_dir)
:ets.match_delete(:microwaveprop_cache, {{Microwaveprop.Propagation.ScoresFile, :list_valid_times, :_, :_}, :_, :_})
:ok
end
test "renders a 'Data from …' line on both mobile and desktop sidebars", %{conn: conn} do
{:ok, _lv, html} = live(conn, ~p"/map")
assert html =~ ~s(id="data-timestamp-mobile")