Exemplo n.º 1
0
    def testBlacklistedTaskNoRetries(self):
        """Test that a blacklisted task raises an exception."""
        setup_env = self._create_patch(
            'kale.task.Task._setup_task_environment')
        pre_run = self._create_patch('kale.task.Task._pre_run')
        run_task = self._create_patch('kale.task.Task.run_task')
        clean_env = self._create_patch(
            'kale.task.Task._clean_task_environment')
        check_blacklist = self._create_patch('kale.task.Task._check_blacklist')
        raised_exc = exceptions.BlacklistedException()
        check_blacklist.side_effect = raised_exc

        mock_message = test_utils.new_mock_message(
            task_class=test_utils.MockTask)
        task_inst = mock_message.task_inst
        task_inst._start_time = 1
        task_args = [1, 'a']

        with self.assertRaises(exceptions.BlacklistedException):
            task_inst.run(*task_args)

        setup_env.assert_called_once_with()
        pre_run.assert_called_once_with(*task_args)
        self.assertFalse(run_task.called)
        clean_env.assert_called_once_with(task_id='mock_task',
                                          task_name='kale.test_utils.MockTask',
                                          exc=raised_exc)

        # Check that task
        permanent_failure = not task_inst.__class__.handle_failure(
            mock_message, raised_exc)
        self.assertTrue(permanent_failure)
Exemplo n.º 2
0
    def testBlacklistedTaskFails(self):
        """Test that a blacklisted task raises an exception."""
        setup_env = self._create_patch(
            'kale.task.Task._setup_task_environment')
        pre_run = self._create_patch('kale.task.Task._pre_run')
        run_task = self._create_patch('kale.task.Task.run_task')
        clean_env = self._create_patch(
            'kale.task.Task._clean_task_environment')
        check_blacklist = self._create_patch('kale.task.Task._check_blacklist')
        raised_exc = exceptions.BlacklistedException()
        check_blacklist.side_effect = raised_exc

        task_inst = test_utils.new_mock_task(task_class=test_utils.MockTask)
        task_inst._start_time = 1
        task_args = [1, 'a']

        with self.assertRaises(exceptions.BlacklistedException):
            task_inst.run(*task_args)

        setup_env.assert_called_once_with()
        pre_run.assert_called_once_with(*task_args)
        self.assertFalse(run_task.called)
        clean_env.assert_called_once_with(task_id='mock_task',
                                          task_name='kale.test_utils.MockTask',
                                          exc=raised_exc)
Exemplo n.º 3
0
    def testBlacklistedTaskFailsChildProcess(self):
        """Test that a blacklisted task raises an exception in the child process.."""
        check_blacklist = self._create_patch('kale.task.Task._check_blacklist')
        raised_exc = exceptions.BlacklistedException()
        check_blacklist.side_effect = raised_exc

        settings.RUN_TASK_AS_CHILD = True

        task_inst = test_utils.new_mock_task(task_class=test_utils.MockTask)
        task_inst._start_time = 1
        task_args = [1, 'a']

        with self.assertRaises(exceptions.BlacklistedException):
            task_inst.run(*task_args)
Exemplo n.º 4
0
    def testBlacklistedTaskNoRetriesChildProcess(self):
        """Test that a blacklisted task raises an exception in the child process.."""
        check_blacklist = self._create_patch('kale.task.Task._check_blacklist')
        raised_exc = exceptions.BlacklistedException()
        check_blacklist.side_effect = raised_exc

        settings.RUN_TASK_AS_CHILD = True

        mock_message = test_utils.new_mock_message(
            task_class=test_utils.MockTask)
        task_inst = mock_message.task_inst
        task_inst._start_time = 1
        task_args = [1, 'a']

        with self.assertRaises(exceptions.BlacklistedException):
            task_inst.run(*task_args)

        # Check that task
        permanent_failure = not task_inst.__class__.handle_failure(
            mock_message, raised_exc)
        self.assertTrue(permanent_failure)