Unknown database when running tests at root level of umbrella app

I have three apps in my umbrella app, one is the database and the other two have dependencies on that database. When I cd into each individual app, that apps’ tests pass. However, when I run all the tests at the root level, I receive the following database errors:

** (DBConnection.ConnectionError) connection not available because of disconnection
and
18:28:49.210 [error] Mariaex.Protocol (#PID<0.403.0>) failed to connect: ** (Mariaex.Error) (1049): Unknown database 'umbrella_app_test'

Any help is greatly appreciated. Thanks!

Below are my config & mix.es setups…


Test Config files

umbrella_app/apps/db/config/test.exs

use Mix.Config

config :db, DB.Repo,
  adapter: Ecto.Adapters.MySQL,
  database: "umbrella_app_test",
  username: System.get_env["MYSQL_USER"] || "root",
  password: System.get_env["MYSQL_PASSWORD"],
  hostname: System.get_env["MYSQL_HOST"] || "localhost",
  pool: Ecto.Adapters.SQL.Sandbox,
  priv: "priv/repo",
  port: System.get_env["MYSQL_PORT"] || "3306"

umbrella_app/apps/app_a/config/test.exs

use Mix.Config
config :app_b, ecto_repos: [DB.Repo]

umbrella_app/apps/app_b/config/test.exs

use Mix.Config
config :app_b, ecto_repos: [DB.Repo]

Mix.exs files

defmodule UmbrellaApp.Mixfile do
  use Mix.Project

  def project do
    [
      apps_path: "apps",
      start_permanent: Mix.env == :prod,
      deps: deps(),
      aliases: aliases()
    ]
  end

  defp deps do
    []
  end

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


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

      def application do
        [
          applications: [
            :cowboy,
            :plug,
            :db
          ],
          mod: {AppA, []}
        ]
      end

      defp deps do
        [
          {:cowboy, "~> 1.1"},
          {:plug, "~> 1.3"},
          {:db, in_umbrella: true}
        ]
      end

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

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

defmodule AppB.Mixfile do
  use Mix.Project

  def project do
    [
      app: :chemistry,
      version: "0.0.1",
      build_path: "../../_build",
      config_path: "../../config/config.exs",
      deps_path: "../../deps",
      lockfile: "../../mix.lock",
      elixir: "~> 1.4",
      elixirc_paths: elixirc_paths(Mix.env),
      compilers: [:phoenix, :gettext] ++ Mix.compilers,
      start_permanent: Mix.env == :prod,
      aliases: aliases(),
      deps: deps()
    ]
  end

  def application do
    [
      mod: {AppB.Application, []},
      extra_applications: [:logger, :runtime_tools, :phoenix_ecto, :db]
    ]
  end

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

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

  defp deps do
    [
      {:phoenix, "~> 1.3.0"},
      {:phoenix_pubsub, "~> 1.0"},
      {:phoenix_html, "~> 2.10"},
      {:phoenix_ecto, "~> 3.0"},
      {:phoenix_live_reload, "~> 1.0", only: :dev},
      {:gettext, "~> 0.11"},
      {:cowboy, "~> 1.0"},
      {:db, in_umbrella: true}
    ]
  end
end
1 Like

Wow. Such a simple and dumb mistake. I removed aliases() from the root Mix.exs file, and now I can run my tests from the root app.

4 Likes