From 0a491491f24c7c5b4f27723c82816cf9d1f0d157 Mon Sep 17 00:00:00 2001 From: Micah Cooper Date: Thu, 13 Nov 2025 11:55:49 -0600 Subject: [PATCH 1/3] Ensure 1 GRPC.Client.Supervisor --- lib/grpc/client/supervisor.ex | 6 +++++- test/grpc/client/supervisor_test.exs | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 test/grpc/client/supervisor_test.exs diff --git a/lib/grpc/client/supervisor.ex b/lib/grpc/client/supervisor.ex index 07832e56..ef76f8fb 100644 --- a/lib/grpc/client/supervisor.ex +++ b/lib/grpc/client/supervisor.ex @@ -44,7 +44,11 @@ defmodule GRPC.Client.Supervisor do use DynamicSupervisor def start_link(opts) do - DynamicSupervisor.start_link(__MODULE__, opts, name: __MODULE__) + case DynamicSupervisor.start_link(__MODULE__, opts, name: __MODULE__) do + {:error, {:already_started, pid}} -> {:ok, pid} + {:ok, _pid} = started -> started + other -> other + end end @impl true diff --git a/test/grpc/client/supervisor_test.exs b/test/grpc/client/supervisor_test.exs new file mode 100644 index 00000000..81a69669 --- /dev/null +++ b/test/grpc/client/supervisor_test.exs @@ -0,0 +1,14 @@ +defmodule GRPC.Client.SupervisorTest do + use ExUnit.Case, async: false + + alias GRPC.Client + + describe "start_link/1" do + test "allows multiple start_links" do + {:ok, second_pid} = Client.Supervisor.start_link([]) + {:ok, third_pid} = Client.Supervisor.start_link([]) + + assert second_pid == third_pid + end + end +end From 2fb38111319dc901bd7c339558e644f07a4456d9 Mon Sep 17 00:00:00 2001 From: Adriano Santos Date: Thu, 13 Nov 2025 16:07:15 -0300 Subject: [PATCH 2/3] Update lib/grpc/client/supervisor.ex --- lib/grpc/client/supervisor.ex | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/grpc/client/supervisor.ex b/lib/grpc/client/supervisor.ex index ef76f8fb..ac7bdd97 100644 --- a/lib/grpc/client/supervisor.ex +++ b/lib/grpc/client/supervisor.ex @@ -45,8 +45,11 @@ defmodule GRPC.Client.Supervisor do def start_link(opts) do case DynamicSupervisor.start_link(__MODULE__, opts, name: __MODULE__) do - {:error, {:already_started, pid}} -> {:ok, pid} - {:ok, _pid} = started -> started + {:ok, _pid} = started -> + started + + {:error, {:already_started, pid}} -> + {:ok, pid} other -> other end end From 983cea91e6bcda3d041a09bb2063b969ea995116 Mon Sep 17 00:00:00 2001 From: Micah Cooper Date: Thu, 13 Nov 2025 14:01:37 -0600 Subject: [PATCH 3/3] Format code - verify author --- lib/grpc/client/supervisor.ex | 10 ++++++---- test/grpc/client/supervisor_test.exs | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/grpc/client/supervisor.ex b/lib/grpc/client/supervisor.ex index ac7bdd97..099cba73 100644 --- a/lib/grpc/client/supervisor.ex +++ b/lib/grpc/client/supervisor.ex @@ -45,12 +45,14 @@ defmodule GRPC.Client.Supervisor do def start_link(opts) do case DynamicSupervisor.start_link(__MODULE__, opts, name: __MODULE__) do - {:ok, _pid} = started -> + {:ok, _pid} = started -> started - - {:error, {:already_started, pid}} -> + + {:error, {:already_started, pid}} -> {:ok, pid} - other -> other + + other -> + other end end diff --git a/test/grpc/client/supervisor_test.exs b/test/grpc/client/supervisor_test.exs index 81a69669..cd83c871 100644 --- a/test/grpc/client/supervisor_test.exs +++ b/test/grpc/client/supervisor_test.exs @@ -5,8 +5,8 @@ defmodule GRPC.Client.SupervisorTest do describe "start_link/1" do test "allows multiple start_links" do - {:ok, second_pid} = Client.Supervisor.start_link([]) - {:ok, third_pid} = Client.Supervisor.start_link([]) + {:ok, second_pid} = Client.Supervisor.start_link([]) + {:ok, third_pid} = Client.Supervisor.start_link([]) assert second_pid == third_pid end