diff --git a/lib/amqp/application/connection.ex b/lib/amqp/application/connection.ex index fdf6916..9a14b22 100644 --- a/lib/amqp/application/connection.ex +++ b/lib/amqp/application/connection.ex @@ -37,6 +37,13 @@ defmodule AMQP.Application.Connection do GenServer.start_link(__MODULE__, init_arg, name: name) end + @doc false + def start(opts) do + {name, init_arg} = link_opts_to_init_arg(opts) + + GenServer.start(__MODULE__, init_arg, name: name) + end + defp link_opts_to_init_arg(opts) do proc_name = Keyword.get(opts, :proc_name, :default) server_name = get_server_name(proc_name) @@ -145,7 +152,7 @@ defmodule AMQP.Application.Connection do %{state | connection: nil, monitor_ref: nil} end - defp close(%{connection: %Connection{} = conn, monior_ref: ref}) do + defp close(%{connection: %Connection{} = conn, monitor_ref: ref}) do if Process.alive?(conn.pid) do Process.demonitor(ref) Connection.close(conn) diff --git a/test/application/channel_test.exs b/test/application/channel_test.exs index 7559de5..eed850f 100644 --- a/test/application/channel_test.exs +++ b/test/application/channel_test.exs @@ -4,10 +4,10 @@ defmodule AMQP.Application.ChnnelTest do alias AMQP.Application.Channel, as: AppChan setup do - {:ok, app_conn_pid} = AppConn.start_link([]) + {:ok, app_conn_pid} = AppConn.start([]) on_exit(fn -> - Process.exit(app_conn_pid, :normal) + GenServer.stop(app_conn_pid) end) [app_conn: app_conn_pid] @@ -18,17 +18,18 @@ defmodule AMQP.Application.ChnnelTest do {:ok, pid} = AppChan.start_link(opts) assert {:ok, %AMQP.Channel{}} = AppChan.get_channel(:test_chan) - Process.exit(pid, :normal) + GenServer.stop(pid, :normal) end test "reconnects when the channel is gone" do opts = [connection: :default, proc_name: :test_chan] - {:ok, _pid} = AppChan.start_link(opts) + {:ok, pid} = AppChan.start_link(opts) {:ok, %AMQP.Channel{} = chan1} = AppChan.get_channel(:test_chan) AMQP.Channel.close(chan1) :timer.sleep(50) assert {:ok, %AMQP.Channel{} = chan2} = AppChan.get_channel(:test_chan) refute chan1 == chan2 + GenServer.stop(pid) end end diff --git a/test/application/connection_test.exs b/test/application/connection_test.exs index 5efd0aa..8af6601 100644 --- a/test/application/connection_test.exs +++ b/test/application/connection_test.exs @@ -9,16 +9,17 @@ defmodule AMQP.Application.ConnectionTest do {:ok, conn} = AppConn.get_connection(:my_conn) assert %AMQP.Connection{} = conn - Process.exit(pid, :normal) + GenServer.stop(pid) end test "reconnects when the connection is gone" do - {:ok, _pid} = AppConn.start_link([]) + {:ok, pid} = AppConn.start_link([]) {:ok, %AMQP.Connection{} = conn1} = AppConn.get_connection() AMQP.Connection.close(conn1) :timer.sleep(50) assert {:ok, %AMQP.Connection{} = conn2} = AppConn.get_connection() refute conn1 == conn2 + GenServer.stop(pid) end end