summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMichal Muskala <michal@muskala.eu>2016-05-13 20:51:08 +0200
committerMichal Muskala <michal@muskala.eu>2016-05-13 21:25:14 +0200
commit01c4c42e117636cdba2d5278c851fbe7a3b39bc0 (patch)
treea8a6bbf1f15715e982c7d7c5aade7ac5593dc6f2 /test
parentMerge pull request #43 from Annwenn/master (diff)
Monitor owner of the connection
The connection process should monitor the process that started it and die with the same reason that the owner process did. This should solve the issue of zombie connections laying around after the processes that started them die.
Diffstat (limited to 'test')
-rw-r--r--test/client_test.exs25
1 files changed, 22 insertions, 3 deletions
diff --git a/test/client_test.exs b/test/client_test.exs
index 6cff0b7..b7277b6 100644
--- a/test/client_test.exs
+++ b/test/client_test.exs
@@ -1,11 +1,30 @@
defmodule ExIrc.ClientTest do
use ExUnit.Case
-
test "start multiple clients" do
- {:ok, pid} = ExIrc.start_client!
- {:ok, pid2} = ExIrc.start_client!
+ assert {:ok, pid} = ExIrc.start_client!
+ assert {:ok, pid2} = ExIrc.start_client!
assert pid != pid2
end
+ test "client dies if owner process dies" do
+ test_pid = self()
+
+ pid = spawn_link(fn ->
+ assert {:ok, pid} = ExIrc.start_client!
+ send(test_pid, {:client, pid})
+ receive do
+ :stop -> :ok
+ end
+ end)
+
+ client_pid = receive do
+ {:client, pid} -> pid
+ end
+
+ assert Process.alive?(client_pid)
+ send(pid, :stop)
+ :timer.sleep(1)
+ refute Process.alive?(client_pid)
+ end
end