Skip to content

Instantly share code, notes, and snippets.

@tfrisk-old
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tfrisk-old/211efb17e5df2b134d96 to your computer and use it in GitHub Desktop.
Save tfrisk-old/211efb17e5df2b134d96 to your computer and use it in GitHub Desktop.
test_helper.exs:
exclude =
if Node.alive?, do: [], else: [distributed: true]
ExUnit.start(exclude: exclude)
router_test.exs:
defmodule KV.RouterTest do
use ExUnit.Case, async: true
@tag :distributed
test "route requests across nodes" do
assert KV.Router.route("hello", Kernel, :node, []) ==
:"foo@localhost"
assert KV.Router.route("world", Kernel, :node, []) ==
:"bar@localhost"
end
test "raises on unknown entries" do
assert_raise RuntimeError, ~r/could not find entry/, fn ->
KV.Router.route(<<0>>, Kernel, :node, [])
end
end
end
test output:
✗ mix test
==> kv
......
1) test route requests across nodes (KV.RouterTest)
test/kv/router_test.exs:5
** (exit) exited in: GenServer.call({KV.RouterTasks, :foo@localhost}, {:start_child, [#PID<0.148.0>, {:nonode@nohost, #PID<0.148.0>}, {:erlang, :apply, [#Function<1.124167133/0 in KV.Router.route/4>, []]}]}, :infinity)
** (EXIT) no connection to foo@localhost
stacktrace:
(elixir) lib/gen_server.ex:356: GenServer.call/3
(elixir) lib/task/supervisor.ex:68: Task.Supervisor.async/4
(kv) lib/kv/router.ex:21: KV.Router.route/4
test/kv/router_test.exs:6
...
Finished in 0.1 seconds (0.1s on load, 0.01s on tests)
10 tests, 1 failures
Randomized with seed 840118
==> kv_server
Accepting connections on port 4040
........
Finished in 0.01 seconds
8 tests, 0 failures
Randomized with seed 63203
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment