小编use*_*226的帖子

在Elixir中测试主管的最佳实践

我用Google搜索了一下,无法找到关于这个问题的任何内容 - 无论是Elixir还是一个语言太年轻还是我用错误的术语搜索.

我正在研究Jose Valim的Elixir Portal教程(https://howistart.org/posts/elixir/1),并正在构建练习测试(我已经构建了所有功能).

本教程的一部分是构建一个Supervisor,使Portal.Door模块具有容错能力.

我正在尝试使用以下代码测试容错(例如,如果不正确关闭,Supervisor将重新启动Portal.Door实例)

defmodule PortalTest do
  use ExUnit.Case, async: true

  ...

  test "supervisor restarts doors" do 
    {:ok, pid} = Portal.shoot(:third)
    Process.unlink(pid)
    Process.exit(pid, :shutdown)
    assert Portal.Door.get(:third) == [] #new doors initialize with an empty array
  end

end
Run Code Online (Sandbox Code Playgroud)

但是当我运行测试时,我不断收到此错误:

  1) test supervisor restarts doors (PortalTest)
     test/portal_test.exs:35
     ** (exit) exited in: GenServer.call(:third, {:get, #Function<3.47016826/1 in Portal.Door.get/1>}, 5000)
         ** (EXIT) shutdown
     stacktrace:
       (elixir) lib/gen_server.ex:356: GenServer.call/3
       test/portal_test.exs:39
Run Code Online (Sandbox Code Playgroud)

所以,我想知道是否有更好的方法来做到这一点,或者我的代码是坏的.

elixir

5
推荐指数
1
解决办法
2154
查看次数

标签 统计

elixir ×1