Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions lib/bob/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,19 @@ defmodule Bob.Application do

File.mkdir_p!(Bob.tmp_dir())

opts = [strategy: :one_for_one, name: Bob.Supervisor]
Supervisor.start_link(children(), opts)
end

@doc false
# PromEx has to start before the repo. Its Ecto plugin picks up the pool size,
# timeout and repo name from the telemetry event the repo emits once, when it
# starts, and the Ecto dashboard reads its repo dropdown from those.
def children() do
children =
repo_children() ++
[Bob.PromEx] ++
repo_children() ++
[
Bob.PromEx,
{Finch, name: Bob.Finch},
{Task.Supervisor, [name: Bob.Tasks]},
{Phoenix.PubSub, name: Bob.PubSub},
Expand All @@ -27,10 +36,7 @@ defmodule Bob.Application do
metrics_server_spec()
]

children = Enum.reject(children, &is_nil/1)

opts = [strategy: :one_for_one, name: Bob.Supervisor]
Supervisor.start_link(children, opts)
Enum.reject(children, &is_nil/1)
end

defp repo_children() do
Expand Down
10 changes: 10 additions & 0 deletions test/bob/application_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
defmodule Bob.ApplicationTest do
use ExUnit.Case, async: true

test "PromEx starts before the repo so it sees the repo's init telemetry" do
children = Bob.Application.children()

assert Enum.find_index(children, &(&1 == Bob.PromEx)) <
Enum.find_index(children, &(&1 == Bob.Repo))
end
end
18 changes: 16 additions & 2 deletions test/bob/runner_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,22 @@ defmodule Bob.RunnerTest do
setup do
on_exit(fn ->
case Process.whereis(Bob.Runner) do
nil -> :ok
pid -> Process.exit(pid, :kill)
nil ->
:ok

pid ->
# Process.exit only sends the signal, and the runner holds a registered
# name until it is really gone. Returning before then leaves the next
# test's start_link racing the name, which it loses as
# {:error, {:already_started, pid}}.
ref = Process.monitor(pid)
Process.exit(pid, :kill)

receive do
{:DOWN, ^ref, :process, ^pid, _reason} -> :ok
after
5_000 -> raise "the runner outlived the test that started it"
end
end
end)

Expand Down
Loading