File: ordering_of_published_messages_spec.rb

package info (click to toggle)
ruby-amqp 1.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 2,508 kB
  • sloc: ruby: 8,272; sh: 11; makefile: 10
file content (96 lines) | stat: -rw-r--r-- 2,112 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# encoding: utf-8

require 'spec_helper'

describe "100 AMQP messages" do

  #
  # Environment
  #

  include EventedSpec::AMQPSpec
  default_options AMQP_OPTS
  default_timeout 5


  before :all do
    @list = Range.new(0, 100, true).to_a
  end


  context "published and received on the same channel" do
    amqp_before do
      @channel   = AMQP::Channel.new
      @channel.on_error do |ch, close|
        raise "Channel-level error!: #{close.inspect}"
      end

      @queue = @channel.queue("amqpgem.tests.integration.queue1", :auto_delete => true)
    end

    #
    # Examples
    #

    it "are received on the same channel in the order of publishing" do
      received = []

      @queue.subscribe do |metadata, payload|
        received << payload.to_i
      end

      EventMachine.add_timer(0.3) do
        @list.each { |i| @channel.default_exchange.publish(i.to_s, :routing_key => @queue.name) }
      end

      done(3.5) {
        received.size.should == 100
        received.first.should == 0
        received.last.should == 99

        received.should == @list
      }
    end
  end


  context "published on two different channels" do
    amqp_before do
      @channel1   = AMQP::Channel.new
      @channel2   = AMQP::Channel.new

      @channel1.on_error do |ch, close|
        raise "Channel-level error!: #{close.inspect}"
      end
      @channel2.on_error do |ch, close|
        raise "Channel-level error!: #{close.inspect}"
      end

      @queue = @channel1.queue("amqpgem.tests.integration.queue1", :auto_delete => true)
    end

    #
    # Examples
    #

    it "are received on the same channel in the order of publishing" do
      received = []

      @queue.subscribe do |metadata, payload|
        received << payload.to_i
      end

      EventMachine.add_timer(0.3) do
        @list.each { |i| @channel2.default_exchange.publish(i.to_s, :routing_key => @queue.name) }
      end

      done(3.5) {
        received.size.should == 100
        received.first.should == 0
        received.last.should == 99

        received.should == @list
      }
    end
  end
end # describe