简体   繁体   English

小袋鼠Ecto.Registry.lookup错误

[英]Wallaby Ecto.Registry.lookup error

I'm trying to get Wallaby working on a new Phoenix project. 我正在尝试让Wallaby从事新的Phoenix项目。 I've followed the setup instructions in the readme, but when I try to run a basic test I get an Ecto registry error: 我已经按照自述文件中的设置说明进行操作,但是当我尝试运行基本测试时,出现Ecto注册表错误:

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 这是我的设置更改的整个PR: https : //github.com/marcdel/wallaby_test/pull/1/files

I'm using Elixir 1.6, PhantomJs 2.1.1. 我正在使用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. 测试套件当然不是问题,因为在使用Elixir 1.5或更高版本以及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. 尝试为TEST环境运行所有迁移,然后重新运行测试。 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. ecto.reset将重置您的数据库(检查mix.exs文件),这是用于重新创建数据库,迁移数据库并再次运行种子的别名。

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! 我的存储库位于单独的应用程序中,因此在FeatureCase中,我用WallabyTestWeb.Repo替换了WallabyTest.Repo ,现在测试很高兴!

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 . e:提示是,在运行测试时,我仅在日志中收到Postgres错误,而不是在进行mix ecto.reset

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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