Refactor test runtime ownership
This commit is contained in:
34
test/support/runtime.ex
Normal file
34
test/support/runtime.ex
Normal file
@@ -0,0 +1,34 @@
|
||||
defmodule Parrhesia.TestSupport.Runtime do
|
||||
@moduledoc false
|
||||
|
||||
@required_processes [
|
||||
Parrhesia.Supervisor,
|
||||
Parrhesia.Config,
|
||||
Parrhesia.Repo,
|
||||
Parrhesia.Subscriptions.Supervisor,
|
||||
Parrhesia.Web.Endpoint
|
||||
]
|
||||
|
||||
def ensure_started! do
|
||||
if healthy?() do
|
||||
:ok
|
||||
else
|
||||
restart!()
|
||||
end
|
||||
end
|
||||
|
||||
defp healthy? do
|
||||
Enum.all?(@required_processes, &is_pid(Process.whereis(&1)))
|
||||
end
|
||||
|
||||
defp restart! do
|
||||
case Application.stop(:parrhesia) do
|
||||
:ok -> :ok
|
||||
{:error, {:not_started, :parrhesia}} -> :ok
|
||||
{:error, {:not_started, _app}} -> :ok
|
||||
end
|
||||
|
||||
{:ok, _apps} = Application.ensure_all_started(:parrhesia)
|
||||
:ok
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user