Repository: elixir-grpc/grpc (elixir)

Issue:
Remove the `start_server: true` global config
We should avoid global application config because it makes things more difficult when a dependency also depends on the library an user wishes to use.

One such case is the `config :grpc, :start_server, true` key

Pull request:
refactor: change application config methods
This PR changes the configuration methods for the library.

- Deprecates global application env
- Changes the init method for GRPC.Server.Supervisor in favor of accepting a keyword list

closes #246 

Patch:
diff --git a/README.md b/README.md
index 6438b3d..4f2a925 100644
--- a/README.md
+++ b/README.md
@@ -65,7 +65,7 @@ defmodule HelloworldApp do
   def start(_type, _args) do
     children = [
       # ...
-      supervisor(GRPC.Server.Supervisor, [{Helloworld.Endpoint, 50051}])
+      {GRPC.Server.Supervisor, endpoint: Helloworld.Endpoint, port: 50051}
     ]
 
     opts = [strategy: :one_for_one, name: YourApp]
@@ -74,24 +74,6 @@ defmodule HelloworldApp do
 end
 ```
 
-Then start it when starting your application:
-
-```elixir
-# config.exs
-config :grpc, start_server: true
-
-# test.exs
-config :grpc, start_server: false
-
-$ iex -S mix
-```
-
-or run grpc.server using a mix task
-
-```
-$ mix grpc.server
-```
-
 4. Call rpc:
 ```elixir
 iex> {:ok, channel} = GRPC.Stub.connect("localhost:50051")
diff --git a/config/config.exs b/config/config.exs
index 9e0a907..773875c 100644
--- a/config/config.exs
+++ b/config/config.exs
@@ -1,7 +1,5 @@
 import Config
 
-config :grpc, http2_client_adapter: GRPC.Client.Adapters.Gun
-
 config_file = Path.expand("#{config_env()}.exs", __DIR__)
 
 if File.exists?(config_file) do
diff --git a/examples/helloworld/README.md b/examples/helloworld/README.md
index 8eaa2c2..924681f 100644
--- a/examples/helloworld/README.md
+++ b/examples/helloworld/README.md
@@ -9,7 +9,7 @@ $ mix do deps.get, compile
 
 2. Run the server
 ```shell
-$ mix grpc.server
+$ mix run --no-halt
 ```
 
 3. Run the client script
@@ -34,11 +34,7 @@ Refer to [protobuf-elixir](https://github.com/tony612/protobuf-elixir#usage) for
 
 ## How to start server when starting your application?
 
-Change the config to:
-
-```elixir
-config :grpc, start_server: true
-```
+Pass `start_server: true` as an option for the `GRPC.Server.Supervisor` in your supervision tree.
 
 ## Benchmark
 
diff --git a/examples/helloworld/config/config.exs b/examples/helloworld/config/config.exs
index ef385b1..9def7c2 100644
--- a/examples/helloworld/config/config.exs
+++ b/examples/helloworld/config/config.exs
@@ -1,6 +1,3 @@
 import Config
 
-# Start server in OTP
-config :grpc, start_server: true
-
 import_config "#{Mix.env}.exs"
diff --git a/examples/helloworld/config/prod.exs b/examples/helloworld/config/prod.exs
index 2a16500..2dd33c3 100644
--- a/examples/helloworld/config/prod.exs
+++ b/examples/helloworld/config/prod.exs
@@ -1,6 +1,4 @@
 import Config
 
-config :grpc, start_server: true
-
 config :logger,
   level: :warn
diff --git a/examples/helloworld/lib/helloworld_app.ex b/examples/helloworld/lib/helloworld_app.ex
index 3295d0d..d84d62a 100644
--- a/examples/helloworld/lib/helloworld_app.ex
+++ b/examples/helloworld/lib/helloworld_app.ex
@@ -3,7 +3,7 @@ defmodule HelloworldApp do
 
   def start(_type, _args) do
     children = [
-      {GRPC.Server.Supervisor, {Helloworld.Endpoint, 50051}}
+      {GRPC.Server.Supervisor, endpoint: Helloworld.Endpoint, port: 50051, start_server: true}
     ]
 
     opts = [strategy: :one_for_one, name: HelloworldApp]
diff --git a/examples/helloworld/mix.lock b/examples/helloworld/mix.lock
index 2d0dfb0..9a77ff1 100644
--- a/examples/helloworld/mix.lock
+++ b/examples/helloworld/mix.lock
@@ -3,7 +3,7 @@
   "cowlib": {:hex, :cowlib, "2.11.0", "0b9ff9c346629256c42ebe1eeb769a83c6cb771a6ee5960bd110ab0b9b872063", [:make, :rebar3], [], "hexpm", "2b3e9da0b21c4565751a6d4901c20d1b4cc25cbb7fd50d91d2ab6dd287bc86a9"},
   "dialyxir": {:hex, :dialyxir, "1.1.0", "c5aab0d6e71e5522e77beff7ba9e08f8e02bad90dfbeffae60eaf0cb47e29488", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "07ea8e49c45f15264ebe6d5b93799d4dd56a44036cf42d0ad9c960bc266c0b9a"},
   "erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
-  "gun": {:hex, :gun, "2.0.0-rc.2", "7c489a32dedccb77b6e82d1f3c5a7dadfbfa004ec14e322cdb5e579c438632d2", [:make, :rebar3], [{:cowlib, "2.11.0", [hex: :cowlib, repo: "hexpm", optional: false]}], "hexpm", "6b9d1eae146410d727140dbf8b404b9631302ecc2066d1d12f22097ad7d254fc"},
+  "gun": {:hex, :grpc_gun, "2.0.1", "221b792df3a93e8fead96f697cbaf920120deacced85c6cd3329d2e67f0871f8", [:rebar3], [{:cowlib, "~> 2.11", [hex: :cowlib, repo: "hexpm", optional: false]}], "hexpm", "795a65eb9d0ba16697e6b0e1886009ce024799e43bb42753f0c59b029f592831"},
   "protobuf": {:hex, :protobuf, "0.10.0", "4e8e3cf64c5be203b329f88bb8b916cb8d00fb3a12b2ac1f545463ae963c869f", [:mix], [{:jason, "~> 1.2", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "4ae21a386142357aa3d31ccf5f7d290f03f3fa6f209755f6e87fc2c58c147893"},
   "ranch": {:hex, :ranch, "1.8.0", "8c7a100a139fd57f17327b6413e4167ac559fbc04ca7448e9be9057311597a1d", [:make, :rebar3], [], "hexpm", "49fbcfd3682fab1f5d109351b61257676da1a2fdbe295904176d5e521a2ddfe5"},
 }
diff --git a/examples/route_guide/README.md b/examples/route_guide/README.md
index 7ab2d1a..5e9fa0d 100644
--- a/examples/route_guide/README.md
+++ b/examples/route_guide/README.md
@@ -9,7 +9,7 @@ $ mix do deps.get, compile
 
 2. Run the server
 ```
-$ mix grpc.server
+$ mix run --no-halt
 ```
 
 2. Run the client
@@ -35,7 +35,7 @@ Refer to [protobuf-elixir](https://github.com/tony612/protobuf-elixir#usage) for
 ## Authentication
 
 ```
-$ TLS=true mix grpc.server
+$ TLS=true mix run --no-halt
 $ TLS=true mix run priv/client.exs
 ```
 
@@ -44,10 +44,3 @@ $ TLS=true mix run priv/client.exs
 * How to change log level? Check out `config/config.exs`, default to warn
 * Use local grpc-elixir? Uncomment `{:grpc, path: "../../"}` in `mix.exs`
 * Why is output format of `Feature` & `Point` different from normal map? Check out `lib/inspect.ex`
-* How to start server when starting your application?
-
-  Change the config to:
-
-  ```elixir
-  config :grpc, start_server: true
-  ```
diff --git a/examples/route_guide/config/config.exs b/examples/route_guide/config/config.exs
deleted file mode 100644
index 28aeed1..0000000
--- a/examples/route_guide/config/config.exs
+++ /dev/null
@@ -1,3 +0,0 @@
-import Config
-
-config :grpc, start_server: true
diff --git a/examples/route_guide/lib/app.ex b/examples/route_guide/lib/app.ex
index 035d24c..8cebbf3 100644
--- a/examples/route_guide/lib/app.ex
+++ b/examples/route_guide/lib/app.ex
@@ -15,12 +15,13 @@ defmodule Routeguide.App do
   end
 
   defp start_args do
+    opts = [endpoint: Routeguide.Endpoint, port: 10000, start_server: true]
+
     if System.get_env("TLS") do
       cred = GRPC.Credential.new(ssl: [certfile: @cert_path, keyfile: @key_path])
-      IO.inspect(cred)
-      {Routeguide.Endpoint, 10000, cred: cred}
+      Keyword.put(opts, :cred, cred)
     else
-      {Routeguide.Endpoint, 10000}
+      opts
     end
   end
 end
diff --git a/examples/route_guide/mix.lock b/examples/route_guide/mix.lock
index c7f7f96..3d14fba 100644
--- a/examples/route_guide/mix.lock
+++ b/examples/route_guide/mix.lock
@@ -3,7 +3,7 @@
   "cowlib": {:hex, :cowlib, "2.11.0", "0b9ff9c346629256c42ebe1eeb769a83c6cb771a6ee5960bd110ab0b9b872063", [:make, :rebar3], [], "hexpm", "2b3e9da0b21c4565751a6d4901c20d1b4cc25cbb7fd50d91d2ab6dd287bc86a9"},
   "dialyxir": {:hex, :dialyxir, "1.2.0", "58344b3e87c2e7095304c81a9ae65cb68b613e28340690dfe1a5597fd08dec37", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "61072136427a851674cab81762be4dbeae7679f85b1272b6d25c3a839aff8463"},
   "erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
-  "gun": {:hex, :gun, "2.0.0-rc.2", "7c489a32dedccb77b6e82d1f3c5a7dadfbfa004ec14e322cdb5e579c438632d2", [:make, :rebar3], [{:cowlib, "2.11.0", [hex: :cowlib, repo: "hexpm", optional: false]}], "hexpm", "6b9d1eae146410d727140dbf8b404b9631302ecc2066d1d12f22097ad7d254fc"},
+  "gun": {:hex, :grpc_gun, "2.0.1", "221b792df3a93e8fead96f697cbaf920120deacced85c6cd3329d2e67f0871f8", [:rebar3], [{:cowlib, "~> 2.11", [hex: :cowlib, repo: "hexpm", optional: false]}], "hexpm", "795a65eb9d0ba16697e6b0e1886009ce024799e43bb42753f0c59b029f592831"},
   "jason": {:hex, :jason, "1.3.0", "fa6b82a934feb176263ad2df0dbd91bf633d4a46ebfdffea0c8ae82953714946", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "53fc1f51255390e0ec7e50f9cb41e751c260d065dcba2bf0d08dc51a4002c2ac"},
   "protobuf": {:hex, :protobuf, "0.10.0", "4e8e3cf64c5be203b329f88bb8b916cb8d00fb3a12b2ac1f545463ae963c869f", [:mix], [{:jason, "~> 1.2", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "4ae21a386142357aa3d31ccf5f7d290f03f3fa6f209755f6e87fc2c58c147893"},
   "ranch": {:hex, :ranch, "1.8.0", "8c7a100a139fd57f17327b6413e4167ac559fbc04ca7448e9be9057311597a1d", [:make, :rebar3], [], "hexpm", "49fbcfd3682fab1f5d109351b61257676da1a2fdbe295904176d5e521a2ddfe5"},
diff --git a/interop/config/config.exs b/interop/config/config.exs
index c4e7cbc..5d2660c 100644
--- a/interop/config/config.exs
+++ b/interop/config/config.exs
@@ -6,6 +6,4 @@ config :prometheus, GRPCPrometheus.ServerInterceptor,
 config :prometheus, GRPCPrometheus.ClientInterceptor,
   latency: :histogram
 
-# config :grpc, start_server: true
-
 config :logger, level: :warn
diff --git a/interop/lib/interop/app.ex b/interop/lib/interop/app.ex
index 033f347..1d3d2d8 100644
--- a/interop/lib/interop/app.ex
+++ b/interop/lib/interop/app.ex
@@ -2,7 +2,7 @@ defmodule Interop.App do
   use Application
 
   def start(_type, _args) do
-    children = [{GRPC.Server.Supervisor, {Interop.Endpoint, 10000}}]
+    children = [{GRPC.Server.Supervisor, endpoint: Interop.Endpoint, port: 10000}]
 
     GRPCPrometheus.ServerInterceptor.setup()
     GRPCPrometheus.ClientInterceptor.setup()
diff --git a/interop/script/run.exs b/interop/script/run.exs
index 18a41bc..81cb5d5 100644
--- a/interop/script/run.exs
+++ b/interop/script/run.exs
@@ -1,5 +1,5 @@
 {options, _, _} = OptionParser.parse(System.argv(), strict: [rounds: :integer, concurrency: :integer, port: :integer])
-rounds = Keyword.get(options, :rounds) || 100
+rounds = Keyword.get(options, :rounds) || 20
 max_concurrency = System.schedulers_online()
 concurrency = Keyword.get(options, :concurrency) || max_concurrency
 port = Keyword.get(options, :port) || 0
@@ -16,7 +16,8 @@ alias Interop.Client
 
 {:ok, _pid, port} = GRPC.Server.start_endpoint(Interop.Endpoint, port)
 
-stream = Task.async_stream(1..concurrency, fn _cli ->
+1..concurrency
+|> Task.async_stream(fn _cli ->
   ch = Client.connect("127.0.0.1", port, interceptors: [GRPCPrometheus.ClientInterceptor, GRPC.Logger.Client])
 
   for _ <- 1..rounds do
@@ -41,11 +42,7 @@ stream = Task.async_stream(1..concurrency, fn _cli ->
   end
   :ok
 end, max_concurrency: concurrency, ordered: false, timeout: :infinity)
-
-Enum.map(stream, fn result ->
-  result
-end)
-|> IO.inspect
+|> Enum.to_list()
 
 # defmodule Helper do
 #   def flush() do
diff --git a/lib/grpc/server/supervisor.ex b/lib/grpc/server/supervisor.ex
index a09539b..5d97b1d 100644
--- a/lib/grpc/server/supervisor.ex
+++ b/lib/grpc/server/supervisor.ex
@@ -2,29 +2,20 @@ defmodule GRPC.Server.Supervisor do
   @moduledoc """
   A simple supervisor to start your servers.
 
-  You can add it to your OTP tree as below. But to make the servers start, you have to config `grpc`
+  You can add it to your OTP tree as below.
+  To start the server, you can pass `start_server: true` and an option
 
       defmodule Your.App do
         use Application
 
         def start(_type, _args) do
           children = [
-            {GRPC.Server.Supervisor, {Your.Endpoint, 50051, opts}}
-          ]
+            {GRPC.Server.Supervisor, endpoint: Your.Endpoint, port: 50051, start_server: true, ...}]
 
-          opts = [strategy: :one_for_one, name: __MODULE__]
-          Supervisor.start_link(children, opts)
+          Supervisor.start_link(children, strategy: :one_for_one, name: __MODULE__)
         end
       end
 
-      # config.exs
-      config :grpc, start_server: true
-
-  or
-
-      run `mix grpc.server` on local
-
-  or you can pass `start_server: true` as an option for the supervisor (as started above)
   """
 
   use Supervisor
@@ -36,28 +27,53 @@ defmodule GRPC.Server.Supervisor do
     Supervisor.start_link(__MODULE__, endpoint)
   end
 
-  @spec init({module() | [module()], integer()}) ::
-          {:ok, {:supervisor.sup_flags(), [:supervisor.child_spec()]}} | :ignore
-  def init({endpoint, port}) do
-    init({endpoint, port, []})
+  @doc """
+  ## Options
+
+    * `:endpoint` - defines the endpoint module that will be started.
+    * `:port` - the HTTP port for the endpoint.
+    * `:servers` - the list of servers that will be be started.
+
+  Either `:endpoint` or `:servers` must be present, but not both.
+  """
+  @spec init(tuple()) :: no_return
+  @spec init(keyword()) :: {:ok, {:supervisor.sup_flags(), [:supervisor.child_spec()]}} | :ignore
+  def init(opts \\ [])
+
+  def init(opts) when is_tuple(opts) do
+    raise ArgumentError,
+          "passing a tuple as configuration for GRPC.Server.Supervisor is no longer supported. See the documentation for more information on how to configure."
   end
 
-  @spec init({module() | [module()], integer(), Keyword.t()}) ::
-          {:ok, {:supervisor.sup_flags(), [:supervisor.child_spec()]}} | :ignore
-  def init({endpoint, port, opts}) do
-    check_deps_version()
+  def init(opts) when is_list(opts) do
+    unless is_nil(Application.get_env(:grpc, :start_server)) do
+      raise "the :start_server config key has been deprecated.\
+      The currently supported way is to configure it\
+      through the :start_server option for the GRPC.Server.Supervisor"
+    end
 
-    # The code is repeated because it is concise and this way we can make it lazy
-    children =
-      cond do
-        opts[:start_server] ->
-          [child_spec(endpoint, port, opts)]
+    endpoint_or_servers =
+      case {opts[:endpoint], opts[:servers]} do
+        {endpoint, servers}
+        when (not is_nil(endpoint) and not is_nil(servers)) or
+               (is_nil(endpoint) and is_nil(servers)) ->
+          raise ArgumentError, "either :endpoint or :servers must be passed, but not both."
 
-        not Keyword.has_key?(opts, :start_server) and Application.get_env(:grpc, :start_server) ->
-          [child_spec(endpoint, port, opts)]
+        {endpoint, nil} ->
+          endpoint
 
-        :otherwise ->
-          []
+        {nil, servers} when not is_list(servers) ->
+          raise ArgumentError, "either :servers must be a list of modules"
+
+        {nil, servers} when is_list(servers) ->
+          servers
+      end
+
+    children =
+      if opts[:start_server] do
+        [child_spec(endpoint_or_servers, opts[:port], opts)]
+      else
+        []
       end
 
     Supervisor.init(children, strategy: :one_for_one)
@@ -74,8 +90,9 @@ defmodule GRPC.Server.Supervisor do
       If present, has more precedence then the `config :gprc, :start_server`
       config value (i.e. `start_server: false` will not start the server in any case).
   """
-  @spec child_spec(atom() | [atom()], integer(), Keyword.t()) :: Supervisor.Spec.spec()
-  def child_spec(endpoint, port, opts \\ [])
+  @spec child_spec(endpoint_or_servers :: atom() | [atom()], port :: integer, opts :: keyword()) ::
+          Supervisor.Spec.spec()
+  def child_spec(endpoint_or_servers, port, opts \\ [])
 
   def child_spec(endpoint, port, opts) when is_atom(endpoint) do
     {endpoint, servers} =
@@ -100,22 +117,4 @@ defmodule GRPC.Server.Supervisor do
     servers = GRPC.Server.servers_to_map(servers)
     adapter.child_spec(nil, servers, port, opts)
   end
-
-  defp check_deps_version() do
-    # cowlib
-    case :application.get_key(:cowlib, :vsn) do
-      {:ok, vsn} ->
-        ver = to_string(vsn)
-
-        unless Version.match?(ver, ">= 2.9.0") do
-          Logger.warn("cowlib should be >= 2.9.0, it's #{ver} now. See grpc's README for details")
-        end
-
-      _ ->
-        :ok
-    end
-  rescue
-    _ ->
-      :ok
-  end
 end
diff --git a/lib/grpc/stub.ex b/lib/grpc/stub.ex
index a774d2b..6dab7dd 100644
--- a/lib/grpc/stub.ex
+++ b/lib/grpc/stub.ex
@@ -143,9 +143,13 @@ defmodule GRPC.Stub do
   end
 
   def connect(host, port, opts) when is_integer(port) do
-    adapter =
-      Keyword.get(opts, :adapter) ||
-        Application.get_env(:grpc, :http2_client_adapter, GRPC.Client.Adapters.Gun)
+    if Application.get_env(:grpc, :http2_client_adapter) do
+      raise "the :http2_client_adapter config key has been deprecated.\
+      The currently supported way is to configure it\
+      through the :adapter option for GRPC.Stub.connect/3"
+    end
+
+    adapter = Keyword.get(opts, :adapter) || GRPC.Client.Adapters.Gun
 
     cred = Keyword.get(opts, :cred)
     scheme = if cred, do: @secure_scheme, else: @insecure_scheme
diff --git a/lib/mix/tasks/grpc.server.ex b/lib/mix/tasks/grpc.server.ex
deleted file mode 100644
index d0e856e..0000000
--- a/lib/mix/tasks/grpc.server.ex
+++ /dev/null
@@ -1,24 +0,0 @@
-defmodule Mix.Tasks.Grpc.Server do
-  use Mix.Task
-
-  @shortdoc "Starts applications and their servers"
-
-  @moduledoc """
-  Starts the application by configuring `start_server` to true.
-
-  The `--no-halt` flag is automatically added.
-  """
-  @impl true
-  def run(args) do
-    Application.put_env(:grpc, :start_server, true, persistent: true)
-    Mix.Task.run("run", run_args() ++ args)
-  end
-
-  defp run_args do
-    if iex_running?(), do: [], else: ["--no-halt"]
-  end
-
-  defp iex_running? do
-    Code.ensure_loaded?(IEx) and IEx.started?()
-  end
-end


Test patch:
diff --git a/examples/helloworld/config/test.exs b/examples/helloworld/config/test.exs
new file mode 100644
index 0000000..becde76
--- /dev/null
+++ b/examples/helloworld/config/test.exs
@@ -0,0 +1,1 @@
+import Config
diff --git a/test/grpc/server/supervisor_test.exs b/test/grpc/server/supervisor_test.exs
index 251be37..e69de01 100644
--- a/test/grpc/server/supervisor_test.exs
+++ b/test/grpc/server/supervisor_test.exs
@@ -7,43 +7,27 @@ defmodule GRPC.Server.SupervisorTest do
     def __meta__(_), do: [FeatureServer]
   end
 
-  setup_all do
-    start_server = Application.get_env(:grpc, :start_server)
-
-    on_exit(fn -> Application.put_env(:grpc, :start_server, start_server) end)
-
-    :ok
-  end
-
   describe "init/1" do
-    test "does not start children if no opts and global env is false" do
-      Application.put_env(:grpc, :start_server, false)
-      assert {:ok, {%{strategy: :one_for_one}, []}} = Supervisor.init({MockEndpoint, 1234})
-    end
-
-    test "does not start children if opts sets false and global env is true" do
-      Application.put_env(:grpc, :start_server, true)
-
+    test "does not start children if opts sets false" do
       assert {:ok, {%{strategy: :one_for_one}, []}} =
-               Supervisor.init({MockEndpoint, 1234, start_server: false})
+               Supervisor.init(endpoint: MockEndpoint, port: 1234, start_server: false)
     end
 
-    test "does not start children if opts sets true and global env is false" do
-      Application.put_env(:grpc, :start_server, false)
-
-      endpoint_str = "#{Macro.to_string(MockEndpoint)}"
-
-      assert {:ok,
-              {%{strategy: :one_for_one},
-               [
-                 {{:ranch_listener_sup, ^endpoint_str}, _, :permanent, :infinity, :supervisor,
-                  [:ranch_listener_sup]}
-               ]}} = Supervisor.init({MockEndpoint, 1234, start_server: true})
+    test "fails if a tuple is passed" do
+      assert_raise ArgumentError,
+                   "passing a tuple as configuration for GRPC.Server.Supervisor is no longer supported. See the documentation for more information on how to configure.",
+                   fn ->
+                     Supervisor.init({MockEndpoint, 1234})
+                   end
+
+      assert_raise ArgumentError,
+                   "passing a tuple as configuration for GRPC.Server.Supervisor is no longer supported. See the documentation for more information on how to configure.",
+                   fn ->
+                     Supervisor.init({MockEndpoint, 1234, start_server: true})
+                   end
     end
 
-    test "does not start children if opts sets true and global env is true" do
-      Application.put_env(:grpc, :start_server, true)
-
+    test "starts children if opts sets true" do
       endpoint_str = "#{Macro.to_string(MockEndpoint)}"
 
       assert {:ok,
@@ -51,7 +35,7 @@ defmodule GRPC.Server.SupervisorTest do
                [
                  {{:ranch_listener_sup, ^endpoint_str}, _, :permanent, :infinity, :supervisor,
                   [:ranch_listener_sup]}
-               ]}} = Supervisor.init({MockEndpoint, 1234, start_server: true})
+               ]}} = Supervisor.init(endpoint: MockEndpoint, port: 1234, start_server: true)
     end
   end
 end