diff --git a/lib/grpc/client/supervisor.ex b/lib/grpc/client/supervisor.ex index 07832e56..099cba73 100644 --- a/lib/grpc/client/supervisor.ex +++ b/lib/grpc/client/supervisor.ex @@ -44,7 +44,16 @@ 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 + {:ok, _pid} = started -> + started + + {:error, {:already_started, pid}} -> + {:ok, pid} + + 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..cd83c871 --- /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