Sha256: 3d0f5e49703c8ebc096e1410a4da34b83a05e7d2994a69bd1ae7fb058610e24c

Contents?: true

Size: 1.77 KB

Versions: 53

Compression:

Stored size: 1.77 KB

Contents

# encoding: utf-8
require 'spec_helper'

unless ENV["CI"]
  describe "Per-channel automatic channel recovery" do

    #
    # Environment
    #

    include RabbitMQ::Control

    include EventedSpec::AMQPSpec
    default_timeout 20.0

    amqp_before do
      @channel = AMQP::Channel.new(AMQP.connection, :auto_recovery => true)
    end

    after :all do
      start_rabbitmq unless rabbitmq_pid
    end

    # ...


    #
    # Examples
    #

    it "kicks in when broker goes down" do
      AMQP.connection.on_tcp_connection_loss do |conn, settings|
        puts "[network failure] Trying to reconnect..."
        conn.reconnect(false, 1)
      end

      pid = rabbitmq_pid
      puts "rabbitmq pid = #{pid.inspect}"

      kill_rabbitmq
      rabbitmq_pid.should be_nil

      # 2 seconds later, check that we are reconnecting
      EventMachine.add_timer(2.0) do
        AMQP.connection.should_not be_connected
        AMQP.connection.should be_reconnecting
      end


      # 4 seconds later, start RabbitMQ
      EventMachine.add_timer(4.0) do
        start_rabbitmq
        rabbitmq_pid.should_not be_nil
      end

      # 12 seconds later, use the (now recovered) connection. Note that depending
      # on # of plugins used it may take 5-10 seconds to start up RabbitMQ and initialize it,
      # then open a new AMQP connection. That's why we wait. MK.
      EventMachine.add_timer(12.0) do
        AMQP.connection.should be_connected
        AMQP.connection.should_not be_reconnecting

        @channel.queue("amqpgem.tests.a.queue", :auto_delete => true).subscribe do |metadata, payload|
          puts "Got a message"
          done
        end

        EventMachine.add_timer(1.5) { @channel.default_exchange.publish("Hi", :routing_key => "amqpgem.tests.a.queue") }
      end
    end
  end
end

Version data entries

53 entries across 53 versions & 1 rubygems

Version Path
amqp-1.8.0 spec/integration/recovery/per_channel_automatic_recovery_spec.rb
amqp-1.7.0 spec/integration/recovery/per_channel_automatic_recovery_spec.rb
amqp-1.6.0 spec/integration/recovery/per_channel_automatic_recovery_spec.rb
amqp-1.5.3 spec/integration/recovery/per_channel_automatic_recovery_spec.rb
amqp-1.5.2 spec/integration/recovery/per_channel_automatic_recovery_spec.rb
amqp-1.5.1 spec/integration/recovery/per_channel_automatic_recovery_spec.rb
amqp-1.5.0 spec/integration/recovery/per_channel_automatic_recovery_spec.rb
amqp-1.4.2 spec/integration/recovery/per_channel_automatic_recovery_spec.rb
amqp-1.4.1 spec/integration/recovery/per_channel_automatic_recovery_spec.rb
amqp-1.4.0 spec/integration/recovery/per_channel_automatic_recovery_spec.rb
amqp-1.3.0 spec/integration/recovery/per_channel_automatic_recovery_spec.rb
amqp-1.2.1 spec/integration/recovery/per_channel_automatic_recovery_spec.rb
amqp-1.2.0 spec/integration/recovery/per_channel_automatic_recovery_spec.rb
amqp-1.1.8 spec/integration/recovery/per_channel_automatic_recovery_spec.rb
amqp-1.1.7 spec/integration/recovery/per_channel_automatic_recovery_spec.rb
amqp-1.1.6 spec/integration/recovery/per_channel_automatic_recovery_spec.rb
amqp-1.1.5 spec/integration/recovery/per_channel_automatic_recovery_spec.rb
amqp-1.1.4 spec/integration/recovery/per_channel_automatic_recovery_spec.rb
amqp-1.1.3 spec/integration/recovery/per_channel_automatic_recovery_spec.rb
amqp-1.0.4 spec/integration/recovery/per_channel_automatic_recovery_spec.rb