Sha256: 50ed7f0d2029b4424dcb45be29d9a4332c3e2b68ad3de6218081b6f55e80a417

Contents?: true

Size: 1.56 KB

Versions: 1

Compression:

Stored size: 1.56 KB

Contents

require 'spec_helper'

describe "Firehose amqp resources" do

  let(:channel)   { "/resource-test-#{Time.now.to_i}" }
  let(:consumer)  { Firehose::Consumer.new }

  it "should clean up exchanges and queues" do
    sent, received = 'howdy!', nil
    
    before_exchange_count = `rabbitmqctl list_exchanges`.lines.count
    before_queue_count    = `rabbitmqctl list_queues`.lines.count

    during_exchange_count = nil
    during_queue_count    = nil

    EM.run do
      # Kill test if it runs longer than 5s
      EM.add_timer(5) { EM.stop }

      subscription = Firehose::Subscription.new(consumer, channel)
      subscription.ttl = 1

      subscription.subscribe do |payload|
        received = payload
        subscription.unsubscribe

        during_exchange_count = `rabbitmqctl list_exchanges`.lines.count
        during_queue_count = `rabbitmqctl list_queues`.lines.count

        # I wait 1 second before killing em so that unsubscribe
        # can talk to AMQP before the whole thing dies.
        EM.add_timer(1){ EM.stop }
      end

      # Let the subscriber subscribe before publishing messages.
      EM.add_timer(1){ Firehose::Publisher.new.publish(channel, sent) }
    end

    after_exchange_count = `rabbitmqctl list_exchanges`.lines.count
    after_queue_count =    `rabbitmqctl list_queues`.lines.count

    received.should == sent

    after_exchange_count.should == before_exchange_count
    after_queue_count.should    == before_queue_count

    during_exchange_count.should == before_exchange_count + 1
    during_queue_count.should    == before_queue_count + 1
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
firehose-0.0.16 spec/integrations/amqp_resources_spec.rb