Skip to content

Commit

Permalink
Return an error when starting a server twice
Browse files Browse the repository at this point in the history
  • Loading branch information
whitfin committed Sep 7, 2016
1 parent 7e32748 commit 4094af7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/eternal/supervisor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ defmodule Eternal.Supervisor do
# table twice. Otherwise, we execute the callback which will create the table.
defp detect_clash(name, ets_opts, fun) do
if exists?(name, ets_opts) do
{ :ok, Process.whereis(name), name }
{ :error, { :already_started, Process.whereis(name) } }
else
fun.()
end
Expand Down
7 changes: 3 additions & 4 deletions test/eternal_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,9 @@ defmodule EternalTest do
end

test "starting a table twice finds the previous owner" do
{ :ok, pid1 } = Eternal.start_link(:existing_table, [], [ quiet: true ])
{ :ok, pid2 } = Eternal.start_link(:existing_table, [], [ quiet: true ])

assert(pid1 == pid2)
{ :ok, pid } = Eternal.start_link(:existing_table, [], [ quiet: true ])
result2 = Eternal.start_link(:existing_table, [], [ quiet: true ])
assert(result2 == { :error, { :already_started, pid } })
end

test "deprecation warnings when using new/3" do
Expand Down

0 comments on commit 4094af7

Please sign in to comment.