fix: Subscription workers restart strategy, sandbox ownership race condition
Some checks failed
CI / Test (OTP 27.2 / Elixir 1.18.2) (push) Failing after 0s
CI / Test (OTP 28.4 / Elixir 1.19.4 + Marmot E2E) (push) Failing after 0s

This commit is contained in:
2026-03-17 18:49:50 +01:00
parent e13c08fd5a
commit 65b47ec191
3 changed files with 31 additions and 3 deletions

View File

@@ -30,11 +30,38 @@ defmodule Parrhesia.IntegrationCase do
:ok = Sandbox.checkout(Repo)
:shared ->
:ok = Sandbox.checkout(Repo)
Sandbox.mode(Repo, {:shared, self()})
# Delegate sandbox ownership to a dedicated process that outlives
# the test process. ExUnit terminates start_supervised! children
# (in reverse start order) before running on_exit callbacks. With
# the test process as sandbox owner, the connection dies the
# moment the test process exits — supervised children that make
# DB calls during their shutdown sequence would hit a dead
# connection. The separate owner stays alive through the entire
# supervised-child shutdown, and is only stopped in on_exit
# (which runs afterwards).
test_pid = self()
owner =
spawn(fn ->
:ok = Sandbox.checkout(Repo)
send(test_pid, {:sandbox_ready, self()})
receive do
:stop -> :ok
end
end)
receive do
{:sandbox_ready, ^owner} -> :ok
after
5_000 -> raise "Sandbox owner checkout timed out"
end
Sandbox.mode(Repo, {:shared, owner})
on_exit(fn ->
Sandbox.mode(Repo, :manual)
send(owner, :stop)
end)
end

View File

@@ -6,6 +6,7 @@ defmodule Parrhesia.TestSupport.Runtime do
Parrhesia.Config,
Parrhesia.Repo,
Parrhesia.Subscriptions.Supervisor,
Parrhesia.API.Stream.Supervisor,
Parrhesia.Web.Endpoint
]