Sha256: c61edd790d17e546b625b226317b0ca4d8762a958e717c58d3d2f099285d32c2

Contents?: true

Size: 1.09 KB

Versions: 5

Compression:

Stored size: 1.09 KB

Contents

# -*- coding: utf-8 -*-
require "spec_helper"

unless ENV["CI"]
  describe "Concurrent publishers sharing a connection" do
    before :all do
      @connection = Bunny.new(:user => "bunny_gem", :password => "bunny_password", :vhost => "bunny_testbed", :automatically_recover => false)
      @connection.start
    end

    after :all do
      @connection.close
    end

    let(:concurrency) { 24 }
    let(:rate)        { 5_000 }

    it "successfully finish publishing" do
      body = "сообщение"

      chs  = {}
      concurrency.times do |i|
        ch     = @connection.create_channel
        ch.confirm_select
        chs[i] = ch
      end

      ts = []

      concurrency.times do |i|
        t = Thread.new do
          cht = chs[i]
          x   = cht.default_exchange

          rate.times do
            x.publish(body)
          end
          puts "Published #{rate} messages..."
          cht.wait_for_confirms
        end
        t.abort_on_exception = true

        ts << t
      end

      ts.each do |t|
        t.join
      end

      chs.each { |_, ch| ch.close }
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
bunny-2.6.1 spec/stress/concurrent_publishers_stress_spec.rb
bunny-2.6.0 spec/stress/concurrent_publishers_stress_spec.rb
bunny-2.5.1 spec/stress/concurrent_publishers_stress_spec.rb
bunny-2.5.0 spec/stress/concurrent_publishers_stress_spec.rb
bunny-2.4.0 spec/stress/concurrent_publishers_stress_spec.rb