Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to test synchronous api #59

Open
namxam opened this issue Oct 15, 2023 · 1 comment
Open

How to test synchronous api #59

namxam opened this issue Oct 15, 2023 · 1 comment

Comments

@namxam
Copy link

namxam commented Oct 15, 2023

I know it is not really an issue, but right now I am a bit lost and could need some help :)

I have a synchronous handle_call/3 callback like this:

  def handle_call({:track_event, name, payload}, _from, %{assigns: %{channel: channel}} = socket) do
    {:ok, ref} = push(socket, channel, name, payload)
    result = case await_reply(ref) do
      {:error, :timeout} -> :error
      reply -> reply
    end
    {:reply, result, socket}
  end

How would I test such a function? connect_and_assert_join/4 works as expected. But I do not know how to implement assert_push/4 and reply/3. They work, but I always trigger the callbacks timeout. I could test the handle_call/3 function directly, but that triggers a process attempted to call itself error.

@the-mikedavis
Copy link
Collaborator

Could you share a snippet of how you are testing this? I think the problem might be that the GenServer call that hits this handle_call branch will block the caller until the reply is sent. So you may need the call to reply/3 to happen in a separate process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants