Sha256: c31223134b7a0e13a6efb4dfdfe616ccb9ea7e077a1682f558ec98b8b2ec1bd5

Contents?: true

Size: 1.85 KB

Versions: 2

Compression:

Stored size: 1.85 KB

Contents

require "spec_helper"

describe Bunny::Consumer, "#cancel" do
  let(:connection) do
    c = Bunny.new(:user => "bunny_gem", :password => "bunny_password", :vhost => "bunny_testbed")
    c.start
    c
  end

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

  context "with a non-blocking consumer" do
    let(:queue_name) { "bunny.queues.#{rand}" }

    it "cancels the consumer" do
      delivered_data = []

      t = Thread.new do
        ch         = connection.create_channel
        q          = ch.queue(queue_name, :auto_delete => true, :durable => false)
        consumer = q.subscribe(:block => false) do |_, _, payload|
          delivered_data << payload
        end

        consumer.consumer_tag.should_not be_nil
        cancel_ok = consumer.cancel
        cancel_ok.consumer_tag.should == consumer.consumer_tag

        ch.close
      end
      t.abort_on_exception = true
      sleep 0.5

      ch = connection.create_channel
      ch.default_exchange.publish("", :routing_key => queue_name)

      sleep 0.7
      delivered_data.should be_empty
    end
  end


  context "with a blocking consumer" do
    let(:queue_name) { "bunny.queues.#{rand}" }

    it "cancels the consumer" do
      delivered_data = []
      consumer       = nil

      t = Thread.new do
        ch         = connection.create_channel
        q          = ch.queue(queue_name, :auto_delete => true, :durable => false)

        consumer   = Bunny::Consumer.new(ch, q)
        consumer.on_delivery do |_, _, payload|
          delivered_data << payload
        end

        q.subscribe_with(consumer, :block => false)
      end
      t.abort_on_exception = true
      sleep 0.5

      consumer.cancel
      sleep 0.5

      ch = connection.create_channel
      ch.default_exchange.publish("", :routing_key => queue_name)

      sleep 0.7
      delivered_data.should be_empty
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bunny-0.9.1 spec/higher_level_api/integration/basic_cancel_spec.rb
bunny-0.9.0 spec/higher_level_api/integration/basic_cancel_spec.rb