Sha256: 3fefb186f83ea7a90c45f8c4141e4a511ee67c9d6827ade1fb296c02d2b03cee

Contents?: true

Size: 1.35 KB

Versions: 1

Compression:

Stored size: 1.35 KB

Contents

require "spec_helper"

unless ENV["CI"]
  describe "Rapidly opening and closing lots of channels on a non-threaded connection" do
    let(:connection) do
      c = Bunny.new(:user => "bunny_gem", :password => "bunny_password", :vhost => "bunny_testbed", :automatic_recovery => false, :threaded => false)
      c.start
      c
    end

    after :all do
      connection.close
    end

    context "in a single-threaded scenario" do
      let(:n) { 500 }

      it "works correctly" do
        xs = Array.new(n) { connection.create_channel }

        xs.size.should == n
        xs.each do |ch|
          ch.close
        end
      end
    end

    context "in a multi-threaded scenario" do
      # actually, on MRI values greater than ~100 will eventually cause write
      # operations to fail with a timeout (1 second is not enough)
      # which will cause recovery to re-acquire @channel_mutex in Session.
      # Because Ruby's mutexes are not re-entrant, it will raise a ThreadError.
      #
      # But this already demonstrates that within these platform constraints,
      # Bunny is safe to use in such scenarios.
      let(:n) { 20 }

      it "works correctly" do
        n.times do
          t = Thread.new do
            ch = connection.create_channel

            ch.close
          end
          t.abort_on_exception = true
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bunny-0.9.0.pre10 spec/stress/channel_open_stress_with_single_threaded_connection_spec.rb