Error after following Elixir guides on Mix and OTP (ETS section)

erlang
otp
troubleshooting

#1

Following the Elixir guides on Mix and OTP, at the ETS chapter, using mix test gives me the error below. I set mix test --timeout 300000 but still get the error - what happened?

  1. test removes buckets on exit (KV.RegistryTest)
    test/kv/registry_test.exs:19
    ** (exit) exited in: GenServer.call(:“test removes buckets on exit”, {:create, “shopping”}, 5000)
    ** (EXIT) an exception was raised:
    ** (ErlangError) Erlang error: :timeout_value
    (stdlib) gen_server.erl:389: :gen_server.loop/7
    (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
    code: KV.Registry.create(registry, “shopping”)
    stacktrace:
    (elixir) lib/gen_server.ex:774: GenServer.call/3
    test/kv/registry_test.exs:20: (test)
  1. test spawns buckets (KV.RegistryTest)
    test/kv/registry_test.exs:9
    ** (exit) exited in: GenServer.call(:“test spawns buckets”, {:create, “shopping”}, 5000)
    ** (EXIT) an exception was raised:
    ** (ErlangError) Erlang error: :timeout_value
    (stdlib) gen_server.erl:389: :gen_server.loop/7
    (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
    code: KV.Registry.create(registry, “shopping”)
    stacktrace:
    (elixir) lib/gen_server.ex:774: GenServer.call/3
    test/kv/registry_test.exs:12: (test)
  1. test removes bucket on crash (KV.RegistryTest)
    test/kv/registry_test.exs:28
    ** (exit) exited in: GenServer.call(:“test removes bucket on crash”, {:create, “shopping”}, 5000)
    ** (EXIT) an exception was raised:
    ** (ErlangError) Erlang error: :timeout_value
    (stdlib) gen_server.erl:389: :gen_server.loop/7
    (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
    code: KV.Registry.create(registry, “shopping”)
    stacktrace:
    (elixir) lib/gen_server.ex:774: GenServer.call/3
    test/kv/registry_test.exs:29: (test)

Finished in 0.06 seconds


#2

I would bet that you are returning the wrong tuple from the handle_call command in the KV.Registry implementation. If you share your code, we would be able to confirm it.


#3

yes, I got the wrong return, it should be reply, i write the noreply, thanks for your reply.
def handle_call({:create, name}, _from, {names, refs}) do
case lookup(names, name) do
{:ok, pid} ->
{:noreply, pid, {names, refs}}
:error ->
{:ok, pid} = KV.BucketSupervisor.start_bucket()
ref = Process.monitor(pid)
refs = Map.put(refs, ref, name)
:ets.insert(names, {name, pid})
{:noreply, pid, {names, refs}}
end
end