Sha256: 169d7d827043829473abd64e541841e9a8f29dfc09814551d91789e1430b6b6c

Contents?: true

Size: 1.85 KB

Versions: 46

Compression:

Stored size: 1.85 KB

Contents

require "spec_helper"

describe Bunny::Channel, "#basic_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

  let(:queue_name) { "bunny.queues.#{rand}" }

  it "returns basic.cancel-ok" do
    ch = connection.create_channel
    q  = ch.queue("", :exclusive => true)

    consume_ok = ch.basic_consume(q, "")
    cancel_ok  = ch.basic_cancel(consume_ok.consumer_tag)

    cancel_ok.should be_instance_of(AMQ::Protocol::Basic::CancelOk)
    cancel_ok.consumer_tag.should == consume_ok.consumer_tag

    ch.close
  end

  context "when the given consumer tag is valid" do
    let(:queue_name) { "bunny.basic.cancel.queue#{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)
        consume_ok = ch.basic_consume(q, "", true, false) do |_, _, payload|
          delivered_data << payload
        end

        consume_ok.consumer_tag.should_not be_nil
        cancel_ok = ch.basic_cancel(consume_ok.consumer_tag)
        cancel_ok.consumer_tag.should == consume_ok.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 "when the given consumer tag is invalid (was never registered)" do
    it "DOES NOT cause a channel error" do
      ch = connection.create_channel

      # RabbitMQ 3.1 does not raise an exception w/ unknown consumer tag. MK.
      ch.basic_cancel("878798s7df89#{rand}#{Time.now.to_i}")

      ch.close
    end
  end
end

Version data entries

46 entries across 46 versions & 1 rubygems

Version Path
bunny-1.0.0.rc1 spec/lower_level_api/integration/basic_cancel_spec.rb
bunny-0.10.7 spec/lower_level_api/integration/basic_cancel_spec.rb
bunny-0.10.6 spec/lower_level_api/integration/basic_cancel_spec.rb
bunny-1.0.0.pre6 spec/lower_level_api/integration/basic_cancel_spec.rb
bunny-0.10.5 spec/lower_level_api/integration/basic_cancel_spec.rb
bunny-1.0.0.pre5 spec/lower_level_api/integration/basic_cancel_spec.rb
bunny-0.10.4 spec/lower_level_api/integration/basic_cancel_spec.rb
bunny-0.10.3 spec/lower_level_api/integration/basic_cancel_spec.rb
bunny-1.0.0.pre4 spec/lower_level_api/integration/basic_cancel_spec.rb
bunny-0.10.2 spec/lower_level_api/integration/basic_cancel_spec.rb
bunny-0.10.1 spec/lower_level_api/integration/basic_cancel_spec.rb
bunny-0.10.0 spec/lower_level_api/integration/basic_cancel_spec.rb
bunny-1.0.0.pre3 spec/lower_level_api/integration/basic_cancel_spec.rb
bunny-0.9.8 spec/lower_level_api/integration/basic_cancel_spec.rb
bunny-1.0.0.pre2 spec/lower_level_api/integration/basic_cancel_spec.rb
bunny-0.9.7 spec/lower_level_api/integration/basic_cancel_spec.rb
bunny-0.9.6 spec/lower_level_api/integration/basic_cancel_spec.rb
bunny-0.9.5 spec/lower_level_api/integration/basic_cancel_spec.rb
bunny-0.9.4 spec/lower_level_api/integration/basic_cancel_spec.rb
bunny-1.0.0.pre1 spec/lower_level_api/integration/basic_cancel_spec.rb