For some reason PGListener.start_link: {:ok, #PID<0.343.0>} pg_listener starts during database tests, and not web tests … But it’s the same on localhost where tests pass.
use Mix.Config
# We don't run a server during test. If one is required,
# you can enable the server option below.
config :web, Web.Endpoint,
http: [port: 4001],
server: false
# Print only warnings and errors during test
config :logger, level: :warn
and neither do I do anything for test env in endpoint.ex
@doc """
Callback invoked for dynamically configuring the endpoint.
It receives the endpoint configuration and checks if
configuration should be loaded from the system environment.
"""
@spec init(atom, Keyword.t()) :: {:ok, Keyword.t()} | no_return
def init(_key, config) do
if config[:load_from_system_env] do
port = System.get_env("PORT") || raise("expected the PORT environment variable to be set")
secret_key_base =
System.get_env("SECRET_KEY_BASE") ||
raise("expected the SECRET_KEY_BASE environment variable to be set")
# inet6?
config =
config
|> Keyword.put(:http, [:inet6, port: port])
|> Keyword.put(:secret_key_base, secret_key_base)
{:ok, config}
else
{:ok, config}
end
end
Oh, I’ve missed localhost in localhost:5432! Now I have at least some idea of where to look …
Just in case, here’s rdb's app config/test.exs
use Mix.Config
config :logger, level: :warn
config :rdb, RDB.Repo,
pool: Ecto.Adapters.SQL.Sandbox,
pool_size: 20
if url = System.get_env("DATABASE_URL") do
IO.inspect(url, label: "config DATABASE_URL")
config :rdb, RDB.Repo, url: url
else
config :rdb, RDB.Repo,
database: "db_test",
hostname: "localhost"
end
and repo.ex
@doc """
Callback invoked for dynamically configuring the repo.
It receives the repo configuration and checks if
configuration should be loaded from the system environment.
"""
@spec init(atom, Keyword.t()) :: {:ok, Keyword.t()} | no_return
def init(_type, config) do
if config[:load_from_system_env] do
db_url =
System.get_env("DATABASE_URL") ||
raise("expected the DATABASE_URL environment variable to be set")
config = Keyword.put(config, :url, db_url)
{:ok, config}
else
{:ok, config}
end
end
It seems like postgrex doesn’t recognize :url (which is just for ecto?) option and falls back to its defaults. There is probably a function in ecto which parses the url and takes postgrex options out of it. Will try to use that.