Exemple #1
0
    def test_with_delay_default(self):
        callable = DummyCallableRaises(ValueError("test"))

        with self.assertRaises(ValueError):
            with_delay(delay=constant(RETRY_WAIT_TIME))(callable)()

        self.assertEqual(callable.count, 1)
Exemple #2
0
    def test_with_delay_default(self):
        callable = DummyCallableRaises(ValueError("test"))

        with self.assertRaises(ValueError):
            with_delay(delay=constant(RETRY_WAIT_TIME))(callable)()

        self.assertEquals(callable.count, 1)
Exemple #3
0
    def test_with_delay_wrong_exception(self):
        callable = DummyCallableRaises(ValueError("test"))
        with self.assertRaises(ValueError):
            with_delay(nb_times=3,
                       delay=constant(RETRY_WAIT_TIME),
                       on_exceptions=[KeyError])(callable)()

        # 1 == no retry
        self.assertEqual(1, callable.count)
Exemple #4
0
    def test_with_delay_wrong_exception(self):
        callable = DummyCallableRaises(ValueError('test'))
        with self.assertRaises(ValueError):
            with_delay(nb_times=3,
                       delay=constant(RETRY_WAIT_TIME),
                       on_exceptions=[KeyError])(callable)()

        # 1 == no retry
        self.assertEqual(1, callable.count)
Exemple #5
0
    def test_with_delay_except(self):
        callable = DummyCallableRaises(ValueError('test'))
        with self.assertRaises(ValueError):
            with_delay(nb_times=3,
                       delay=constant(RETRY_WAIT_TIME),
                       except_on=Exception,
                       on_exceptions=[ValueError])(callable)()

        # 1 == no retry
        self.assertEquals(1, callable.count)
Exemple #6
0
    def test_with_delay(self):
        callable = DummyCallableRaises(ValueError("test"))
        max_count = 2

        t0 = time()
        with self.assertRaises(ValueError):
            with_delay(nb_times=max_count, delay=constant(RETRY_WAIT_TIME))(callable)()

        self.assertEquals(callable.count, max_count)

        total_time = time() - t0
        self.assertTrue(abs(total_time - max_count * RETRY_WAIT_TIME) <= error_epsilon * max_count)
Exemple #7
0
    def test_with_delay(self):
        callable = DummyCallableRaises(ValueError('test'))
        max_count = 2

        t0 = time()
        with self.assertRaises(ValueError):
            with_delay(nb_times=max_count, delay=constant(RETRY_WAIT_TIME))(callable)()

        self.assertEqual(callable.count, max_count)

        total_time = time() - t0
        self.assertTrue(abs(total_time - max_count * RETRY_WAIT_TIME) <= error_epsilon * max_count)
Exemple #8
0
    def test_with_delay_multiple_exceptions(self):
        callable = DummyCallableRaises(ValueError("test"))
        max_count = 3
        func = with_delay(nb_times=max_count, delay=constant(RETRY_WAIT_TIME), on_exceptions=[KeyError, ValueError])(
            callable
        )

        t0 = time()
        with self.assertRaises(ValueError):
            func()

        self.assertEquals(callable.count, max_count)
        total_time = time() - t0
        self.assertTrue(abs(total_time - max_count * RETRY_WAIT_TIME) <= error_epsilon * max_count)
Exemple #9
0
    def test_with_delay_multiple_exceptions(self):
        callable = DummyCallableRaises(ValueError('test'))
        max_count = 3
        func = with_delay(nb_times=max_count,
                          delay=constant(RETRY_WAIT_TIME),
                          on_exceptions=[KeyError, ValueError])(callable)

        t0 = time()
        with self.assertRaises(ValueError):
            func()

        self.assertEqual(callable.count, max_count)
        total_time = time() - t0
        self.assertTrue(abs(total_time - max_count * RETRY_WAIT_TIME) <= error_epsilon * max_count)