Skip to content

Commit

Permalink
Merge pull request #158 from edgurgel/fix-activity-timeout-setting
Browse files Browse the repository at this point in the history
Fix WebsocketHandler init to pass proper idle_timeout
  • Loading branch information
edgurgel authored Dec 14, 2019
2 parents 3a5cc8b + 9ede7fb commit 7168155
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/poxa/websocket_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ defmodule Poxa.WebsocketHandler do
end

@doc false
def init(req, _opts), do: {:cowboy_websocket, req, req}
def init(req, _opts) do
idle_timeout_ms = Application.get_env(:poxa, :activity_timeout) * 1_000
{:cowboy_websocket, req, req, %{idle_timeout: idle_timeout_ms}}
end

@doc """
This function checks for proper app_key and protocol before continuing
Expand Down
7 changes: 7 additions & 0 deletions test/websocket_handler_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,13 @@ defmodule Poxa.WebsocketHandlerTest do
assert websocket_handle({:text, :client_event_json}, state) == {:ok, state}
end

describe "init/1" do
test "sets cowboy's idle_timeout" do
:application.set_env(:poxa, :activity_timeout, 30)
assert init(:req, []) == {:cowboy_websocket, :req, :req, %{idle_timeout: 30_000}}
end
end

describe "websocket_init/1" do
test "websocket init" do
expect(:cowboy_req, :binding, fn :app_key, :req -> "app_key" end)
Expand Down

0 comments on commit 7168155

Please sign in to comment.