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

Intermittent :closed message caused by race condition #61

Closed
elbow-jason opened this issue Jun 6, 2018 · 1 comment
Closed

Intermittent :closed message caused by race condition #61

elbow-jason opened this issue Jun 6, 2018 · 1 comment

Comments

@elbow-jason
Copy link

When running tests I am intermittently getting this error:

12:06:12.384 [error] Process #PID<0.1286.0> raised an exception
** (CaseClauseError) no case clause matching: <payload_here>
    (cowboy) /Users/elbow-jason/my_app/deps/cowboy/src/cowboy_protocol.erl:344: :cowboy_protocol.parse_hd_value/9
12:06:12.389 [error] Ranch protocol #PID<0.1286.0> (:cowboy_protocol) of listener #Reference<0.1060090579.823656453.233967> terminated
** (exit) an exception was raised:
    ** (CaseClauseError) no case clause matching: <payload_here>
        (cowboy) /Users/elbow-jason/my_app/deps/cowboy/src/cowboy_protocol.erl:344: :cowboy_protocol.parse_hd_value/9

with a failing test that says:

  1) test client can post! and handle the response (MyApp.NotifierClientTest)
     test/my_app/notifier_client_test.exs:12
     ** (HTTPoison.Error) :closed
     code: assert ^payload = NotifierClient.post!(endpoint_url(bypass.port), %{"hello" => "world"})
     stacktrace:
       (httpoison) lib/httpoison.ex:66: HTTPoison.request!/5
       (my_app) lib/my_app/notifier_client.ex:10: MyApp.NotifierClient.post!/2
       test/my_app/notifier_client_test.exs:18: (test)

here is the source:

  setup do
    bypass = Bypass.open
    {:ok, bypass: bypass}
  end

  test "client can post! and handle the response", %{bypass: bypass} do
    payload = %{"errors" => [%{"code" => 88, "message" => "Rate limit exceeded"}]}
    Bypass.expect_once bypass, "POST", "/", fn conn ->
      body = Poison.encode!(payload)
      Plug.Conn.resp(conn, 200, body)
    end
    assert ^payload = NotifierClient.post!(endpoint_url(bypass.port), %{"hello" => "world"})
  end

  defp endpoint_url(port), do: "http://localhost:#{port}/"

If I put a timer.sleep(100) in the setup block it stops happening.

Any suggestions/ideas for a solution?

@elbow-jason
Copy link
Author

I was dead wrong. Sorry. I was not encoding a binary correctly and it was failing intermittently. :-/

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

1 participant