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

Channel response timeout #2

Open
wants to merge 1 commit into
base: absinthe
Choose a base branch
from

Conversation

dustinfarris
Copy link

@dustinfarris dustinfarris commented Jan 19, 2017

Summary

The assert_reply channel test macro times out on the first test that invokes Absinthe.run and returns a result.

Details

This PR contains models for Chat.Message and Chat.User, a new schema field message, and a "graphql" channel that takes a standard GraphQL query, runs it through Absinthe, and returns the result.

There is a test that verifies that this works. The test creates a Message, sends a message query to the graphql channel, and listens for a reply using the assert_reply macro. assert_reply, by default, times out after 100ms.

There are actually two tests that are nearly identical. The only difference is the test on line 44 uses assert_reply's default timeout. The test on line 28 increases the timeout to 300ms.

I am using Elixir 1.4.0 and Erlang 19.2

To reproduce

Clone this repo:

git clone git@github.com:dustinfarris/phoenix_chat_example
cd phoenix_chat_example && git checkout channel-timeout
mix do deps.get, compile

Run the default timeout test:

mix test test/message_query_test.exs:44

The test fails:

  1) test message query (Chat.MessageQueryTest)
     test/message_query_test.exs:44
     No message matching %Phoenix.Socket.Reply{ref: ^ref, status: :ok, payload: %{data: %{"message" => %{"body" => "Test message", "author" => %{"name" => "Dustin Farris"}}}}} after 100ms.
     The following variables were pinned:
       ref = #Reference<0.0.2.17387>
     The process mailbox is empty.
     stacktrace:
       test/message_query_test.exs:50: (test)

That "The process mailbox is empty." line is a result of the assertion timing out before a message was received.

Now, run the test where the timeout is increased to 300ms

mix test test/message_query_test.exs:28

The test passes:

.

Finished in 0.2 seconds

Now—and this is interesting—run both tests:

mix test test/message_query_test.exs

Both tests pass:

..

Finished in 0.2 seconds

I have observed that only the first test that runs will fail with this timeout error, if it is left at the default 100ms. From that point on everything passes.

@josevalim
Copy link

Related to phoenixframework/phoenix#2023.

If Absinthe is doing some lazy compilation, that would be it. Otherwise it may be code loading.

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