vendredi 16 mars 2018

Configure channel test timeout phoenix

I have a channel which I'm using to push messages to the client when carrying out some kind of sync:

defmodule AppWeb.SyncChannel do
  use AppWeb, :channel

  def join("sync:database", _payload, socket) do
    send(self(), {:sync, :database})

    {:ok, socket}
  end

  def join("sync:rule", _payload, socket) do
    {:ok, socket}
  end

  def handle_info({:sync, :database}, socket) do
    Process.sleep(2000)
    push(socket, "one", %{})
    Process.sleep(2000)
    push(socket, "two", %{})
    Process.sleep(2000)
    push(socket, "three", %{})

    {:noreply, socket}
  end
end

I have a test for this channel:

defmodule AppWeb.SyncChannelTest do
  use AppWeb.ChannelCase, async: false

  alias AppWeb.SyncChannel

  describe "sync:database" do
    setup do
      {:ok, _, socket} = subscribe_and_join(socket(), SyncChannel, "sync:database")

      {:ok, socket: socket}
    end

    test "socket pushes 3 messages", %{socket: _socket} do
      assert_push("one", %{})
      assert_push("two", %{})
      assert_push("three", %{})
    end
  end
end

But when I run the tests, I am getting the error:

** (exit) exited in: GenServer.call(#PID<0.463.0>, :socket, 5000)

** (EXIT) time out

How can I configure the channel timeout in my tests so that handle_info function is able to run for more than the default 5 seconds.

I have tried looking to configure this in the config/ files, without joy and also in the app_web/channels/user_socket.ex, but again I can't find anywhere specify a timeout

Aucun commentaire:

Enregistrer un commentaire