def test_not_retriable_is_not_retried(self): class MyTask(manage.Task): def _run_once(self): raise Exception('I always fail.') with self.assertRaisesRegexp(Exception, 'I always fail.'): manage.Command().real_run_cmd(MyTask(None, []))
def test_retriable_is_retried(self): class MyTask(manage.Task): def __init__(self): super(MyTask, self).__init__(None, []) self.try_count = 0 def _run_once(self): self.try_count += 1 if self.try_count == 1: raise Exception('I always fail once.') with self.assertRaisesRegexp(Exception, 'I always fail once.'): manage.Command().real_run_cmd(MyTask()) task = MyTask() task.max_try_count = 3 manage.Command().real_run_cmd(task) self.assertEquals(2, task.try_count)
def test_max_try_count_is_respected(self): class MyTask(manage.Task): def __init__(self): super(MyTask, self).__init__(None, []) self.try_count = 0 def _run_once(self): self.try_count += 1 raise Exception('I always fail even with retry.') with self.assertRaisesRegexp(Exception, 'I always fail even with retry.'): manage.Command().real_run_cmd(MyTask()) task = MyTask() task.max_try_count = 3 with self.assertRaisesRegexp(Exception, 'I always fail even with retry.'): manage.Command().real_run_cmd(task) self.assertEquals(3, task.try_count)
def _run(self, args): return manage.Command().real_run_cmd(manage.Task(None, args))