Skip to content

Commit

Permalink
Add Verk.QueueSupervisor.name & child_spec
Browse files Browse the repository at this point in the history
  • Loading branch information
edgurgel committed Sep 2, 2017
1 parent bc6f08a commit 0c6801a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
13 changes: 11 additions & 2 deletions lib/verk/queue_supervisor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ defmodule Verk.Queue.Supervisor do

@doc false
def start_link(name, size) do
supervisor_name = String.to_atom("#{name}.supervisor")
Supervisor.start_link(__MODULE__, [name, size], name: supervisor_name)
Supervisor.start_link(__MODULE__, [name, size], name: name(name))
end

@doc false
Expand All @@ -30,4 +29,14 @@ defmodule Verk.Queue.Supervisor do
args = [[name: {:local, pool_name}, worker_module: Verk.Worker, size: pool_size, max_overflow: 0], []]
worker(:poolboy, args, restart: :permanent, shutdown: 5000, id: pool_name)
end

@doc false
def name(queue) do
String.to_atom("#{queue}.supervisor")
end

@doc false
def child_spec(queue, size) when is_atom(queue) do
supervisor(Verk.Queue.Supervisor, [queue, size], id: name(queue))
end
end
29 changes: 29 additions & 0 deletions test/queue_supervisor_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
defmodule Verk.QueueSupervisorTest do
use ExUnit.Case
import Verk.Queue.Supervisor

describe "init/1" do
test "defines tree" do
{:ok, {_, children}} = init([:default, 25])
[queue_manager, pool, workers_manager] = children

assert {:"default.queue_manager", _, _, _, :worker, [Verk.QueueManager]} = queue_manager
assert {:"default.pool", _, _, _, :worker, [:poolboy]} = pool
assert {:"default.workers_manager", _, _, _, :worker, [Verk.WorkersManager]} = workers_manager
end
end

describe "name/1" do
test "returns supervisor name" do
assert name("default") == :"default.supervisor"
end
end

describe "child_spec/2" do
test "returns supervisor spec" do
assert {:"default.supervisor",
{Verk.Queue.Supervisor, :start_link, [:default, 25]}, _,
_, :supervisor, [Verk.Queue.Supervisor]} = child_spec(:default, 25)
end
end
end

0 comments on commit 0c6801a

Please sign in to comment.