From a17b6fb804ee2eee2fe92a76df1dde3f0ea7b71d Mon Sep 17 00:00:00 2001 From: Justin Baker Date: Mon, 22 Jan 2018 14:32:29 -0600 Subject: [PATCH] Move and rename exit from terminate test --- test/websockex_test.exs | 50 ++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/test/websockex_test.exs b/test/websockex_test.exs index 80218f7..dbdccd0 100644 --- a/test/websockex_test.exs +++ b/test/websockex_test.exs @@ -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 @@ -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