Sha256: a2e5ca9885e3112dac0150f0961b50a0a70f417388cf11ef92bde1379285577d

Contents?: true

Size: 1.33 KB

Versions: 44

Compression:

Stored size: 1.33 KB

Contents

require "spec_helper"

unless ENV["CI"]
  describe "Rapidly opening and closing lots of channels" do
    let(:connection) do
      c = Bunny.new(:user => "bunny_gem", :password => "bunny_password", :vhost => "bunny_testbed", :automatic_recovery => 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 }
        puts "Opened #{n} channels"

        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

44 entries across 44 versions & 1 rubygems

Version Path
bunny-1.1.0.rc1 spec/stress/channel_open_stress_spec.rb
bunny-1.0.7 spec/stress/channel_open_stress_spec.rb
bunny-1.0.6 spec/stress/channel_open_stress_spec.rb
bunny-1.0.5 spec/stress/channel_open_stress_spec.rb
bunny-1.1.0.pre2 spec/stress/channel_open_stress_spec.rb
bunny-1.1.0.pre1 spec/stress/channel_open_stress_spec.rb
bunny-1.0.4 spec/stress/channel_open_stress_spec.rb
bunny-1.0.3 spec/stress/channel_open_stress_spec.rb
bunny-1.0.2 spec/stress/channel_open_stress_spec.rb
bunny-1.0.1 spec/stress/channel_open_stress_spec.rb
bunny-1.0.0 spec/stress/channel_open_stress_spec.rb
bunny-1.0.0.rc3 spec/stress/channel_open_stress_spec.rb
bunny-1.0.0.rc2 spec/stress/channel_open_stress_spec.rb
bunny-0.10.8 spec/stress/channel_open_stress_spec.rb
bunny-1.0.0.rc1 spec/stress/channel_open_stress_spec.rb
bunny-0.10.7 spec/stress/channel_open_stress_spec.rb
bunny-0.10.6 spec/stress/channel_open_stress_spec.rb
bunny-1.0.0.pre6 spec/stress/channel_open_stress_spec.rb
bunny-0.10.5 spec/stress/channel_open_stress_spec.rb
bunny-1.0.0.pre5 spec/stress/channel_open_stress_spec.rb