From ec1df7a4df6f3ff3285715777734f8632e3d01c8 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Tue, 4 Aug 2026 13:27:15 -0500 Subject: [PATCH] fix: resolve test failures from async interference and rate limiting - hrrr_client_test: async:true => async:false so Req.Test stubs are visible in Task.Supervisor.async_stream_nolink worker processes. - weather_test: add setup blocks to latest_grid_valid_time/0 and available_weather_valid_times/0 describe blocks that delete is_grid_point=true HrrrProfile rows before each test, preventing cross-contamination from other async test modules. - contact_map_controller_test: call RateLimiter.reset() in setup so accumulated ETS counters from prior tests don't trigger 429s. --- test/microwaveprop/weather/hrrr_client_test.exs | 2 +- test/microwaveprop/weather_test.exs | 13 +++++++++++++ .../controllers/contact_map_controller_test.exs | 9 +++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/test/microwaveprop/weather/hrrr_client_test.exs b/test/microwaveprop/weather/hrrr_client_test.exs index 4a7a2261..e1af658d 100644 --- a/test/microwaveprop/weather/hrrr_client_test.exs +++ b/test/microwaveprop/weather/hrrr_client_test.exs @@ -1,5 +1,5 @@ defmodule Microwaveprop.Weather.HrrrClientTest do - use ExUnit.Case, async: true + use ExUnit.Case, async: false alias Microwaveprop.Weather.HrrrClient diff --git a/test/microwaveprop/weather_test.exs b/test/microwaveprop/weather_test.exs index ec2f648d..91e3f8bb 100644 --- a/test/microwaveprop/weather_test.exs +++ b/test/microwaveprop/weather_test.exs @@ -1327,12 +1327,25 @@ defmodule Microwaveprop.WeatherTest do end describe "available_weather_valid_times/0" do + # Other async test modules insert HrrrProfile rows with + # is_grid_point: true. Wipe them so the "empty DB" assertion + # doesn't flake. + setup do + Repo.delete_all(from(h in HrrrProfile, where: h.is_grid_point == true)) + :ok + end + test "returns an empty list when no scores are stored" do assert Weather.available_weather_valid_times() == [] end end describe "latest_grid_valid_time/0" do + setup do + Repo.delete_all(from(h in HrrrProfile, where: h.is_grid_point == true)) + :ok + end + test "returns nil when no scores are stored" do assert Weather.latest_grid_valid_time() == nil end diff --git a/test/microwaveprop_web/controllers/contact_map_controller_test.exs b/test/microwaveprop_web/controllers/contact_map_controller_test.exs index 1567765b..f1d69608 100644 --- a/test/microwaveprop_web/controllers/contact_map_controller_test.exs +++ b/test/microwaveprop_web/controllers/contact_map_controller_test.exs @@ -2,12 +2,21 @@ defmodule MicrowavepropWeb.ContactMapControllerTest do use MicrowavepropWeb.ConnCase, async: false alias Microwaveprop.Cache + alias MicrowavepropWeb.Api.RateLimiter setup do # The controller caches a gzipped payload under a module-level key — # clear it between tests so gzip vs identity requests don't reuse # each other's output. Cache.invalidate({MicrowavepropWeb.ContactMapController, :gzipped_payload}) + + # The controller uses a fixed-window ETS rate limiter. Since every + # test request shares the same client IP, accumulated counters from + # prior tests (or async tests) can exhaust the bucket and trigger a + # 429 before this test even runs. Reset the table per-test so each + # describe/3 group starts with a clean slate. + RateLimiter.reset() + :ok end