I am trying to configure a Phoenix Ecto app for testing using the example from the docs.
Problem: Each time I run mix test
, even when localized to a test that does not require DB access, I receive an error:
16:47:43.083 [error] Postgrex.Protocol (#PID<0.312.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (localhost:5432): connection refused - :econnrefused
** (Mix) The database for MyApp.Repo couldn't be created: connection not available and request was dropped from queue after 2000ms. This means requests are coming in and your connection pool cannot serve them fast enough. You can address this by:
Following this error, it appears as if no unit tests are run.
What I’ve done: In my config/test.exs
file, I have the following:
config :my_app, MyApp.Repo,
username: "postgres",
password: "password",
hostname: "localhost",
database: "daxta_server_test#{System.get_env("MIX_TEST_PARTITION")}",
pool: Ecto.Adapters.SQL.Sandbox,
pool_size: 10
In my mix.exs
file I have:
use Mix.Project
def project do
[
app: :daxta_server,
version: "0.1.0",
elixir: "~> 1.14",
elixirc_paths: elixirc_paths(Mix.env()),
start_permanent: Mix.env() == :prod,
aliases: aliases(),
deps: deps()
]
end
def application do
[
mod: {MyApp.Application, []},
extra_applications: [:logger, :runtime_tools]
]
end
# Specifies which paths to compile per environment.
defp elixirc_paths(:test), do: ["lib", "test/support"]
defp elixirc_paths(_), do: ["lib"]
Within test/support
I have a file repo_case.ex
where I checkout the SQL sandbox, but for the test I’m running I don’t call this, as I am not testing anything Ecto related.
I received a suggestion to add the --no_start
tag to the mix test command, but that sounds hacky. I’m sure that there’s a better way to set this up, and I’m just missing some fundamental configuration setting.
Any help is appreciated!