예제 #1
0
 def test_on_message_task_fail(self, send_result_mock):
     app = MagicMock()
     app.tasks.func.apply.side_effect = ValueError
     worker = WorkerProcess(app, None, 2)
     worker.counter = 0
     channel = MagicMock()
     body = '{"task": "func", "args": [1], "kwargs": {"two": 2}}'
     msg = MagicMock(body=body, correlation_id="testid", reply_to="test")
     self.assertRaises(ValueError, worker._on_message, channel, msg)
     app.tasks.func.apply.assert_called_with([1], {"two": 2}, "testid")
     send_result_mock.assert_called_with(channel, "testid", "test", ANY)
     channel.basic_reject.assert_called_with(ANY, requeue=False)
     self.assertFalse(channel.basic_cancel.called)
예제 #2
0
 def test_on_message_task_fail(self, send_result_mock):
     app = MagicMock()
     app.tasks.func.apply.side_effect = ValueError
     worker = WorkerProcess(app, None, 2)
     worker.counter = 0
     channel = MagicMock()
     body = '{"task": "func", "args": [1], "kwargs": {"two": 2}}'
     msg = MagicMock(body=body, correlation_id='testid', reply_to='test')
     self.assertRaises(ValueError, worker._on_message, channel, msg)
     app.tasks.func.apply.assert_called_with([1], {'two': 2}, 'testid')
     send_result_mock.assert_called_with(channel, 'testid', 'test', ANY)
     channel.basic_reject.assert_called_with(ANY, requeue=False)
     self.assertFalse(channel.basic_cancel.called)
예제 #3
0
    def test_on_message_limit(self):
        app = MagicMock()
        worker = WorkerProcess(app, None, 1)
        worker.counter = 0
        channel = MagicMock(callbacks={1: None, 2: None})

        def clear_callbacks(consumer_tag):
            channel.callbacks = {}

        channel.basic_cancel.side_effect = clear_callbacks
        body = '{"task": "func", "args": [1], "kwargs": {"two": 2}}'
        msg = MagicMock(body=body, correlation_id="testid", reply_to=None)
        worker._on_message(channel, msg)
        app.tasks.func.apply.assert_called_with([1], {"two": 2}, "testid")
        channel.basic_ack.assert_called_with(ANY)
        channel.basic_cancel.assert_any_call(1)
        channel.basic_cancel.assert_any_call(2)
예제 #4
0
    def test_on_message_limit(self):
        app = MagicMock()
        worker = WorkerProcess(app, None, 1)
        worker.counter = 0
        channel = MagicMock(callbacks={1: None, 2: None})

        def clear_callbacks(consumer_tag):
            channel.callbacks = {}

        channel.basic_cancel.side_effect = clear_callbacks
        body = '{"task": "func", "args": [1], "kwargs": {"two": 2}}'
        msg = MagicMock(body=body, correlation_id='testid', reply_to=None)
        worker._on_message(channel, msg)
        app.tasks.func.apply.assert_called_with([1], {'two': 2}, 'testid')
        channel.basic_ack.assert_called_with(ANY)
        channel.basic_cancel.assert_any_call(1)
        channel.basic_cancel.assert_any_call(2)