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
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:
parent
9fd2622550
commit
ec1df7a4df
3 changed files with 23 additions and 1 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
defmodule Microwaveprop.Weather.HrrrClientTest do
|
defmodule Microwaveprop.Weather.HrrrClientTest do
|
||||||
use ExUnit.Case, async: true
|
use ExUnit.Case, async: false
|
||||||
|
|
||||||
alias Microwaveprop.Weather.HrrrClient
|
alias Microwaveprop.Weather.HrrrClient
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1327,12 +1327,25 @@ defmodule Microwaveprop.WeatherTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "available_weather_valid_times/0" do
|
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
|
test "returns an empty list when no scores are stored" do
|
||||||
assert Weather.available_weather_valid_times() == []
|
assert Weather.available_weather_valid_times() == []
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "latest_grid_valid_time/0" do
|
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
|
test "returns nil when no scores are stored" do
|
||||||
assert Weather.latest_grid_valid_time() == nil
|
assert Weather.latest_grid_valid_time() == nil
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,21 @@ defmodule MicrowavepropWeb.ContactMapControllerTest do
|
||||||
use MicrowavepropWeb.ConnCase, async: false
|
use MicrowavepropWeb.ConnCase, async: false
|
||||||
|
|
||||||
alias Microwaveprop.Cache
|
alias Microwaveprop.Cache
|
||||||
|
alias MicrowavepropWeb.Api.RateLimiter
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
# The controller caches a gzipped payload under a module-level key —
|
# The controller caches a gzipped payload under a module-level key —
|
||||||
# clear it between tests so gzip vs identity requests don't reuse
|
# clear it between tests so gzip vs identity requests don't reuse
|
||||||
# each other's output.
|
# each other's output.
|
||||||
Cache.invalidate({MicrowavepropWeb.ContactMapController, :gzipped_payload})
|
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
|
:ok
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue