Skip to content

Commit

Permalink
Merge pull request #547 from markcf/master
Browse files Browse the repository at this point in the history
#544 get_waiting_message_count()
  • Loading branch information
gmr committed Apr 29, 2015
2 parents e7b6d73 + 1583537 commit 6f8c538
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
7 changes: 7 additions & 0 deletions pika/adapters/blocking_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,13 @@ def consume(self, queue, no_ack=False, exclusive=False):
yield self._generator_messages.pop(0)
self.connection.process_data_events()

def get_waiting_message_count(self):
"""Returns the amount of messages waiting in the generator messages list.
:rtype: int
"""
return len(self._generator_messages)

def force_data_events(self, enable):
"""Turn on and off forcing the blocking adapter to stop and look to see
if there are any frames from RabbitMQ in the read buffer. By default
Expand Down
15 changes: 15 additions & 0 deletions tests/unit/blocking_channel_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,18 @@ def test_init_initial_value_wait(self):
def test_init_open_called(self):
self._open.assert_called_once_with()


def test_init_create_generator(self):
self.obj.consume("queue")
self.assertEquals(self.obj.get_waiting_message_count(), 0)


def test_init_value_waiting_message_count(self):
self.obj.consume("queue")
self.obj._generator_messages.append("test")
self.assertEquals(self.obj.get_waiting_message_count(), 1)
self.obj._generator_messages.append("test")
self.assertEquals(self.obj.get_waiting_message_count(), 2)
self.obj._generator_messages.pop(0)
self.assertEquals(self.obj.get_waiting_message_count(), 1)

0 comments on commit 6f8c538

Please sign in to comment.