Packages

Elixir messaging library using RabbitMQ, providing easy-to-use modules for message publishing, consuming, and retry handling

Current section

Files

Jump to
hare_mq lib connection connection_test.exs
Raw

lib/connection/connection_test.exs

defmodule HareMq.ConnectionTest do
use HareMq.TestCase
alias HareMq.Connection
setup do
Application.put_env(:hare_mq, :configuration, %{reconnect_interval_ms: 100})
stop_global(HareMq.Connection)
on_exit(fn -> stop_global(HareMq.Connection) end)
end
test "successfully connects and gets connection" do
{:ok, _pid} = Connection.start_link([])
assert wait_until(fn -> {:ok, %AMQP.Connection{}} = Connection.get_connection() end)
end
test "fails to get connection when not connected" do
assert {:error, :not_connected} = Connection.get_connection()
end
test "successfully closes the connection" do
{:ok, _pid} = Connection.start_link([])
assert wait_until(fn -> {:ok, %AMQP.Connection{}} = Connection.get_connection() end)
# Close the connection
assert wait_until(fn -> {:ok, %AMQP.Connection{}} = Connection.close_connection() end)
# Verify that the connection is indeed closed
assert wait_until(fn -> {:error, :not_connected} = Connection.get_connection() end)
end
test "fails to close connection when not connected" do
{:ok, _pid} = Connection.start_link([])
assert wait_until(fn -> {:ok, %AMQP.Connection{}} = Connection.close_connection() end)
assert wait_until(fn -> {:error, :not_connected} = Connection.close_connection() end)
end
end