aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/conn_test.exs23
-rw-r--r--test/test_helper.exs7
2 files changed, 30 insertions, 0 deletions
diff --git a/test/conn_test.exs b/test/conn_test.exs
index ff746b7..d2431d7 100644
--- a/test/conn_test.exs
+++ b/test/conn_test.exs
@@ -39,4 +39,27 @@ defmodule ShardTest.Conn do
{:ok, msg} = Box.open_easy(enc, n, pk, sk)
msg
end
+
+
+ test "set nickname" do
+ Shard.Identity.set_nickname "test bot"
+ end
+
+ test "connect to other instance" do
+ Shard.Manager.add_peer({127, 0, 0, 1}, 4045)
+ receive do after 100 -> nil end
+ end
+
+ test "connect to chat rooms" do
+ {:ok, pid1} = DynamicSupervisor.start_child(Shard.DynamicSupervisor, {SApp.Chat, "test"})
+ {:ok, pid2} = DynamicSupervisor.start_child(Shard.DynamicSupervisor, {SApp.Chat, "other_test"})
+ GenServer.cast(pid1, {:chat_send, "test msg 1"})
+ GenServer.cast(pid2, {:chat_send, "test msg 2"})
+
+ receive do after 100 -> nil end
+ {:ok, pid3} = DynamicSupervisor.start_child(Shard.DynamicSupervisor, {SApp.Chat, "test"})
+ receive do after 100 -> nil end
+ assert not Process.alive?(pid3)
+ end
+
end
diff --git a/test/test_helper.exs b/test/test_helper.exs
index 869559e..e5b6600 100644
--- a/test/test_helper.exs
+++ b/test/test_helper.exs
@@ -1 +1,8 @@
ExUnit.start()
+
+case :gen_tcp.connect('localhost', 4045, []) do
+ {:ok, socket} ->
+ :gen_tcp.close(socket)
+ {:error, _reason} ->
+ Mix.raise "Please have another instance of Shard running at 127.0.0.1:4045, it can be launched with the command: PORT=4045 iex -S mix"
+end