Umbrella app & Ecto: ExUnit DBConnection.OwnershipError

I have an umbrella application and am using Ecto, where one app is using GenServer processes for keeping mutable state for a queue, along with supervisors. When I run the tests for all umbrella applications together, after my first app is finished running, I receive a DBConnection.OwnershipError. This seems to be because the GenServer process loses access to its database. My application.ex looks like so:

defmodule MyProject.Application do
  use Application

  def start(_type, _args) do
    children = [
      Supervisor.child_spec({MyProject.Repo, []}, type: :supervisor),

    opts = [strategy: :rest_for_one, name: MyProject.Supervisor]
    IO.inspect("Application Successfully started")
    {:ok, _pid} = Supervisor.start_link(children, opts)

  def stop(_) do
    IO.inspect("Application Successfully Stopped")

Interestingly, the IO.inspect output appears for start/2 but not for stop/1. This makes me think Exunit does not call stop/1 and the “CallbackSupervisor” managing the GenServers is not being stopped before the Repo supervisor is. I do not have lots of knowledge about how ExUnit runs for umbrella apps, does anyone have insight on this?

No insight, but I believe I’ve seen this error as well in circleci for an umbrella project. I’ll be watching this discussion.

add this to your test_helper.ex

:ok = Ecto.Adapters.SQL.Sandbox.checkout(App.Repo)