Testing GenServer Appears To Do A Call When Doing a Cast(Elixir 1.5.2)

My test, second in two tests, “Test 2”, does a handle_cast() and it fails when I do mix test.

BTW, if you want to see all the code you can go to:

Here is the output:

➜  fb_manager git:(master) ✗ mix test
.
12:43:44.377 [error] GenServer :ffnerd terminating
** (stop) bad return value: {:no_reply, %{"Russell Wilson" => %FFNerd.Player{active: "1", college: "Wisconsin",display_name: "Russell Wilson", dob: "1988-11-29", fname: "Russell", height: "5-11", jersey: "3", lname: "Wilson", player_id: "1847", position: "QB", star: nil, team: "SEA", twitter_id: nil, weight: "215"}}}
Last message: {:"$gen_cast", {:add, "Russell Wilson"}}
State: %{}


  1) test can add a player (FbManagerTest)
     test/fb_manager_test.exs:13
     ** (exit) exited in: GenServer.call(:ffnerd, :roster, 5000)
         ** (EXIT) bad return value: {:no_reply, %{"Russell Wilson" => %FFNerd.Player{active: "1", college: "Wisconsin", display_name: "Russell Wilson", dob: "1988-11-29", fname: "Russell", height: "5-11", jersey: "3", lname: "Wilson", player_id: "1847", position: "QB", star: nil, team: "SEA", twitter_id: nil, weight: "215"}}}
     code: assert FbManager.FFServer.roster() != %{}
     stacktrace:
       (elixir) lib/gen_server.ex:774: GenServer.call/3
       test/fb_manager_test.exs:19: (test)



Finished in 1.1 seconds
2 tests, 1 failure

Randomized with seed 244785

in the test I am doing:

  test "can add a player" do
    FbManager.FFServer.start_link
    FbManager.FFServer.add("Russell Wilson")
    # IO.inspect(FbManager.FFServer.roster())
    
    assert FbManager.FFServer.roster() != %{}
  end    

and in the code I am doing :no_reply but it seems like elixir believes otherwise. Any ideas?

defmodule FbManager.FFServer do

  use GenServer

  # client 

  def start_link do
    GenServer.start_link __MODULE__, [], name: :ffnerd
  end

  def roster() do
    GenServer.call(:ffnerd, :roster)
  end

  def add(name) do
    GenServer.cast(:ffnerd, {:add, name})
  end 

  # server

  def init(_) do
    {:ok, %{}}
  end

  def handle_call(:roster, _from, state) do
    {:reply, state, state}
  end

  def handle_cast({:add, name}, state) do
    client = FFNerd.Client.new("hrqevq4h55mt")
    player = FFNerd.Player.find(name, client)
    new_state = Map.put(state, name, player)
    {:no_reply, new_state}
  end
end

I have also tried mix test --no-start but this returns with

    ** (EXIT) no process: the process is not alive or there's no process currently associated with the given name, possibly because its application isn't started
1 Like

It’s :noreply, not :no_reply :slight_smile:

3 Likes

LOL thanks. Appreciate you taking the time to helping me out! Learning something new is always a humbling experience.

3 Likes