Compare commits

...

1 commit

Author SHA1 Message Date
e9bcb25d20 Fix postgres errors when running tests
Some checks failed
continuous-integration/drone/push Build is failing
2025-12-03 14:44:20 +01:00
4 changed files with 18 additions and 2 deletions

View file

@ -45,3 +45,6 @@ config :mv, :token_signing_secret, "test_secret_key_for_ash_authentication_token
config :mv, :session_identifier, :unsafe config :mv, :session_identifier, :unsafe
config :mv, :require_token_presence_for_authentication, false config :mv, :require_token_presence_for_authentication, false
# Enable SQL Sandbox for async LiveView tests
config :mv, :sql_sandbox, true

View file

@ -39,6 +39,11 @@ defmodule MvWeb.Endpoint do
plug Phoenix.Ecto.CheckRepoStatus, otp_app: :mv plug Phoenix.Ecto.CheckRepoStatus, otp_app: :mv
end end
# Enable Ecto SQL Sandbox in test environment for async tests
if Application.compile_env(:mv, :sql_sandbox) do
plug Phoenix.Ecto.SQL.Sandbox
end
plug Phoenix.LiveDashboard.RequestLogger, plug Phoenix.LiveDashboard.RequestLogger,
param_key: "request_logger", param_key: "request_logger",
cookie_key: "request_logger" cookie_key: "request_logger"

View file

@ -123,7 +123,13 @@ defmodule MvWeb.ConnCase do
end end
setup tags do setup tags do
Mv.DataCase.setup_sandbox(tags) pid = Mv.DataCase.setup_sandbox(tags)
{:ok, conn: Phoenix.ConnTest.build_conn()}
conn = Phoenix.ConnTest.build_conn()
# Set metadata for Phoenix.Ecto.SQL.Sandbox plug to allow LiveView processes
# to share the test's database connection in async tests
conn = Plug.Conn.put_private(conn, :ecto_sandbox, pid)
{:ok, conn: conn}
end end
end end

View file

@ -34,10 +34,12 @@ defmodule Mv.DataCase do
@doc """ @doc """
Sets up the sandbox based on the test tags. Sets up the sandbox based on the test tags.
Returns the owner pid for use with Phoenix.Ecto.SQL.Sandbox.
""" """
def setup_sandbox(tags) do def setup_sandbox(tags) do
pid = Ecto.Adapters.SQL.Sandbox.start_owner!(Mv.Repo, shared: not tags[:async]) pid = Ecto.Adapters.SQL.Sandbox.start_owner!(Mv.Repo, shared: not tags[:async])
on_exit(fn -> Ecto.Adapters.SQL.Sandbox.stop_owner(pid) end) on_exit(fn -> Ecto.Adapters.SQL.Sandbox.stop_owner(pid) end)
pid
end end
@doc """ @doc """