fix: Subscription workers restart strategy, sandbox ownership race condition
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
defmodule Parrhesia.API.Stream.Subscription do
|
||||
@moduledoc false
|
||||
|
||||
use GenServer
|
||||
use GenServer, restart: :temporary
|
||||
|
||||
alias Parrhesia.Protocol.Filter
|
||||
alias Parrhesia.Subscriptions.Index
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ defmodule Parrhesia.TestSupport.Runtime do
|
||||
Parrhesia.Config,
|
||||
Parrhesia.Repo,
|
||||
Parrhesia.Subscriptions.Supervisor,
|
||||
Parrhesia.API.Stream.Supervisor,
|
||||
Parrhesia.Web.Endpoint
|
||||
]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user