Skip to content

Commit e9a6c9e

Browse files
committed
No need to revert trap exits
1 parent 237f3bc commit e9a6c9e

File tree

1 file changed

+18
-21
lines changed

1 file changed

+18
-21
lines changed

lib/logger/test/logger/translator_test.exs

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -772,14 +772,13 @@ defmodule Logger.TranslatorTest do
772772
end
773773

774774
test "translates Supervisor reports start error" do
775+
Process.flag(:trap_exit, true)
776+
775777
assert capture_log(:info, fn ->
776-
trap = Process.flag(:trap_exit, true)
777778
children = [worker(__MODULE__, [], function: :error)]
778779

779780
assert {:error, {:shutdown, {:failed_to_start_child, __MODULE__, :stop}}} =
780781
Supervisor.start_link(children, strategy: :one_for_one)
781-
782-
Process.flag(:trap_exit, trap)
783782
end) =~ ~r"""
784783
\[error\] Child Logger.TranslatorTest of Supervisor #PID<\d+\.\d+\.\d+> \(Supervisor\.Default\) failed to start
785784
\*\* \(exit\) :stop
@@ -788,14 +787,13 @@ defmodule Logger.TranslatorTest do
788787
end
789788

790789
test "translates Supervisor reports start error with raise" do
790+
Process.flag(:trap_exit, true)
791+
791792
assert capture_log(:info, fn ->
792-
trap = Process.flag(:trap_exit, true)
793793
children = [worker(__MODULE__, [], function: :undef)]
794794

795795
assert {:error, {:shutdown, {:failed_to_start_child, __MODULE__, {:EXIT, _}}}} =
796796
Supervisor.start_link(children, strategy: :one_for_one)
797-
798-
Process.flag(:trap_exit, trap)
799797
end) =~ ~r"""
800798
\[error\] Child Logger.TranslatorTest of Supervisor #PID<\d+\.\d+\.\d+> \(Supervisor\.Default\) failed to start
801799
\*\* \(exit\) an exception was raised:
@@ -808,12 +806,12 @@ defmodule Logger.TranslatorTest do
808806
end
809807

810808
test "translates Supervisor reports terminated" do
809+
Process.flag(:trap_exit, true)
810+
811811
assert capture_log(:info, fn ->
812-
trap = Process.flag(:trap_exit, true)
813812
children = [worker(Task, [Kernel, :exit, [:stop]])]
814813
{:ok, pid} = Supervisor.start_link(children, strategy: :one_for_one, max_restarts: 0)
815814
receive do: ({:EXIT, ^pid, _} -> :ok)
816-
Process.flag(:trap_exit, trap)
817815
end) =~ ~r"""
818816
\[error\] Child Task of Supervisor #PID<\d+\.\d+\.\d+> \(Supervisor\.Default\) terminated
819817
\*\* \(exit\) :stop
@@ -831,12 +829,12 @@ defmodule Logger.TranslatorTest do
831829
end
832830

833831
test "translates Supervisor reports max restarts shutdown" do
832+
Process.flag(:trap_exit, true)
833+
834834
assert capture_log(:info, fn ->
835-
trap = Process.flag(:trap_exit, true)
836835
children = [worker(Task, [Kernel, :exit, [:stop]])]
837836
{:ok, pid} = Supervisor.start_link(children, strategy: :one_for_one, max_restarts: 0)
838837
receive do: ({:EXIT, ^pid, _} -> :ok)
839-
Process.flag(:trap_exit, trap)
840838
end) =~ ~r"""
841839
\[error\] Child Task of Supervisor #PID<\d+\.\d+\.\d+> \(Supervisor\.Default\) caused shutdown
842840
\*\* \(exit\) :reached_max_restart_intensity
@@ -892,14 +890,14 @@ defmodule Logger.TranslatorTest do
892890
end
893891

894892
test "translates DynamicSupervisor reports abnormal shutdown" do
893+
Process.flag(:trap_exit, true)
894+
895895
assert capture_log(:info, fn ->
896-
trap = Process.flag(:trap_exit, true)
897896
child = %{id: __MODULE__, start: {__MODULE__, :abnormal, []}}
898897
{:ok, pid} = DynamicSupervisor.start_link(strategy: :one_for_one)
899898
{:ok, _pid2} = DynamicSupervisor.start_child(pid, child)
900899
Process.exit(pid, :normal)
901900
receive do: ({:EXIT, ^pid, _} -> :ok)
902-
Process.flag(:trap_exit, trap)
903901
end) =~ ~r"""
904902
\[error\] Child :undefined of Supervisor #PID<\d+\.\d+\.\d+> \(Supervisor\.Default\) shut down abnormally
905903
\*\* \(exit\) :stop
@@ -913,17 +911,16 @@ defmodule Logger.TranslatorTest do
913911
end
914912

915913
test "translates DynamicSupervisor reports abnormal shutdown including extra_arguments" do
916-
assert capture_log(:info, fn ->
917-
trap = Process.flag(:trap_exit, true)
914+
Process.flag(:trap_exit, true)
918915

916+
assert capture_log(:info, fn ->
919917
{:ok, pid} =
920918
DynamicSupervisor.start_link(strategy: :one_for_one, extra_arguments: [:extra])
921919

922920
child = %{id: __MODULE__, start: {__MODULE__, :abnormal, [:args]}}
923921
{:ok, _pid2} = DynamicSupervisor.start_child(pid, child)
924922
Process.exit(pid, :normal)
925923
receive do: ({:EXIT, ^pid, _} -> :ok)
926-
Process.flag(:trap_exit, trap)
927924
end) =~ ~r"""
928925
\[error\] Child :undefined of Supervisor #PID<\d+\.\d+\.\d+> \(Supervisor\.Default\) shut down abnormally
929926
\*\* \(exit\) :stop
@@ -937,14 +934,14 @@ defmodule Logger.TranslatorTest do
937934
end
938935

939936
test "translates named DynamicSupervisor reports abnormal shutdown" do
937+
Process.flag(:trap_exit, true)
938+
940939
assert capture_log(:info, fn ->
941-
trap = Process.flag(:trap_exit, true)
942940
child = %{id: __MODULE__, start: {__MODULE__, :abnormal, []}}
943941
{:ok, pid} = DynamicSupervisor.start_link(strategy: :one_for_one, name: __MODULE__)
944942
{:ok, _pid2} = DynamicSupervisor.start_child(pid, child)
945943
Process.exit(pid, :normal)
946944
receive do: ({:EXIT, ^pid, _} -> :ok)
947-
Process.flag(:trap_exit, trap)
948945
end) =~ ~r"""
949946
\[error\] Child :undefined of Supervisor Logger.TranslatorTest shut down abnormally
950947
\*\* \(exit\) :stop
@@ -958,11 +955,11 @@ defmodule Logger.TranslatorTest do
958955
end
959956

960957
test "translates :supervisor_bridge progress" do
958+
Process.flag(:trap_exit, true)
959+
961960
assert capture_log(:info, fn ->
962-
trap = Process.flag(:trap_exit, true)
963961
{:ok, pid} = :supervisor_bridge.start_link(MyBridge, :normal)
964962
receive do: ({:EXIT, ^pid, _} -> :ok)
965-
Process.flag(:trap_exit, trap)
966963
end) =~ ~r"""
967964
\[info\] Child of Supervisor #PID<\d+\.\d+\.\d+> \(Logger\.TranslatorTest\.MyBridge\) started
968965
Pid: #PID<\d+\.\d+\.\d+>
@@ -971,11 +968,11 @@ defmodule Logger.TranslatorTest do
971968
end
972969

973970
test "translates :supervisor_bridge reports" do
971+
Process.flag(:trap_exit, true)
972+
974973
assert capture_log(:info, fn ->
975-
trap = Process.flag(:trap_exit, true)
976974
{:ok, pid} = :supervisor_bridge.start_link(MyBridge, :stop)
977975
receive do: ({:EXIT, ^pid, _} -> :ok)
978-
Process.flag(:trap_exit, trap)
979976
end) =~ ~r"""
980977
\[error\] Child of Supervisor #PID<\d+\.\d+\.\d+> \(Logger\.TranslatorTest\.MyBridge\) terminated
981978
\*\* \(exit\) :stop

0 commit comments

Comments
 (0)