【发布时间】:2017-03-03 10:26:51
【问题描述】:
我正在寻找一种方法来测试套接字是否被终止。被测代码是这样做的:
def handle_in("logout", _payload, socket) do
{:stop, :logout, socket |> assign(:user, nil)}
end
而我的测试代码(改编自 http://elixir-lang.org/getting-started/try-catch-and-rescue.html#exits)是这样做的:
test "logout terminates the socket", %{socket: socket} do
try do
push socket, "logout"
catch
huh -> IO.puts("Caught something #{IO.inspect huh}")
:exit, what -> IO.puts("Caught :exit #{IO.inspect what}")
end
assert_receive {:DOWN, monitor_ref, _, :normal}
end
但是当我运行测试时,我得到了这个:
1) test logout without login terminates the socket (Main.AuthChannelTest)
test/channels/auth_channel_test.exs:47
** (EXIT from #PID<0.505.0>) :logout
.....09:06:41.139 [error] GenServer #PID<0.507.0> terminating
** (stop) :logout
我应该如何测试套接字关闭?
【问题讨论】: