Sha256: 4a7562606d8de210f803ae74c2cd1fa9be82bff88eeb4586fa18dac8876966de

Contents?: true

Size: 1.92 KB

Versions: 32

Compression:

Stored size: 1.92 KB

Contents

require "spec_helper"

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

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

  context "with a valid (known) delivery tag" do
    it "acknowledges a message" do
      ch = connection.create_channel
      q  = ch.queue("bunny.basic.ack.manual-acks", :exclusive => true)
      x  = ch.default_exchange

      x.publish("bunneth", :routing_key => q.name)
      sleep 0.5
      q.message_count.should == 1
      delivery_details, properties, content = q.pop(:ack => true)

      ch.ack(delivery_details.delivery_tag, true)
      q.message_count.should == 0

      ch.close
    end
  end


  context "with a valid (known) delivery tag and automatic ack mode" do
    it "results in a channel exception" do
      ch = connection.create_channel
      q  = ch.queue("bunny.basic.ack.manual-acks", :exclusive => true)
      x  = ch.default_exchange

      q.subscribe(:manual_ack => false) do |delivery_info, properties, payload|
        ch.ack(delivery_info.delivery_tag, false)
      end

      x.publish("bunneth", :routing_key => q.name)
      sleep 0.5
      lambda do
        q.message_count
      end.should raise_error(Bunny::ChannelAlreadyClosed)
    end
  end

  context "with an invalid (random) delivery tag" do
    it "causes a channel-level error" do
      ch = connection.create_channel
      q  = ch.queue("bunny.basic.ack.unknown-delivery-tag", :exclusive => true)
      x  = ch.default_exchange

      x.publish("bunneth", :routing_key => q.name)
      sleep 0.5
      q.message_count.should == 1
      _, _, content = q.pop(:ack => true)

      ch.on_error do |ch, channel_close|
        @channel_close = channel_close
      end
      ch.ack(82, true)
      sleep 0.25

      @channel_close.reply_code.should == AMQ::Protocol::PreconditionFailed::VALUE
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
bunny-1.4.1 spec/higher_level_api/integration/basic_ack_spec.rb
bunny-1.4.0 spec/higher_level_api/integration/basic_ack_spec.rb
bunny-1.3.1 spec/higher_level_api/integration/basic_ack_spec.rb
bunny-1.3.0 spec/higher_level_api/integration/basic_ack_spec.rb
bunny-1.2.2 spec/higher_level_api/integration/basic_ack_spec.rb
bunny-1.2.1 spec/higher_level_api/integration/basic_ack_spec.rb
bunny-1.2.0 spec/higher_level_api/integration/basic_ack_spec.rb
bunny-1.1.9 spec/higher_level_api/integration/basic_ack_spec.rb
bunny-1.1.8 spec/higher_level_api/integration/basic_ack_spec.rb
bunny-1.1.7 spec/higher_level_api/integration/basic_ack_spec.rb
bunny-1.1.6 spec/higher_level_api/integration/basic_ack_spec.rb
bunny-1.1.5 spec/higher_level_api/integration/basic_ack_spec.rb
bunny-1.1.4 spec/higher_level_api/integration/basic_ack_spec.rb
bunny-1.1.3 spec/higher_level_api/integration/basic_ack_spec.rb
bunny-1.1.2 spec/higher_level_api/integration/basic_ack_spec.rb
bunny-1.1.1 spec/higher_level_api/integration/basic_ack_spec.rb
bunny-1.1.0 spec/higher_level_api/integration/basic_ack_spec.rb
bunny-1.1.0.rc1 spec/higher_level_api/integration/basic_ack_spec.rb
bunny-1.0.7 spec/higher_level_api/integration/basic_ack_spec.rb
bunny-1.0.6 spec/higher_level_api/integration/basic_ack_spec.rb