Recently I start getting this flaky issue running Ecto tests.
** (MatchError) no match of right hand side value: 
{:error, {:undef, [{MyApp.Repo, :get_dynamic_repo, [], []}, 
{Ecto.Adapters.SQL.Sandbox, :lookup_meta!, 1, [file: ~c"lib/ecto/adapters/sql/sandbox.ex", line: 580]}, 
{Ecto.Adapters.SQL.Sandbox, :checkout, 2, [file: ~c"lib/ecto/adapters/sql/sandbox.ex", line: 494]}, 
{Ecto.Adapters.SQL.Sandbox, :"-start_owner!/2-fun-0-", 3, [file: ~c"lib/ecto/adapters/sql/sandbox.ex", line: 416]}, 
{Agent.Server, :init, 1, [file: ~c"lib/agent/server.ex", line: 8]}, {:gen_server, :init_it, 2, [file: ~c"gen_server.erl", line: 962]}, 
{:gen_server, :init_it, 6, [file: ~c"gen_server.erl", line: 917]}, 
{:proc_lib, :init_p_do_apply, 3, [file: ~c"proc_lib.erl", line: 241]}]}}
I couldn’t find out the root cause of this error. since there’s no major change in the configs of the sandbox.
# lib/my_app/repo.ex
defmodule MyApp.Repo do
  use Ecto.Repo,
    otp_app: :my_app,
    adapter: Ecto.Adapters.Postgres
end
# config/test.exs
config :my_app, MyApp.Repo,
  url: @default_db_url,
  pool: Ecto.Adapters.SQL.Sandbox,
  pool_size: 10,
  ownership_timeout: 360_000
# test/support/data_case.ex
defmodule MyApp.DataCase do
use ExUnit.CaseTemplate
  alias Ecto.Adapters.SQL.Sandbox
  using do
    quote do
      alias MyApp.Repo
      import Ecto
      import Ecto.Changeset
      import Ecto.Query
      import MyApp.DataCase
      import MyApp.Factory
    end
  end
  setup tags do
    MyApp.DataCase.setup_sandbox(tags)
    :ok
  end
  def setup_sandbox(tags) do
    pid = Sandbox.start_owner!(MyApp.Repo, shared: not tags[:async])
    on_exit(fn -> Sandbox.stop_owner(pid) end)
  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
can someone give some hands on this issue. I tried to tweak configs left and right, but the only thing get it works is to get rid of sandbox setup (which means get rid of the failing statement) and change it following Ecto documnentation
# test/support/data_case.ex
 setup tags do
    :ok = Ecto.Adapters.SQL.Sandbox.checkout(MyApp.Repo)
    unless tags[:async] do
      Ecto.Adapters.SQL.Sandbox.mode(MyApp.Repo, {:shared, self()})
    end
    :ok
  end
Any thoughts.





















