This repository has been archived by the owner on Sep 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathqueue_declare_test.exs
67 lines (55 loc) · 2.3 KB
/
queue_declare_test.exs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
defmodule RabbitHole.Protocol.QueueDeclareTest do
use ExUnit.Case
alias RabbitHole.Protocol.{Connection, Channel, Queue}
@queue "my_queue"
describe "channel and connection kept open" do
setup do
{:ok, conn} = Connection.open()
{:ok, chan} = Channel.open(conn)
{:ok, _} = Queue.delete(chan, @queue)
on_exit(fn ->
:ok = Channel.close(chan)
:ok = Connection.close(conn)
end)
[conn: conn, chan: chan]
end
test "declares a queue with auto-generated name", params do
assert {:ok, queue} = Queue.declare(params.chan)
assert {:ok, another_queue} = Queue.declare(params.chan)
refute queue == another_queue
{:ok, %{message_count: 0}} = Queue.delete(params.chan, queue)
end
test "declares a queue with a specified name", params do
assert {:ok, @queue} = Queue.declare(params.chan, @queue)
# redeclaration of the same queue checks its name and all its params
assert {:ok, @queue} = Queue.declare(params.chan, @queue)
{:ok, %{message_count: 0}} = Queue.delete(params.chan, @queue)
end
test "succeds if a queue with a given name already exits", params do
assert {:ok, @queue} = Queue.declare(params.chan, @queue)
# redeclaration of a queue with :passive checks if a queue with the same name exits
assert {:ok, @queue} = Queue.declare(params.chan, @queue, [:passive])
{:ok, %{message_count: 0}} = Queue.delete(params.chan, @queue)
end
end
describe "channel and connection closed as a result of an error" do
setup do
{:ok, conn} = Connection.open()
{:ok, chan} = Channel.open(conn)
{:ok, _} = Queue.delete(chan, @queue)
[conn: conn, chan: chan]
end
test "fails if a queue with the given name doesn't exists", params do
# NOT_FOUND error
assert {{:shutdown, {:server_initiated_close, 404, _}}, _}
= catch_exit(Queue.declare(params.chan, @queue, [:passive]))
end
test "fails if a queue with different params already exists", params do
# by default the queue is not durable
assert {:ok, @queue} = Queue.declare(params.chan, @queue)
# PRECONDITION_FAILED error
assert {{:shutdown, {:server_initiated_close, 406, _}}, _}
= catch_exit(Queue.declare(params.chan, @queue, [:durable]))
end
end
end