def test_drain_consumer(self, eventloop):

        def receive_message(client, **kwargs):
            client.consumer.callbacks[0](1, "foo")
            return [True]

        eventloop.side_effect = receive_message

        consumer = MagicMock()
        client = Mock()

        # nasty circular reference so we can access the callback
        client.consumer = consumer
        consumer.channel.connection.client = client

        assert list(drain_consumer(consumer)) == [(1, 'foo')]
    def test_drain_consumer_no_messages(self, eventloop):

        eventloop.return_value = [True]  # no message arrives

        consumer = MagicMock()
        assert list(drain_consumer(consumer)) == []