File: basic_consume_with_objects_spec.rb

package info (click to toggle)
ruby-bunny 2.23.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,644 kB
  • sloc: ruby: 10,256; sh: 70; makefile: 8
file content (54 lines) | stat: -rw-r--r-- 1,313 bytes parent folder | download | duplicates (5)
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
require "spec_helper"
require "set"

describe Bunny::Queue, "#subscribe_with" do
  let(:connection) do
    c = Bunny.new(username: "bunny_gem", password: "bunny_password", vhost: "bunny_testbed")
    c.start
    c
  end

  after :each do
    connection.close if connection.open?
  end

  context "with explicit acknowledgements mode" do
    class ExampleConsumer < Bunny::Consumer
      def cancelled?
        @cancelled
      end

      def handle_cancellation(_)
        @cancelled = true
      end

      def call(delivery_info, metadata, payload)
         # no-op
      end
    end

    # demonstrates that manual acknowledgement mode is actually
    # used. MK.
    it "requeues messages on channel closure" do
      ch1  = connection.create_channel
      ch2  = connection.create_channel
      q1   = ch1.queue("bunny.tests.consumer_object1", exclusive: true)
      q2   = ch2.queue("bunny.tests.consumer_object1", exclusive: true)
      ec   = ExampleConsumer.new(ch1, q1, "", false)
      x    = ch2.default_exchange

      t = Thread.new do
        50.times do
          x.publish("hello", routing_key: q2.name)
        end
      end
      t.abort_on_exception = true

      q1.subscribe_with(ec, manual_ack: true)
      sleep 2
      ch1.close

      expect(q2.message_count).to eq 50
    end
  end
end