def test_backoff_exponential_base(self):
        retry = WritesRetry(total=5, backoff_factor=2, exponential_base=2)

        retry = retry.increment()
        self.assertEqual(retry.get_backoff_time(), 2)

        retry = retry.increment()
        self.assertEqual(retry.get_backoff_time(), 4)

        retry = retry.increment()
        self.assertEqual(retry.get_backoff_time(), 8)

        retry = retry.increment()
        self.assertEqual(retry.get_backoff_time(), 16)
Beispiel #2
0
    def test_copy(self):
        retry = WritesRetry(exponential_base=3, max_retry_delay=145, total=10)
        self.assertEqual(retry.max_retry_delay, 145)
        self.assertEqual(retry.exponential_base, 3)
        self.assertEqual(retry.total, 10)

        retry = retry.increment()
        self.assertEqual(retry.max_retry_delay, 145)
        self.assertEqual(retry.exponential_base, 3)
        self.assertEqual(retry.total, 9)

        retry = retry.increment()
        self.assertEqual(retry.max_retry_delay, 145)
        self.assertEqual(retry.exponential_base, 3)
        self.assertEqual(retry.total, 8)
    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])