Skip to content

Commit 6d72c18

Browse files
authored
Prevent Salts server from dirty postgres disconnects during tests (#5968)
1 parent f7027b5 commit 6d72c18

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

test/support/conn_case.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ defmodule PlausibleWeb.ConnCase do
4040
Ecto.Adapters.SQL.Sandbox.mode(Plausible.Repo, {:shared, self()})
4141
end
4242

43+
Plausible.Test.Support.Sandbox.allow_salts_process()
44+
4345
# randomize client ip to avoid accidentally hitting
4446
# rate limiting during tests
4547
conn =

test/support/data_case.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ defmodule Plausible.DataCase do
3737
Ecto.Adapters.SQL.Sandbox.mode(Plausible.Repo, {:shared, self()})
3838
end
3939

40+
Plausible.Test.Support.Sandbox.allow_salts_process()
41+
4042
:ok
4143
end
4244
end

test/support/plugins_api_case.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ defmodule PlausibleWeb.PluginsAPICase do
4141
Ecto.Adapters.SQL.Sandbox.mode(Plausible.Repo, {:shared, self()})
4242
end
4343

44+
Plausible.Test.Support.Sandbox.allow_salts_process()
45+
4446
conn = Phoenix.ConnTest.build_conn()
4547

4648
site = Plausible.Teams.Test.new_site()

test/support/sandbox.ex

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
defmodule Plausible.Test.Support.Sandbox do
2+
@moduledoc """
3+
Prevent background processes from interfering with tests
4+
(e.g. exiting before properly returning the connection) by allowing them to access sandbox
5+
"""
6+
def allow_salts_process do
7+
case Process.whereis(Plausible.Session.Salts) do
8+
nil ->
9+
:ok
10+
11+
pid ->
12+
Ecto.Adapters.SQL.Sandbox.allow(Plausible.Repo, self(), pid)
13+
end
14+
end
15+
end

0 commit comments

Comments
 (0)