Ejemplo n.º 1
0
    def test_backoff_increment(self):
        retry = WritesRetry(total=5, retry_interval=4).increment()

        self.assertEqual(retry.total, 4)
        self.assertEqual(retry.is_exhausted(), False)

        backoff_time = retry.get_backoff_time()
        self.assertGreater(backoff_time, 4)
        self.assertLessEqual(backoff_time, 8)
    def test_backoff_jitter(self):
        retry = WritesRetry(total=5, backoff_factor=4,
                            jitter_interval=2).increment()

        self.assertEqual(retry.total, 4)
        self.assertEqual(retry.is_exhausted(), False)

        backoff_time = retry.get_backoff_time()
        self.assertGreater(backoff_time, 4)
        self.assertLessEqual(backoff_time, 6)
    def test_backoff(self):
        retry = WritesRetry(total=5, backoff_factor=1, max_retry_delay=550)
        self.assertEqual(retry.total, 5)
        self.assertEqual(retry.is_exhausted(), False)
        self.assertEqual(retry.get_backoff_time(), 0)

        retry = retry.increment()
        self.assertEqual(retry.total, 4)
        self.assertEqual(retry.is_exhausted(), False)
        self.assertEqual(retry.get_backoff_time(), 1)

        retry = retry.increment()
        self.assertEqual(retry.total, 3)
        self.assertEqual(retry.is_exhausted(), False)
        self.assertEqual(retry.get_backoff_time(), 5)

        retry = retry.increment()
        self.assertEqual(retry.total, 2)
        self.assertEqual(retry.is_exhausted(), False)
        self.assertEqual(retry.get_backoff_time(), 25)

        retry = retry.increment()
        self.assertEqual(retry.total, 1)
        self.assertEqual(retry.is_exhausted(), False)
        self.assertEqual(retry.get_backoff_time(), 125)

        retry = retry.increment()
        self.assertEqual(retry.total, 0)
        self.assertEqual(retry.is_exhausted(), False)
        self.assertEqual(retry.get_backoff_time(), 550)

        with self.assertRaises(MaxRetryError) as cm:
            retry.increment()
        exception = cm.exception

        self.assertEqual("too many error responses", exception.reason.args[0])