Testing an ecto_sqlite3 in an umbrella project

Hello there

I’m new to Elixir and building a simple app to get more familiar with it.
I have an umbrella project with two applications, one of the applications :fetcher_service calls external APIs and was just scaffolded,
and the other :db_service uses Ecto to persist data with ecto_sqlite3. It uses a GenServer to provide access the Repo for simple Crud operations.

I’m running into the following error when trying to run my tests:

mix test
Config runs
==> fetcher_service
Compiling 3 files (.ex)
Generated fetcher_service app
==> db_service
Generated db_service app
==> fetcher_service
There are no tests to run
** (DBConnection.ConnectionError) could not checkout the connection owned by #PID<0.360.0>. When using the sandbox, connections are shared, so this may imply another process is using a connection. Reason: connection not available and request was dropped from queue after 2873ms. This means requests are coming in and your connection pool cannot serve them fast enough. You can address this by:

  1. Ensuring your database is available and that you can connect to it
  2. Tracking down slow queries and making sure they are running fast enough
  3. Increasing the pool_size (although this increases resource consumption)
  4. Allowing requests to wait longer by increasing :queue_target and :queue_interval

See DBConnection.start_link/2 for more information

    (db_connection 2.6.0) lib/db_connection.ex:1059: DBConnection.transaction/3
    (ecto_sql 3.11.2) lib/ecto/migrator.ex:354: Ecto.Migrator.run_maybe_in_transaction/5
    (elixir 1.15.7) lib/task/supervised.ex:101: Task.Supervised.invoke_mfa/2
    (elixir 1.15.7) lib/task/supervised.ex:36: Task.Supervised.reply/4

I’m assuming there is a race condition or a thread is blocked, when running tests but I do not find documentation on configuring tests for Ecto with SQLite, in an umbrella project.

The database setup runs for both applications, first for :fetcher_service which has no tests at all and I want it to know nothing about Ecto and the database. I simply do not want to run database tests there, but not sure how I exclude it inside an umbrella project.
I configured Ecto only for the :db_service application that uses it.

1. Config.exs:

import Config

config :db_service, ecto_repos: [DBService.Repo]

import_config "#{config_env()}.exs"

2. test.exs (test config env)

import Config

config :db_service, DBService.Repo,
 database: ":memory:",
 pool: Ecto.Adapters.SQL.Sandbox,
 pool_size: 1

I am using an in-memory database, (only pools size 1 is allowed) because I don’t want to create files during testing.

3. :db_service mix.exs:

defmodule DBService.MixProject do
  use Mix.Project

  def project do
    [
      app: :db_service,
      version: "0.1.0",
      build_path: "../../_build",
      config_path: "../../config/config.exs",
      deps_path: "../../deps",
      lockfile: "../../mix.lock",
      elixir: "~> 1.15",
      start_permanent: Mix.env() == :prod,
      deps: deps(),
      aliases: aliases(),
      elixirc_paths: elixirc_paths(Mix.env())
    ]
  end

  # Run "mix help compile.app" to learn about applications.
  def application do
    [
      extra_applications: [:logger],
      mod: {DBService.Application, []}
    ]
  end

  # Run "mix help deps" to learn about dependencies.
  defp deps do
    [
      # {:dep_from_hexpm, "~> 0.3.0"},
      # {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"},
      # {:sibling_app_in_umbrella, in_umbrella: true}
      {:ecto_sql, "~> 3.0"},
      {:ecto_sqlite3, "~> 0.13"}
    ]
  end

    defp elixirc_paths(:test), do: ["lib", "test/support"]
    defp elixirc_paths(_), do: ["lib"]

  defp aliases do
    [
      test: ["ecto.create --quiet", "ecto.migrate", "test"]
    ]
  end
end

The :fetcher_service has as simple mix.exs, that was just scaffolded.

4.Tests:

test_helper.exs

ExUnit.start()

Ecto.Adapters.SQL.Sandbox.mode(DBService.Repo, :manual)

test/support/repo_case.ex

defmodule DBService.RepoCase do
    use ExUnit.CaseTemplate

    using do
        quote do
            alias DBService.Repo

            import Ecto
            import Ecto.Query
            import DBService.RepoCase

            # and other stuff if needed
        end
    end

    setup tags do
        :ok = Ecto.Adapters.SQL.Sandbox.checkout(DBService.Repo)

        unless tags[:async] do
            Ecto.Adapters.SQL.Sandbox.mode(DBService.Repo, {:shared, self()})
        end

        :ok
    end
end

And finally the single test case I could not even run:

defmodule DBServiceTest do
   use DBService.RepoCase
   use ExUnit.Case

  test "db_service test" do
  end
end

Documentation I used:
https://hexdocs.pm/ecto/testing-with-ecto.html

I can run everything using iex -S mix, so I manually verified the application works
the dev.exs config is:config :db_service, DBService.Repo, database: "./db/dbservice.db"

Any help is appreciated! Thanks!