-
Notifications
You must be signed in to change notification settings - Fork 46
/
consumer_cancellation_notification_spec.rb
76 lines (56 loc) · 1.58 KB
/
consumer_cancellation_notification_spec.rb
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
68
69
70
71
72
73
74
75
76
RSpec.describe "Non-blocking consumer" do
let(:connection) do
MarchHare.connect
end
after :each do
connection.close if connection.open?
end
let(:queue_name) { "basic.consume#{rand}" }
it "supports consumer cancellation notifications" do
cancelled = false
ch = connection.create_channel
ch2 = connection.create_channel
q = ch2.queue(queue_name, :auto_delete => true)
q.subscribe(:on_cancellation => Proc.new { |_ch, consumer| cancelled = true }) do |_, _|
# no-op
end
sleep 0.5
x = ch.default_exchange
x.publish("abc", :routing_key => queue_name)
sleep 0.5
ch.queue(queue_name, :auto_delete => true).delete
sleep 0.5
expect(cancelled).to eq(true)
ch.close
end
end
RSpec.describe "Blocking consumer" do
let(:connection) do
MarchHare.connect
end
after :each do
connection.close if connection.open?
end
let(:queue_name) { "basic.consume#{rand}" }
it "supports consumer cancellation notifications" do
cancelled = false
ch = connection.create_channel
t = Thread.new do
ch2 = connection.create_channel
q = ch2.queue(queue_name, :auto_delete => true)
q.subscribe(:on_cancellation => Proc.new { |_ch, consumer| cancelled = true }, :block => true) do |_, _|
# no-op
end
end
t.abort_on_exception = true
sleep 0.5
x = ch.default_exchange
x.publish("abc", :routing_key => queue_name)
sleep 0.5
ch.queue(queue_name, :auto_delete => true).delete
sleep 0.5
expect(cancelled).to eq(true)
t.kill
ch.close
end
end