aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2018-08-27 16:19:53 +0200
committerAlex Auvolat <alex@adnab.me>2018-08-27 16:19:53 +0200
commit233989490b0b01670b03154f9e8f83be13e5a89a (patch)
tree9a98641848fc57f85ce2c451911d4030c05153f9 /test
parent6cc81b55f2466cd7526f47da6980e3eb47041457 (diff)
downloadshard-233989490b0b01670b03154f9e8f83be13e5a89a.tar.gz
shard-233989490b0b01670b03154f9e8f83be13e5a89a.zip
Big fixes (1 line), small changes (many lines)
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