test: cap DB pool + ExUnit max_cases via POOL_SIZE for CI

2e92cf0 · gmorell · 2026-06-27 15:19

4 files +10 -2

Files changed

modified config/test.exs
+4 −1
@@ -18,7 +18,10 @@ config :feed_pug, FeedPug.Repo,
18 18 port: String.to_integer(System.get_env("DB_PORT") || "5432"),
19 19 database: "feed_pug_test#{System.get_env("MIX_TEST_PARTITION")}",
20 20 pool: Ecto.Adapters.SQL.Sandbox,
21 − pool_size: System.schedulers_online() * 2
21 + # One sandbox connection per concurrent async test. On a many-core CI runner
22 + # this can exceed Postgres' max_connections (default 100) — cap it there with
23 + # POOL_SIZE. test_helper.exs keeps ExUnit's max_cases in lockstep.
24 + pool_size: String.to_integer(System.get_env("POOL_SIZE") || "#{System.schedulers_online() * 2}")
22 25
23 26 # We don't run a server during test. If one is required,
24 27 # you can enable the server option below.
modified test/test_helper.exs
+6 −1
@@ -1,2 +1,7 @@
1 −ExUnit.start()
1 +# Cap ExUnit's concurrency at the Repo pool size so async tests never wait on a
2 +# sandbox connection (each owns one for its duration). Without this, the default
3 +# `max_cases` (= cores × 2) on a many-core runner outruns a capped `POOL_SIZE`.
4 +max_cases = Application.get_env(:feed_pug, FeedPug.Repo)[:pool_size]
5 +
6 +ExUnit.start(max_cases: max_cases)
2 7 Ecto.Adapters.SQL.Sandbox.mode(FeedPug.Repo, :manual)

Parents: 12d5381