I have two apps into an umbrella project: the first one is Database, which manages queries, and the secon one is an app, which uses some functions from the Database app to check information from the database. I am getting the next error when trying to run tests for functions in the second one which uses functions from the Database app:
** (RuntimeError) could not lookup Ecto repo Repo because it was not started or it does not exist
and this is the setup that I have for my tests:
setup do
:ok = Ecto.Adapters.SQL.Sandbox.checkout(Repo)
end
No and yes. Actually I am trying to create a DDD project and Database app is a dependency of another which is conected to database and is in the middle of Database and the app that I want to test (The app that I want to test is not connected directly with database). It is something like this:
I’m also experiencing this issue. and @dogweather’s solution didn’t help.
Can anyone please suggest how to fix this?
This is really weird.
My app is simple (non-umbrella) with the following relevant deps:
{:phoenix, “~> 1.5.1”},
{:phoenix_ecto, “~> 4.1”},
{:ecto_sql, “~> 3.4”},
{:postgrex, “>= 0.0.0”},
BTW, my OS :
Linux 4.15.0-1-amd64 #1 SMP Debian 4.15.4-1~mx17+1 (2018-02-23) x86_64 GNU/Linux
I had quite a few of those while working on the test exercising upserts - Repo.insert(on_conflict: :nothing, returning: true, conflict_target: [:sku, :lastmod])
As soon as I was done with the test the error went away
Coming into a legacy umbrella project, the error message turned out to be pointing me in the correct direction to solve the problem:
mix.exs
def application do
[
mod: {YourProjectWeb.Application, []}, # had to re-add this line to existing umbrella application
extra_applications: [:logger, :runtime_tools]
]
end
At some point, the supervision tree was disabled for whatever, I just needed to re-enable it. (Hopefully that doesn’t break something else…)
This is a pretty niche solution, but hopefully it is helpful to someone who gets stuck in the same quagmire.
I had the same issue, and it is now fixed. mix ecto.reset or anything else were absolutely not helping.
Basically what happened, were GenServer I was removing from my supervision tree during tests; but were called anyway during tests, leading to an error that crashed the Repo process.
To fix this, figure out a way to have a GenServer replying or doing the business where it is called (mocking, stubbing, whatever suits your need)