Sha256: 99a8ecf230e5e1c03bfdc4b442854a958c5cf191a1a8a0938c6a2c442f493653

Contents?: true

Size: 1.24 KB

Versions: 8

Compression:

Stored size: 1.24 KB

Contents

# frozen_string_literal: true

require 'basquiat/adapters/rabbitmq_adapter'

RSpec.describe Basquiat::Adapters::RabbitMq::Connection do
  subject(:connection) { Basquiat::Adapters::RabbitMq::Connection }

  let(:hosts) do
    [ENV.fetch('BASQUIAT_RABBITMQ_1_PORT_5672_TCP_ADDR') { 'localhost' }]
  end

  it '#connected?' do
    conn = connection.new(hosts: hosts)
    expect(conn.connected?).to be_falsey
    conn.start
    expect(conn.connected?).to_not be_truthy
    conn.disconnect
  end

  context 'failover' do
    let(:failover) do
      { default_timeout: 0.2, max_retries: 2, connection_timeout: 0.3 }
    end

    before(:each) { hosts.unshift('172.168.0.124') }

    it 'tries a reconnection after a few seconds' do
      conn = connection.new(hosts:    ['172.168.0.124'],
                            failover: { default_timeout: 0.2, max_retries: 1 })
      expect { conn.start }.to raise_error(Bunny::TCPConnectionFailed)
      conn.close
    end

    it 'uses another server after all retries on a single one' do
      conn = connection.new(hosts: hosts, failover: failover)
      expect { conn.start }.to_not raise_error
      expect(conn.host).to match(ENV.fetch('BASQUIAT_RABBITMQ_1_PORT_5672_TCP_ADDR') { 'localhost' })
      conn.close
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
basquiat-1.6.0 spec/lib/adapters/rabbitmq/connection_spec.rb
basquiat-1.5.2 spec/lib/adapters/rabbitmq/connection_spec.rb
basquiat-1.5.1 spec/lib/adapters/rabbitmq/connection_spec.rb
basquiat-1.5.0 spec/lib/adapters/rabbitmq/connection_spec.rb
basquiat-1.4.0 spec/lib/adapters/rabbitmq/connection_spec.rb
basquiat-1.3.6 spec/lib/adapters/rabbitmq/connection_spec.rb
basquiat-1.3.5 spec/lib/adapters/rabbitmq/connection_spec.rb
basquiat-1.3.4 spec/lib/adapters/rabbitmq/connection_spec.rb