Sha256: 0ffd4adb0c978b83e3a799e57e9117f3ece36ebcdb8411c4a386e410e96343fb

Contents?: true

Size: 1.8 KB

Versions: 30

Compression:

Stored size: 1.8 KB

Contents

require "spec_helper"

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

  let(:consumer_connection) do
    c = Bunny.new(username: "bunny_reader", password: "reader_password", vhost: "bunny_testbed")
    c.start
    c
  end

  after :each do
    publisher_connection.close if publisher_connection.open?
    consumer_connection.close  if consumer_connection.open?
  end

  context "with automatic acknowledgement mode" do
    let(:queue_name) { "bunny.basic_consume#{rand}" }

    it "registers the consumer" do
      delivered_keys = []
      delivered_data = []

      ch = publisher_connection.create_channel
      # declare the queue because the read-only user won't be able to issue
      # queue.declare
      q  = ch.queue(queue_name, auto_delete: true, durable: false)

      t = Thread.new do
        # give the main thread a bit of time to declare the queue
        sleep 0.5
        ch = consumer_connection.create_channel
        # this connection is read only, use passive declare to only get
        # a reference to the queue
        q  = ch.queue(queue_name, auto_delete: true, durable: false, passive: true)
        q.subscribe(exclusive: false) do |delivery_info, properties, payload|
          delivered_keys << delivery_info.routing_key
          delivered_data << payload
        end
      end
      t.abort_on_exception = true
      sleep 0.5

      x  = ch.default_exchange
      x.publish("hello", routing_key: queue_name)

      sleep 0.7
      expect(delivered_keys).to include(queue_name)
      expect(delivered_data).to include("hello")

      expect(ch.queue(queue_name, auto_delete: true, durable: false).message_count).to eq 0

      ch.close
    end
  end
end # describe

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
bunny-2.19.0 spec/higher_level_api/integration/read_only_consumer_spec.rb
bunny-2.18.0 spec/higher_level_api/integration/read_only_consumer_spec.rb
bunny-2.17.0 spec/higher_level_api/integration/read_only_consumer_spec.rb
bunny-2.16.1 spec/higher_level_api/integration/read_only_consumer_spec.rb
bunny-2.15.0 spec/higher_level_api/integration/read_only_consumer_spec.rb
bunny-2.14.4 spec/higher_level_api/integration/read_only_consumer_spec.rb
bunny-2.14.3 spec/higher_level_api/integration/read_only_consumer_spec.rb
bunny-2.14.2 spec/higher_level_api/integration/read_only_consumer_spec.rb
bunny-2.14.1 spec/higher_level_api/integration/read_only_consumer_spec.rb
bunny-2.13.0 spec/higher_level_api/integration/read_only_consumer_spec.rb
bunny-2.12.1 spec/higher_level_api/integration/read_only_consumer_spec.rb
bunny-2.12.0 spec/higher_level_api/integration/read_only_consumer_spec.rb
bunny-2.12.0.rc1 spec/higher_level_api/integration/read_only_consumer_spec.rb
bunny-2.11.0 spec/higher_level_api/integration/read_only_consumer_spec.rb
bunny-2.11.0.pre1 spec/higher_level_api/integration/read_only_consumer_spec.rb
bunny-2.10.0 spec/higher_level_api/integration/read_only_consumer_spec.rb
bunny-2.9.2 spec/higher_level_api/integration/read_only_consumer_spec.rb
bunny-2.9.1 spec/higher_level_api/integration/read_only_consumer_spec.rb
bunny-2.6.7 spec/higher_level_api/integration/read_only_consumer_spec.rb
bunny-2.7.4 spec/higher_level_api/integration/read_only_consumer_spec.rb