Sha256: 953ba4705d021912fdc7e60d2b4c0db6da290fef7d0d33984ebdff6511580e49

Contents?: true

Size: 1.1 KB

Versions: 2

Compression:

Stored size: 1.1 KB

Contents

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

describe "Concurrent publishers sharing a connection" do
  let(:connection) do
    c = Bunny.new(:user => "bunny_gem", :password => "bunny_password", :vhost => "bunny_testbed", :automatically_recover => false)
    c.start
    c
  end

  after :all do
    connection.close
  end

  let(:n) { 32 }
  let(:m) { 1000 }

  it "successfully finish publishing" do
    ch = connection.create_channel

    q    = ch.queue("", :exclusive => true)
    body = "сообщение"

    # let the queue name be sent back by RabbitMQ
    sleep 0.25

    chs  = {}
    n.times do |i|
      chs[i] = connection.create_channel
    end

    ts = []

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

        5.times do |i|
          m.times do
            x.publish(body, :routing_key => q.name)
          end
          puts "Published #{(i + 1) * m} messages..."
        end
      end
      t.abort_on_exception = true

      ts << t
    end

    ts.each do |t|
      t.join
    end

    sleep 4.0
    q.message_count.should == 5 * n * m
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bunny-0.9.0.pre9 spec/stress/concurrent_publishers_stress_spec.rb
bunny-0.9.0.pre8 spec/stress/concurrent_publishers_stress_spec.rb