matheus.almeida

matheus.almeida

Getting error: could not lookup Ecto repo Raven.Repo because it was not started or it does not exist

Hello everybody, I’m currently working on a project that has around 200+ test files. I’m running the tests using the following command:

mix test <path_to_folder> --seed=0

I’m using --seed=0 to ensure that the order of all executions remains the same.

Now, my problem is quite strange. When I run a test by specifying a single .exs file, it works perfectly. However, when I run the command on the entire folder, it fails.

To be more specific, I’ve done some testing and confirmed that the issue is not caused by the other tests themselves. When I run the command on the folder, the number of failing tests changes—sometimes it’s 50, other times it’s 70. But when I run those same tests individually, they all pass.

I’ve already tried running mix ecto.reset, but that didn’t resolve the problem (and the command itself runs without any issues).

Does anyone have an idea of what could be causing this?

This is my test_helper.ex

ExUnit.start()

{:ok, _} = Application.ensure_all_started(:ex_machina)
{:ok, _} = Application.ensure_all_started(:raven)

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

-configs related to the Raven.Repo in the config.ex

config :raven,
  ecto_repos: [Raven.Repo, Raven.Repo.ReadReplica],
  whitelabel_lambda_url: "url"

config :raven, Oban,
  repo: Raven.Repo,
  plugins: [
    {Oban.Plugins.Pruner, max_age: 60 * 60 * 24 * 7},
    {Oban.Plugins.Lifeline, rescue_after: :timer.minutes(30)},
    {Oban.Plugins.Cron,
     crontab: [
       {"0 4 * * *", Timeline.FutureTransaction.Worker, max_attempts: 3},
       {"0 5 * * *", Raven.Workers.InsightDeactivationWorker, max_attempts: 3}
     ]}
  ],
  queues: [
    default: 10,
    sms_notifications: 10,
    email_notifications: 10,
    verify_user_configs: 10,
    push_notifications: 10,
    routine_jobs: 1
  ]

config :raven, Raven.Repo,
  database: "database",
  username: "username",
  password: "password",
  hostname: "localhost"

config :turbo_ecto, Turbo.Ecto,
  repo: Raven.Repo,
  per_page: 10
  • I have some auxiliary classes, and one of them is Raven.DataCase. This is the file responsible for handling setting up the repo, which I believe is correct.

  use ExUnit.CaseTemplate, async: false

  using do
    quote do
      alias Raven.Repo

      import Ecto
      import Ecto.Changeset
      import Ecto.Query
      import Raven.DataCase
      import Factory
    end
  end

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

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

    :ok
  end

  def errors_on(changeset) do
    Ecto.Changeset.traverse_errors(changeset, fn {message, opts} ->
      Regex.replace(~r"%{(\w+)}", message, fn _, key ->
        opts |> Keyword.get(String.to_existing_atom(key), key) |> to_string()
      end)
    end)
  end
end

My environment is set to test, which I believe is correct. I’m using a local database. This is the file:

import Config

# Configure your databases
repos = [
  Raven.Repo,
  Raven.Repo.ReadReplica
]

for repo <- repos do
  config :raven, repo,
    username: "username",
    password: "password",
    database: "database",
    hostname: "localhost",
    pool: Ecto.Adapters.SQL.Sandbox,
    queue_interval: 1_000,
    parameters: [
      tcp_keepalives_idle: "60",
      tcp_keepalives_interval: "5",
      tcp_keepalives_count: "3"
    ],
    socket_options: [keepalive: true]
end

config :junit_formatter,
  report_file: "report_file_test.xml",
  report_dir: Path.absname("test_result"),
  print_report_file: true,
  prepend_project_name?: true,
  include_filename?: true

# We don't run a server during test. If one is required,
# you can enable the server option below.
config :raven, RavenWeb.Endpoint,
  http: [port: 4002, compress: true],
  server: false

config :raven, Raven.Tracer, disabled?: true

## Print only warnings and errors during test
config :logger, level: :warning

config :daily_balance,
  supress_consumers: true

config :timeline,
  supress_consumers: true

config :raven,
  supress_consumers: true,
  supress_tracking: true,
  supress_fcm: true,
  supress_oban: true

# config :raven, :repo_api, Raven.Utils.MockRepo
config :raven, :repo_api, Raven.Repo

config :unleash_fresha, Unleash,
  url: "http://localhost/api/",
  appname: "raven",
  features_period: 60 * 60 * 1000,
  strategies: Unleash.Strategies,
  disable_client: true,
  disable_metrics: true,
  retries: -1,
  app_env: :dev,
  custom_http_headers: [
    {"authorization", ""}
  ]

First Post!

Hermanverschooten

Hermanverschooten

Aren’t the repos started in your supervision tree?

Last Post!

oliveiragahenrique

oliveiragahenrique

I think a snippet of your code in the application.ex could help here.

Where Next?

Popular in Questions Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
Lily
In templates/appointment/index.html.eex: &lt;%= for appointment &lt;- @appointments do %&gt; &lt;tr&gt; &lt;td&gt;&lt;%= appoi...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New

Other popular topics Top

Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 44139 214
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New

We're in Beta

About us Mission Statement