File: publisher_confirmations_spec.rb

package info (click to toggle)
ruby-amqp 1.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, trixie
  • size: 2,508 kB
  • sloc: ruby: 8,272; sh: 11; makefile: 10
file content (181 lines) | stat: -rw-r--r-- 4,438 bytes parent folder | download | duplicates (2)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# encoding: utf-8

require "spec_helper"

require "amqp/extensions/rabbitmq"


describe "confirm.select" do

  #
  # Environment
  #

  include EventedSpec::AMQPSpec
  include EventedSpec::SpecHelper

  default_options AMQP_OPTS
  default_timeout 3

  amqp_before do
    @channel = AMQP::Channel.new
  end


  context "with :nowait attribute off" do
    it "results in a confirm.select-ok response" do
      @channel.confirm_select do |select_ok|
        done
      end
    end
  end
end




describe "Publisher confirmation(s)" do

  #
  # Environment
  #

  include EventedSpec::AMQPSpec
  include EventedSpec::SpecHelper

  default_options AMQP_OPTS
  default_timeout 3


  amqp_before do
    @channel1 = AMQP::Channel.new
    @channel2 = AMQP::Channel.new
  end

  it 'should increment publisher_index confirming channel' do
    channel3 = AMQP::Channel.new
    exchange = channel3.fanout("amqpgem.tests.fanout0", :auto_delete => true)

    channel3.confirm_select
    channel3.publisher_index.should == 0

    EventMachine.add_timer(0.5) do
      exchange.publish("Hi")
    end

    done(2.0) do
      channel3.publisher_index.should == 1
    end
  end


  context "when messages are transient" do
    context "and routable" do
      it "are confirmed as soon as they arrive on all the queues they were routed to" do
        events   = Array.new

        exchange = @channel2.fanout("amqpgem.tests.fanout1", :auto_delete => true)
        queue    = @channel1.queue("", :auto_delete => true).bind(exchange).subscribe do |metadata, payload|
          events << :basic_delivery
        end

        @channel2.confirm_select
        @channel2.on_ack do |basic_ack|
          events << :basic_ack
        end
        exchange.on_return do |basic_return, metadata, payload|
          fail "Should never happen"
        end

        EventMachine.add_timer(0.5) do
          exchange.publish("Hi", :persistent => false, :mandatory => true)
        end

        done(2.0) do
          events.should include(:basic_ack)
          events.should include(:basic_delivery)
        end
      end
    end


    context "and can be delivered immediately" do
      it "are confirmed as soon as they arrive on all the queues they were routed to" do
        events   = Array.new

        exchange = @channel2.fanout("amqpgem.tests.fanout2", :auto_delete => true)
        queue    = @channel1.queue("", :auto_delete => true).bind(exchange).subscribe do |metadata, payload|
          events << :basic_delivery
        end

        @channel2.confirm_select
        @channel2.on_ack do |basic_ack|
          events << :basic_ack
        end
        exchange.on_return do |basic_return, metadata, payload|
          fail "Should never happen"
        end

        EventMachine.add_timer(0.5) do
          exchange.publish("Hi", :persistent => false)
        end

        done(2.0) do
          events.should include(:basic_ack)
          events.should include(:basic_delivery)
        end
      end
    end



    context "and NOT routable" do
      it "are delivered immediately after basic.return" do
        events   = Array.new

        queue    = @channel1.queue("", :auto_delete => true)
        exchange = @channel2.fanout("amqpgem.tests.fanout3", :auto_delete => true)

        @channel2.confirm_select
        @channel2.on_ack do |basic_ack|
          events << :basic_ack
        end
        exchange.on_return do |basic_return, metadata, payload|
          events << :basic_return
        end

        EventMachine.add_timer(0.5) do
          exchange.publish("Hi", :persistent => false, :mandatory => true)
        end

        done(2.0) { events.should == [:basic_return, :basic_ack] }
      end
    end



    context "and CAN NOT be delivered immediately" do
      it "are delivered immediately after basic.return" do
        events   = Array.new

        queue    = @channel1.queue("", :auto_delete => true)
        exchange = @channel2.fanout("amqpgem.tests.fanout4", :auto_delete => true)

        @channel2.confirm_select
        @channel2.on_ack do |basic_ack|
          events << :basic_ack
        end
        exchange.on_return do |basic_return, metadata, payload|
          events << :basic_return
        end

        EventMachine.add_timer(0.5) do
          exchange.publish("Hi", :persistent => false, :mandatory => true)
        end

        done(2.0) { events.should == [:basic_return, :basic_ack] }
      end
    end

  end
end