Skip to content

Instantly share code, notes, and snippets.

@gabrielelana
Created January 20, 2015 15:50
Show Gist options
  • Save gabrielelana/59952df6adb5b9db9a4b to your computer and use it in GitHub Desktop.
Save gabrielelana/59952df6adb5b9db9a4b to your computer and use it in GitHub Desktop.
Elixir GenServer stop
$elixir stop.exs
Asked to stop because :normal
1) test stop (Test)
stop.exs:28
** (exit) exited in: GenServer.call(#PID<0.68.0>, :stop, 5000)
** (EXIT) normal
stacktrace:
(elixir) lib/gen_server.ex:356: GenServer.call/3
stop.exs:30
Finished in 0.06 seconds (0.05s on load, 0.01s on tests)
1 tests, 1 failures
Randomized with seed 26643
defmodule Server do
use GenServer
def start do
GenServer.start(__MODULE__, [])
end
def stop(pid) do
GenServer.call(pid, :stop)
end
def handle_call(:stop, _from, status) do
{:stop, :normal, status}
end
def terminate(reason, _status) do
IO.puts "Asked to stop because #{inspect reason}"
:ok
end
end
ExUnit.start
defmodule Test do
use ExUnit.Case
test :stop do
{:ok, pid} = Server.start
Server.stop(pid)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment