Example #1
0
    def test_resumeProducing(self):
        # Check the resumeProducing method.
        self.protocol._running = False
        callback = mock.Mock()
        self.protocol._consumers = {
            "testqueue1":
            Consumer("consumer1", "testqueue1", callback,
                     self.protocol._channel),
            "testqueue2":
            Consumer("consumer2", "testqueue2", callback,
                     self.protocol._channel),
            "testqueue3":
            Consumer("consumer3", "testqueue3", callback,
                     self.protocol._channel),
        }
        self.protocol._read = mock.Mock(
            side_effect=lambda _, __: defer.succeed(None))
        d = self.protocol.resumeProducing()

        def _check(_):
            self.assertTrue(self.protocol._running)
            self.assertEqual(self.protocol._channel.basic_consume.call_count,
                             3)
            called_queues = [
                kw["queue"] for arg, kw in
                self.protocol._channel.basic_consume.call_args_list
            ]
            self.assertEqual(sorted(called_queues),
                             sorted(self.protocol._consumers.keys()))
            self.assertEqual(self.protocol._read.call_count, 3)

        d.addCallback(_check)
        return pytest_twisted.blockon(d)
Example #2
0
 def setUp(self):
     self.protocol = MockProtocol(None)
     self.protocol._running = True
     self.protocol._impl.is_closed = False
     self.protocol._on_message = mock.Mock()
     self.queue = mock.Mock()
     self.consumer = Consumer("consumer1", "my_queue_name", lambda _: _, mock.Mock())
Example #3
0
 def setUp(self):
     self.protocol = MockProtocol(None)
     self._message_callback = mock.Mock()
     self.protocol._impl.is_closed = False
     self.protocol._consumers["my_queue_name"] = Consumer(
         "consumer1", "my_queue_name", self._message_callback, mock.Mock()
     )
Example #4
0
    def test_pauseProducing(self):
        # Check the pauseProducing method.
        self.protocol._running = True
        self.protocol._consumers = {
            "testqueue1": Consumer("ct1", "testqueue1", None, self.protocol._channel),
            "testqueue2": Consumer("ct2", "testqueue2", None, self.protocol._channel),
        }
        d = self.protocol.pauseProducing()

        def _check(_):
            self.assertFalse(self.protocol._running)
            self.assertEqual(self.protocol._channel.basic_cancel.call_count, 2)
            called_cts = [
                kw["consumer_tag"]
                for arg, kw in self.protocol._channel.basic_cancel.call_args_list
            ]
            self.assertEqual(sorted(called_cts), sorted(["ct1", "ct2"]))

        d.addCallback(_check)
        return pytest_twisted.blockon(d)
Example #5
0
    def test_cancel_channel_error(self):
        """Assert channel errors are caught; a closed channel cancels consumers."""
        consumer = Consumer("consumer1", "my_queue", lambda _: _, mock.Mock())
        consumer.channel.basic_cancel.side_effect = pika.exceptions.AMQPChannelError(
        )
        self.protocol._consumers = {"my_queue": consumer}

        def _check(_):
            self.assertEqual({}, self.protocol._consumers)
            consumer.channel.basic_cancel.assert_called_once_with(
                consumer_tag=consumer.tag)

        d = self.protocol.consume(consumer.callback, consumer.queue)
        d.addCallback(lambda consumer: self.protocol.cancel(consumer.queue))
        d.addCallback(_check)

        return pytest_twisted.blockon(d)