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?

Where Next?

Popular in Questions Top

jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
Werner
Hi, I’m using Ubuntu 18.04 and after updating to OTP-24.0 yesterday i have this warning when I run “mix local.hex”: 14:57:30.512 [warn] ...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
gonzofish
I’m currently trying to understand how to join three tables using Ecto. All the examples I’ve seen use 2, so maybe I’m just missing somet...
New
chewm
Hi guys, nice to meet you to the whole forum, I’m new here, I’m trying to configure visual studio code for elixir, right now the intellis...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
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
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs &amp; Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3268 119930 1237
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
beno
I will often find my self writing things similar to: case some_value do nil -&gt; something() "" -&gt; something() _ -&gt; someth...
New

We're in Beta

About us Mission Statement