Skip to content

Commit d16f354

Browse files
author
José Valim
committed
Ensure proper reports from named DynamicSupervisor, closes #7425
1 parent dd30768 commit d16f354

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

lib/elixir/lib/dynamic_supervisor.ex

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,14 @@ defmodule DynamicSupervisor do
495495

496496
case mod.init(args) do
497497
{:ok, flags} when is_map(flags) ->
498-
state = %DynamicSupervisor{mod: mod, args: args, name: name || {self(), mod}}
498+
name =
499+
cond do
500+
is_nil(name) -> {self(), mod}
501+
is_atom(name) -> {:local, name}
502+
is_tuple(name) -> name
503+
end
504+
505+
state = %DynamicSupervisor{mod: mod, args: args, name: name}
499506

500507
case init(state, flags) do
501508
{:ok, state} -> {:ok, state}

lib/logger/test/logger/translator_test.exs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,23 @@ defmodule Logger.TranslatorTest do
731731
"""
732732
end
733733

734+
test "translates named DynamicSupervisor reports abnormal shutdown" do
735+
assert capture_log(:info, fn ->
736+
trap = Process.flag(:trap_exit, true)
737+
child = %{id: __MODULE__, start: {__MODULE__, :abnormal, []}}
738+
{:ok, pid} = DynamicSupervisor.start_link(strategy: :one_for_one, name: __MODULE__)
739+
{:ok, _pid2} = DynamicSupervisor.start_child(pid, child)
740+
Process.exit(pid, :normal)
741+
receive do: ({:EXIT, ^pid, _} -> :ok)
742+
Process.flag(:trap_exit, trap)
743+
end) =~ ~r"""
744+
\[error\] Child :undefined of Supervisor Logger.TranslatorTest shutdown abnormally
745+
\*\* \(exit\) :stop
746+
Pid: #PID<\d+\.\d+\.\d+>
747+
Start Call: Logger.TranslatorTest.abnormal\(\)
748+
"""
749+
end
750+
734751
test "translates :supervisor_bridge progress" do
735752
assert capture_log(:info, fn ->
736753
trap = Process.flag(:trap_exit, true)

0 commit comments

Comments
 (0)