Sha256: 887e9244fffc4e9f8845230f428b763faada652a719b051ce56ff8ec08987133

Contents?: true

Size: 1.54 KB

Versions: 9

Compression:

Stored size: 1.54 KB

Contents

require "spec_helper"

describe Bunny::Session do
  let(:http_client) { RabbitMQ::HTTP::Client.new("http://127.0.0.1:15672") }

  def close_connection(client_port)
    c = http_client.
      list_connections.
      find   { |conn_info| conn_info.peer_port.to_i == client_port }

    http_client.close_connection(c.name)
  end

  def wait_for_recovery
    sleep 0.5
  end

  it "can be closed" do
    c  = Bunny.new(:automatically_recover => false)
    c.start
    ch = c.create_channel

    expect(c).to be_connected
    c.stop
    expect(c).to be_closed
  end

  it "can be closed twice (Session#close is idempotent)" do
    c  = Bunny.new(:automatically_recover => false)
    c.start
    ch = c.create_channel

    expect(c).to be_connected
    c.stop
    expect(c).to be_closed
    c.stop
    expect(c).to be_closed
  end

  describe "in a single threaded mode" do
    it "can be closed" do
      c  = Bunny.new(:automatically_recover => false, :threaded => false)
      c.start
      ch = c.create_channel

      expect(c).to be_connected
      c.stop
      expect(c).to be_closed
    end
  end


  describe "that recovers from connection.close" do
    it "can be closed" do
      c  = Bunny.new(:automatically_recover => false, :recover_from_connection_close => true, :network_recovery_interval => 0.2)
      c.start
      ch = c.create_channel

      expect(c).to be_open
      close_connection(c.local_port)
      sleep 0.2
      expect(c).not_to be_open

      wait_for_recovery
      expect(c).to be_open
      expect(ch).to be_open

      c.close
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
bunny-2.3.0 spec/higher_level_api/integration/connection_stop_spec.rb
bunny-2.2.2 spec/higher_level_api/integration/connection_stop_spec.rb
bunny-2.2.1 spec/higher_level_api/integration/connection_stop_spec.rb
bunny-2.2.0 spec/higher_level_api/integration/connection_stop_spec.rb
bunny-2.1.0 spec/higher_level_api/integration/connection_stop_spec.rb
bunny-2.0.1 spec/higher_level_api/integration/connection_stop_spec.rb
bunny-2.0.0 spec/higher_level_api/integration/connection_stop_spec.rb
bunny-2.0.0.rc2 spec/higher_level_api/integration/connection_stop_spec.rb
bunny-2.0.0.rc1 spec/higher_level_api/integration/connection_stop_spec.rb