【问题标题】:Wallaby Ecto.Registry.lookup error小袋鼠 Ecto.Registry.lookup 错误
【发布时间】:2017-11-23 16:05:51
【问题描述】:

我正在尝试让 Wallaby 参与新的 Phoenix 项目。我已按照自述文件中的设置说明进行操作,但是当我尝试运行基本测试时,出现 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

这是失败的测试:

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

这是功能案例:

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

这是我的设置更改的整个 PR:https://github.com/marcdel/wallaby_test/pull/1/files

我正在使用 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)

【问题讨论】:

  • 请告诉我们features/home_page_test.exs:6周围的上下文。
  • @mudasobwa 添加了!

标签: elixir phoenix-framework wallaby


【解决方案1】:

这当然不是您的测试套件的问题,因为在使用 Elixir 1.5 或更高版本以及 Phoenix 1.3 时,此问题非常常见。可能在日志的上方某处,您可能会发现类似这样的内容:

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

尝试为TEST 环境运行所有迁移,然后重新运行测试。你可以用一个命令来做到这一点:

MIX_ENV=test mix ecto.reset && mix test

ecto.reset 将重置您的数据库(检查您的mix.exs 文件),这是重新创建数据库、迁移它并再次运行种子的别名。

【讨论】:

  • 不幸的是,没有骰子。在/usr/local/var/log/postgres.log 中,我在重置和运行测试时看到以下内容:ERROR: database "cheese_log_test" already exists STATEMENT: CREATE DATABASE "cheese_log_test" ENCODING 'UTF8'
  • 这就是原因。您的 psql 帐户无法删除此数据库,可能也没有其他权限,因此您的 repo 测试不起作用。在错误日志中,很明显 ecto 是测试失败的原因。
【解决方案2】:

原来是复制/粘贴问题?

我的 repo 在一个单独的应用程序中,因此在 FeatureCase 中我将 WallabyTestWeb.Repo 替换为 WallabyTest.Repo,现在测试很顺利!

e:提示是我只在运行测试时在日志中收到 Postgres 错误,而不是在执行 mix ecto.reset 时。

【讨论】:

    猜你喜欢
    • 2018-01-04
    • 2016-05-05
    • 1970-01-01
    • 2022-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-24
    相关资源
    最近更新 更多