Skip to content

Instantly share code, notes, and snippets.

@myronmarston
Created September 30, 2016 19:20
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 myronmarston/adacf3884730133a19d033cfe1cc9500 to your computer and use it in GitHub Desktop.
Save myronmarston/adacf3884730133a19d033cfe1cc9500 to your computer and use it in GitHub Desktop.
@doc """
Will ensure the processes with the test does not complete until the process with the
provided pid has exited. This is necessary when writing multiple tests that start the
same named process. See https://github.com/elixir-lang/elixir/issues/3854 for more info.
This accepts either `{:ok, pid}` or just `pid` so that you can use it in a pipeline
after a `start_link` call.
"""
def synchronize_death_on_exit({:ok, pid}) when is_pid(pid), do: synchronize_death_on_exit(pid)
def synchronize_death_on_exit(pid) when is_pid(pid) do
ExUnit.Callbacks.on_exit fn ->
ref = Process.monitor(pid)
receive do
{:DOWN, ^ref, _, _, _} -> :ok
end
end
pid
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment