fix: resolve test failures from async interference and rate limiting
Some checks failed
Build and Push / Build and Push Docker Image (push) Failing after 13m28s

- 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.
This commit is contained in:
Graham McIntire 2026-08-04 13:27:15 -05:00
parent 9fd2622550
commit ec1df7a4df
3 changed files with 23 additions and 1 deletions

View file

@ -1,5 +1,5 @@
defmodule Microwaveprop.Weather.HrrrClientTest do
use ExUnit.Case, async: true
use ExUnit.Case, async: false
alias Microwaveprop.Weather.HrrrClient

View file

@ -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

View file

@ -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