Ejemplo n.º 1
0
    def test_tasks_update_due_at_with_backoff(self):
        """The task updates its due_at with a quadratic growing delay if
        retry_backoff is true.
        """
        base_due_at = datetime.datetime(2018, 11, 28, hour=20, tzinfo=timezone.utc)

        task = Task()
        task.due_at = base_due_at
        task.retry_delay = datetime.timedelta(seconds=10)
        task.retry_backoff = True
        task.function_name = "tests.fixtures.do_nothing"
        task.save()
        self.assertEqual(task.due_at, base_due_at)

        previous_due_at = task.due_at
        for i in range(1, 4):
            task.retries = i
            before = timezone.now()
            task.update_due_at_after_failure()
            after = timezone.now()
            delta = datetime.timedelta(seconds=10 * (2 ** (i - 1)))
            self.assertGreaterEqual(task.due_at, before + delta)
            self.assertLessEqual(task.due_at, after + delta)

            self.assertGreater(task.due_at, previous_due_at)
            previous_due_at = task.due_at
Ejemplo n.º 2
0
    def test_tasks_update_due_at_simple(self):
        """The task updates its due_at after an execution failure."""
        base_due_at = datetime.datetime(2018, 11, 28, hour=20, tzinfo=timezone.utc)

        task = Task()
        task.due_at = base_due_at
        task.retry_delay = datetime.timedelta(seconds=10)
        task.function_name = "tests.fixtures.do_nothing"
        task.save()
        self.assertEqual(task.due_at, base_due_at)

        previous_due_at = task.due_at
        for i in range(1, 4):
            task.retries = i
            before = timezone.now()
            task.update_due_at_after_failure()
            after = timezone.now()
            delta = datetime.timedelta(seconds=10)
            self.assertGreaterEqual(task.due_at, before + delta)
            self.assertLessEqual(task.due_at, after + delta)

            self.assertGreater(task.due_at, previous_due_at)
            previous_due_at = task.due_at
Ejemplo n.º 3
0
    def test_tasks_update_due_at_ignores_backoff_factor_if_backoff_false(self):
        """The task updates its due_at without taking into account its
        retry_backoff_factor if retry_backoff is False.
        """
        base_due_at = datetime.datetime(2018, 11, 28, hour=20, tzinfo=timezone.utc)

        task = Task()
        task.due_at = base_due_at
        task.retry_delay = datetime.timedelta(seconds=10)
        task.retry_backoff = False
        task.retry_backoff_factor = 4
        task.function_name = "tests.fixtures.do_nothing"
        task.save()
        self.assertEqual(task.due_at, base_due_at)

        for i in range(1, 4):
            task.retries = i
            before = timezone.now()
            task.update_due_at_after_failure()
            after = timezone.now()
            delta = datetime.timedelta(seconds=10)
            self.assertGreaterEqual(task.due_at, before + delta)
            self.assertLessEqual(task.due_at, after + delta)