I'm learning to test in Elixir and this problem appeared:
When I run the following test, sometimes it passes and sometimes don't, I'm thinking it is the fact that the Supervisor don't have the time to restart the GenServer:
test "Supervisor will revive the dead gensever" do
{:ok, pid} = KV.Supervisor.start_link([])
KV.RegistryClient.create KV.RegistryClient, "wallet"
[h | _] = Supervisor.which_children(pid)
{KV.RegistryClient, pid_reg, _, _} = h
send(pid_reg, :insta_kill)
assert %{active: 1} = Supervisor.count_children(pid)
end
When occurs, this is the error:
1) test Supervisor will revive the dead gensever (KV.RegistryTest)
test/kv/registry_test.exs:35
match (=) failed
code: assert %{active: 1} = Supervisor.count_children(pid)
right: %{active: 0, specs: 1, supervisors: 0, workers: 1}
stacktrace:
test/kv/registry_test.exs:41: (test)
How do I prevent this to happen? A timeout is a good approach?