Skip to content

Commit

Permalink
Move and rename exit from terminate test
Browse files Browse the repository at this point in the history
  • Loading branch information
Azolo committed Jan 22, 2018
1 parent 66efa25 commit a17b6fb
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions test/websockex_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -934,6 +934,31 @@ defmodule WebSockexTest do

assert_receive :normal_close_terminate
end

test "does not catch exits", %{pid: orig_pid} = context do
defmodule TerminateClient do
use WebSockex
def start(url, state, opts \\ []) do
WebSockex.start(url, __MODULE__, state, opts)
end

def terminate(:test_reason, _state) do
exit(:normal)
end
end

Process.unlink(orig_pid)
ref = Process.monitor(orig_pid)

:sys.terminate(orig_pid, :test_reason)
assert_receive {:DOWN, ^ref, :process, ^orig_pid, :test_reason}

{:ok, pid} = TerminateClient.start(context.url, %{})
ref = Process.monitor(pid)

:sys.terminate(pid, :test_reason)
assert_receive {:DOWN, ^ref, :process, ^pid, :normal}
end
end

describe "handle_ping callback" do
Expand Down Expand Up @@ -1380,29 +1405,4 @@ defmodule WebSockexTest do
# A second data tuple means pretty output for `:observer`. Who knew?
assert {:data, _data} = List.keyfind(rest, :data, 0)
end

test "can exit from terminate", %{pid: orig_pid} = context do
defmodule TerminateClient do
use WebSockex
def start(url, state, opts \\ []) do
WebSockex.start(url, __MODULE__, state, opts)
end

def terminate(:test_reason, _state) do
exit(:normal)
end
end

Process.unlink(orig_pid)
ref = Process.monitor(orig_pid)

:sys.terminate(orig_pid, :test_reason)
assert_receive {:DOWN, ^ref, :process, ^orig_pid, :test_reason}

{:ok, pid} = TerminateClient.start(context.url, %{})
ref = Process.monitor(pid)

:sys.terminate(pid, :test_reason)
assert_receive {:DOWN, ^ref, :process, ^pid, :normal}
end
end

0 comments on commit a17b6fb

Please sign in to comment.