/
15-queue.t
65 lines (47 loc) · 2.22 KB
/
15-queue.t
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
use v6.c;
use Test;
plan 14;
use Net::AMQP;
my $n = Net::AMQP.new;
my $initial-promise = $n.connect;
my $timeout = Promise.in(5);
try await Promise.anyof($initial-promise, $timeout);
unless $initial-promise.status == Kept {
skip-rest "Unable to connect. Please run RabbitMQ on localhost with default credentials.";
exit;
}
my $channel-promise = $n.open-channel(1);
my $channel = $channel-promise.result;
my $queue-promise = $channel.declare-queue("foobaz");
await $queue-promise;
is $queue-promise.status, Kept, "Can declare new queue";
isa-ok $queue-promise.result, Net::AMQP::Queue, "and there is a queue back";
my $queue-delete-promise = $queue-promise.result.delete;
await $queue-delete-promise;
is $queue-delete-promise.status, Kept, "Can delete queue";
$queue-promise = $channel.declare-queue("");
await $queue-promise;
is $queue-promise.status, Kept, "Can declare new queue without an explicit name";
ok $queue-promise.result.name, "and it has the auto-generated name now ({ $queue-promise.result.name })";
$queue-delete-promise = $queue-promise.result.delete;
await $queue-delete-promise;
is $queue-delete-promise.status, Kept, "Can delete that queue";
# declare-queue with no name
lives-ok { $queue-promise = $channel.declare-queue() }, "declare-queue with no name";
await $queue-promise;
is $queue-promise.status, Kept, "Can declare new queue without an explicit name";
ok $queue-promise.result.name, "and it has the auto-generated name now ({ $queue-promise.result.name })";
$queue-delete-promise = $queue-promise.result.delete;
await $queue-delete-promise;
is $queue-delete-promise.status, Kept, "Can delete that queue";
lives-ok { $queue-promise = $channel.declare-queue(:durable, :exclusive) }, "declare-queue with no name but a switch";
await $queue-promise;
is $queue-promise.status, Kept, "Can declare new queue without an explicit name";
ok $queue-promise.result.name, "and it has the auto-generated name now ({ $queue-promise.result.name })";
$queue-delete-promise = $queue-promise.result.delete;
await $queue-delete-promise;
is $queue-delete-promise.status, Kept, "Can delete that queue";
my $chan-close-promise = $channel.close("", "");
await $chan-close-promise;
await $n.close("", "");
# vim: expandtab shiftwidth=4 ft=perl6