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)
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)
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)
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)