Sha256: a60d24afdca2604bec9cb3f468da6dca67d21944897b8939225e0f437c489f02

Contents?: true

Size: 1.82 KB

Versions: 13

Compression:

Stored size: 1.82 KB

Contents

require "spec_helper"

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

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

  after :all 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
      delivered_keys.should include(queue_name)
      delivered_data.should include("hello")

      ch.queue(queue_name, :auto_delete => true, :durable => false).message_count.should == 0

      ch.close
    end
  end
end # describe

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
bunny-0.10.0 spec/higher_level_api/integration/read_only_consumer_spec.rb
bunny-1.0.0.pre3 spec/higher_level_api/integration/read_only_consumer_spec.rb
bunny-0.9.8 spec/higher_level_api/integration/read_only_consumer_spec.rb
bunny-1.0.0.pre2 spec/higher_level_api/integration/read_only_consumer_spec.rb
bunny-0.9.7 spec/higher_level_api/integration/read_only_consumer_spec.rb
bunny-0.9.6 spec/higher_level_api/integration/read_only_consumer_spec.rb
bunny-0.9.5 spec/higher_level_api/integration/read_only_consumer_spec.rb
bunny-0.9.4 spec/higher_level_api/integration/read_only_consumer_spec.rb
bunny-1.0.0.pre1 spec/higher_level_api/integration/read_only_consumer_spec.rb
bunny-0.9.3 spec/higher_level_api/integration/read_only_consumer_spec.rb
bunny-0.9.2 spec/higher_level_api/integration/read_only_consumer_spec.rb
bunny-0.9.1 spec/higher_level_api/integration/read_only_consumer_spec.rb
bunny-0.9.0 spec/higher_level_api/integration/read_only_consumer_spec.rb