简体   繁体   中英

Wallaby Ecto.Registry.lookup error

I'm trying to get Wallaby working on a new Phoenix project. I've followed the setup instructions in the readme, but when I try to run a basic test I get an Ecto registry error:

1) test home page has welcome message (WallabyTestWeb.HomePageTest)
     test/wallaby_test_web/features/home_page_test.exs:6
     ** (ArgumentError) argument error
     stacktrace:
       (stdlib) :ets.lookup_element(Ecto.Registry, nil, 3)
       (ecto) lib/ecto/registry.ex:18: Ecto.Registry.lookup/1
       (ecto) lib/ecto/adapters/sql/sandbox.ex:529: Ecto.Adapters.SQL.Sandbox.proxy_pool/1
       (ecto) lib/ecto/adapters/sql/sandbox.ex:469: Ecto.Adapters.SQL.Sandbox.checkout/2
       (wallaby_test) test/support/feature_case.ex:18: WallabyTestWeb.FeatureCase.__ex_unit_setup_0/1
       (wallaby_test) test/support/feature_case.ex:1: WallabyTestWeb.FeatureCase.__ex_unit__/2
       test/wallaby_test_web/features/home_page_test.exs:1: WallabyTestWeb.HomePageTest.__ex_unit__/2

Here's the failing test:

defmodule WallabyTestWeb.HomePageTest do
  use WallabyTestWeb.FeatureCase, async: true

  import Wallaby.Query

  test "home page has welcome message", %{session: session} do
    require IEx
    IEx.pry()

    session
    |> visit("/")
    |> assert_has(css("h2", text: "Welcome to Phoenix!"))
  end
end

Here's the feature case:

defmodule WallabyTestWeb.FeatureCase do
  use ExUnit.CaseTemplate

  using do
    quote do
      use Wallaby.DSL

      alias WallabyTestWeb.Repo
      import Ecto
      import Ecto.Changeset
      import Ecto.Query

      import WallabyTestWeb.Router.Helpers
    end
  end

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

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

    metadata = Phoenix.Ecto.SQL.Sandbox.metadata_for(WallabyTestWeb.Repo, self())
    {:ok, session} = Wallaby.start_session(metadata: metadata)
    {:ok, session: session}
  end
end

Here's the entire PR with my setup changes: https://github.com/marcdel/wallaby_test/pull/1/files

I'm using Elixir 1.6, PhantomJs 2.1.1.

$ elixir --version
Erlang/OTP 20 [erts-9.1.4] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Elixir 1.6.0-dev (882c2bd) (compiled with OTP 20)

$ brew info phantomjs
phantomjs: stable 2.1.1 (bottled)

It's certainly not the issue with your test suite, because this issue is quite frequent when using Elixir 1.5 or higher and Phoenix 1.3. Propably somewhere above in logs you might find something like this:

** (DBConnection.OwnershipError) cannot find ownership process for 
#PID....

Try to run all the migrations for TEST environment and then re-run the tests. You can do it with one command:

MIX_ENV=test mix ecto.reset && mix test

ecto.reset will reset your database (check your mix.exs file), which is an alias for recreating your database, migrating it and running seeds again.

Turns out it was a copy/paste issue 😞

My repo is in a separate app so in FeatureCase I replaced WallabyTestWeb.Repo with WallabyTest.Repo , and now the tests are happy!

e: the tip off was that I was only getting Postgres errors in the logs when running the test, not when doing mix ecto.reset .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM