Permalink
Browse files

AMQP protocol is asynchronous. queue.message_count does not have to b…

…e in sync with the number of published messages.
  • Loading branch information...
skaes committed Oct 11, 2011
1 parent 640c125 commit 9ae2191f7eb132d9e73d39a703309aabc16f37f5
Showing with 31 additions and 21 deletions.
  1. +16 −11 spec/spec_08/queue_spec.rb
  2. +15 −10 spec/spec_09/queue_spec.rb
View
@@ -16,6 +16,11 @@ def expect_deprecation_warning_for_publishing_on_queue(q, n=1)
Bunny.should_receive(:deprecation_warning).with("Qrack::Queue#publish", "0.8", anything).exactly(n).times
end
+ def message_count(queue, sleep_time = 0.1)
+ sleep sleep_time
+ queue.message_count
+ end
+
before(:each) do
@b = Bunny.new
@b.start
@@ -65,7 +70,7 @@ def expect_deprecation_warning_for_publishing_on_queue(q, n=1)
q = @b.queue('test1')
expect_deprecation_warning_for_publishing_on_queue(q)
q.publish('This is a test message')
- q.message_count.should == 1
+ message_count(q).should == 1
end
it "should be able to pop a message complete with header and delivery details" do
@@ -75,7 +80,7 @@ def expect_deprecation_warning_for_publishing_on_queue(q, n=1)
msg[:header].should be_an_instance_of(Bunny::Protocol::Header)
msg[:payload].should == 'This is a test message'
msg[:delivery_details].should be_an_instance_of(Hash)
- q.message_count.should == 0
+ message_count(q).should == 0
end
it "should be able to pop a message and just get the payload" do
@@ -84,7 +89,7 @@ def expect_deprecation_warning_for_publishing_on_queue(q, n=1)
q.publish('This is another test message')
msg = q.pop[:payload]
msg.should == 'This is another test message'
- q.message_count.should == 0
+ message_count(q).should == 0
end
it "should be able to pop a message where body length exceeds max frame size" do
@@ -108,15 +113,15 @@ def expect_deprecation_warning_for_publishing_on_queue(q, n=1)
q = @b.queue('test1')
expect_deprecation_warning_for_publishing_on_queue(q, 5)
5.times {q.publish('This is another test message')}
- q.message_count.should == 5
+ message_count(q).should == 5
lambda {q.purge(:queue => 'bogus')}.should raise_error(Bunny::ForcedChannelCloseError)
end
it "should be able to be purged to remove all of its messages" do
q = @b.queue('test1')
- q.message_count.should == 5
+ message_count(q).should == 5
q.purge.should == :purge_ok
- q.message_count.should == 0
+ message_count(q).should == 0
end
it "should return an empty message when popping an empty queue" do
@@ -132,17 +137,17 @@ def expect_deprecation_warning_for_publishing_on_queue(q, n=1)
q = @b.queue('test1')
expect_deprecation_warning_for_publishing_on_queue(q, 5)
5.times {q.publish('Yet another test message')}
- q.message_count.should == 5
+ message_count(q).should == 5
q.subscribe(:message_max => 0)
- q.message_count.should == 5
+ message_count(q).should == 5
q.purge.should == :purge_ok
end
it "should stop subscription after processing number of messages specified > 0" do
q = @b.queue('test1')
expect_deprecation_warning_for_publishing_on_queue(q, 5)
5.times {q.publish('Yet another test message')}
- q.message_count.should == 5
+ message_count(q).should == 5
q.subscribe(:message_max => 5)
end
@@ -151,9 +156,9 @@ def expect_deprecation_warning_for_publishing_on_queue(q, n=1)
@b.qos()
expect_deprecation_warning_for_publishing_on_queue(q, 10)
10.times {q.publish('Yet another test message')}
- q.message_count.should == 10
+ message_count(q).should == 10
q.subscribe(:message_max => 5, :ack => true)
- q.message_count.should == 5
+ message_count(q).should == 5
q.purge.should == :purge_ok
end
View
@@ -19,6 +19,11 @@
@default_exchange = @b.exchange("")
end
+ def message_count(queue, sleep_time = 0.1)
+ sleep sleep_time
+ queue.message_count
+ end
+
it "should ignore the :nowait option when instantiated" do
q = @b.queue('test0', :nowait => true)
end
@@ -67,15 +72,15 @@
msg[:header].should be_an_instance_of(Bunny::Protocol09::Header)
msg[:payload].should == 'This is a test message'
msg[:delivery_details].should be_an_instance_of(Hash)
- q.message_count.should == 0
+ message_count(q).should == 0
end
it "should be able to pop a message and just get the payload" do
q = @b.queue('test1')
@default_exchange.publish('This is another test message', :key => 'test1')
msg = q.pop[:payload]
msg.should == 'This is another test message'
- q.message_count.should == 0
+ message_count(q).should == 0
end
it "should be able to pop a message where body length exceeds max frame size" do
@@ -96,15 +101,15 @@
it "should raise an error if purge fails" do
q = @b.queue('test1')
5.times { @default_exchange.publish('This is another test message', :key => 'test1') }
- q.message_count.should == 5
+ message_count(q).should == 5
lambda {q.purge(:queue => 'bogus')}.should raise_error(Bunny::ForcedChannelCloseError)
end
it "should be able to be purged to remove all of its messages" do
q = @b.queue('test1')
- q.message_count.should == 5
+ message_count(q).should == 5
q.purge.should == :purge_ok
- q.message_count.should == 0
+ message_count(q).should == 0
end
it "should return an empty message when popping an empty queue" do
@@ -118,26 +123,26 @@
it "should stop subscription without processing messages if max specified is 0" do
q = @b.queue('test1')
5.times { @default_exchange.publish('Yet another test message', :key => 'test1') }
- q.message_count.should == 5
+ message_count(q).should == 5
q.subscribe(:message_max => 0)
- q.message_count.should == 5
+ message_count(q).should == 5
q.purge.should == :purge_ok
end
it "should stop subscription after processing number of messages specified > 0" do
q = @b.queue('test1')
5.times { @default_exchange.publish('Yet another test message', :key => 'test1') }
- q.message_count.should == 5
+ message_count(q).should == 5
q.subscribe(:message_max => 5)
end
it "should stop subscription after processing message_max messages < total in queue" do
q = @b.queue('test1')
@b.qos()
10.times { @default_exchange.publish('Yet another test message', :key => 'test1') }
- q.message_count.should == 10
+ message_count(q).should == 10
q.subscribe(:message_max => 5, :ack => true)
- q.message_count.should == 5
+ message_count(q).should == 5
q.purge.should == :purge_ok
end

0 comments on commit 9ae2191

Please sign in to comment.