matheus.almeida

matheus.almeida

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", ""}
  ]

Showing Posts 1 to 2

Hermanverschooten

Hermanverschooten

Aren’t the repos started in your supervision tree?

oliveiragahenrique

oliveiragahenrique

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

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
rahultumpala
Hello, I have an Elixir backend that implements a custom protocol over TCP. I want to load test the backend and assess the performance o...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews