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

8fec077 · gmorell · 2026-06-27 15:19

4 files +10 -2

Files changed

modified config/test.exs
+4 −1
@@ -15,7 +15,10 @@ config :diogramos, Diogramos.Repo,
15 15 port: 54329,
16 16 database: "diogramos_test#{System.get_env("MIX_TEST_PARTITION")}",
17 17 pool: Ecto.Adapters.SQL.Sandbox,
18 − pool_size: System.schedulers_online() * 2
18 + # One sandbox connection per concurrent async test. On a many-core CI runner
19 + # this can exceed Postgres' max_connections (default 100) — cap it there with
20 + # POOL_SIZE. test_helper.exs keeps ExUnit's max_cases in lockstep.
21 + pool_size: String.to_integer(System.get_env("POOL_SIZE") || "#{System.schedulers_online() * 2}")
19 22
20 23 # We don't run a server during test. If one is required,
21 24 # 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(:diogramos, Diogramos.Repo)[:pool_size]
5 +
6 +ExUnit.start(max_cases: max_cases)
2 7 Ecto.Adapters.SQL.Sandbox.mode(Diogramos.Repo, :manual)

Parents: 08f0a00