Failing tests following along with Genserver Guide

Pretty much following along with the guide for the genserver, though using a different type of map for the “buckets”. I keep getting this error here:

  1) test spawns viewports (ViewportRegistryTest)
     test/lib/viewport_registry_test.exs:10
     ** (EXIT from #PID<0.309.0>) 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

The error doesn’t mean much to me since it doesn’t include anything but the test that is failing.

test/lib/viewport_registry_test.exs:10:

  test "spawns viewports", %{registry: registry, hex: hex} do
    assert ViewportRegistry.lookup(registry, "xibalba") == :error
    ViewportRegistry.create(registry, "xibalba")
    assert {:ok, viewport} = ViewportRegistry.lookup(registry, "xibalba")

    Viewport.put(viewport, hex, 1)
    assert Viewport.get(viewport, hex) == 1
  end

The thing I find surprising though, is that if I enter in all the lines of the test individually in iex everything evaluates just fine, but it fails when I run mix test.

Might there be cleanup I need to do?

This could of course be a bug in the guide but assuming the guide is correct it’s very hard to say what is wrong in your code without seeing your code. If you include more information it will be easier to help you and you will likely get help quicker.

What do you mean by a different type of map? The BEAM does only have a single type of map: %{}

Also please try to check if you can reproduce the error in iex when you start it in test environment: MIX_ENV=test iex -S mix

Last but not least, how do you initialise the test-context in the tests and how did you initialise it in your iex-session?

Not to leave this dangling, because I did eventually figure it out. I was returning a tuple with one too many elements in the return value of my handle_call/3

Thanks so much for your help

1 Like