def test_with_default_number_of_retries(self):
     self.assertRaises(NotImplementedError,
                       retry.with_exponential_backoff(clock=self.clock)(
                           self.permanent_failure),
                       10,
                       b=20)
     self.assertEqual(len(self.clock.calls), 16)
 def test_with_http_error_that_should_be_retried(self):
     self.assertRaises(
         HttpError,
         retry.with_exponential_backoff(clock=self.clock,
                                        num_retries=10)(self.http_error),
         500)
     self.assertEqual(len(self.clock.calls), 10)
Esempio n. 3
0
 def test_with_http_error_that_should_be_retried(self):
   self.assertRaises(HttpError,
                     retry.with_exponential_backoff(
                         clock=self.clock, num_retries=10)(
                             self.http_error),
                     500)
   self.assertEqual(len(self.clock.calls), 10)
Esempio n. 4
0
 def test_with_explicit_number_of_retries(self):
   self.assertRaises(NotImplementedError,
                     retry.with_exponential_backoff(
                         clock=self.clock, num_retries=10)(
                             self.permanent_failure),
                     10, b=20)
   self.assertEqual(len(self.clock.calls), 10)
 def test_with_http_error_that_should_not_be_retried(self):
     self.assertRaises(
         HttpError,
         retry.with_exponential_backoff(clock=self.clock,
                                        num_retries=10)(self.http_error),
         404)
     # Make sure just one call was made.
     self.assertEqual(len(self.clock.calls), 0)
Esempio n. 6
0
 def test_with_http_error_that_should_not_be_retried(self):
   self.assertRaises(HttpError,
                     retry.with_exponential_backoff(
                         clock=self.clock, num_retries=10)(
                             self.http_error),
                     404)
   # Make sure just one call was made.
   self.assertEqual(len(self.clock.calls), 0)
Esempio n. 7
0
 def test_with_explicit_initial_delay(self):
   self.assertRaises(NotImplementedError,
                     retry.with_exponential_backoff(
                         initial_delay_secs=10.0, clock=self.clock,
                         fuzz=False)(
                             self.permanent_failure),
                     10, b=20)
   self.assertEqual(len(self.clock.calls), 16)
   self.assertEqual(self.clock.calls[0], 10.0)
 def test_with_explicit_initial_delay(self):
     self.assertRaises(NotImplementedError,
                       retry.with_exponential_backoff(
                           initial_delay_secs=10.0,
                           clock=self.clock,
                           fuzz=False)(self.permanent_failure),
                       10,
                       b=20)
     self.assertEqual(len(self.clock.calls), 16)
     self.assertEqual(self.clock.calls[0], 10.0)
Esempio n. 9
0
 def test_log_calls_for_permanent_failure(self):
   self.assertRaises(NotImplementedError,
                     retry.with_exponential_backoff(
                         clock=self.clock, logger=self.logger.log)(
                             self.permanent_failure),
                     10, b=20)
   self.assertEqual(len(self.logger.calls), 16)
   for message, func_name, exn_name  in self.logger.calls:
     self.assertTrue(message.startswith('Retry with exponential backoff:'))
     self.assertEqual(exn_name, 'NotImplementedError\n')
     self.assertEqual(func_name, 'permanent_failure')
Esempio n. 10
0
 def test_log_calls_for_permanent_failure(self):
     self.assertRaises(NotImplementedError,
                       retry.with_exponential_backoff(
                           clock=self.clock,
                           logger=self.logger.log)(self.permanent_failure),
                       10,
                       b=20)
     self.assertEqual(len(self.logger.calls), 16)
     for message, func_name, exn_name in self.logger.calls:
         self.assertTrue(
             message.startswith('Retry with exponential backoff:'))
         self.assertEqual(exn_name, 'NotImplementedError\n')
         self.assertEqual(func_name, 'permanent_failure')
Esempio n. 11
0
 def test_log_calls_for_transient_failure(self):
   result = retry.with_exponential_backoff(
       clock=self.clock, logger=self.logger.log, fuzz=False)(
           self.transient_failure)(10, b=20)
   self.assertEqual(result, 30)
   self.assertEqual(len(self.clock.calls), 8)
   self.assertEqual(self.clock.calls,
                    [5.0 * 1, 5.0 * 2, 5.0 * 4, 5.0 * 8,
                     5.0 * 16, 5.0 * 32, 5.0 * 64, 5.0 * 128])
   self.assertEqual(len(self.logger.calls), 8)
   for message, func_name, exn_name  in self.logger.calls:
     self.assertTrue(message.startswith('Retry with exponential backoff:'))
     self.assertEqual(exn_name, 'NotImplementedError\n')
     self.assertEqual(func_name, 'transient_failure')
Esempio n. 12
0
 def test_log_calls_for_transient_failure(self):
     result = retry.with_exponential_backoff(
         clock=self.clock, logger=self.logger.log,
         fuzz=False)(self.transient_failure)(10, b=20)
     self.assertEqual(result, 30)
     self.assertEqual(len(self.clock.calls), 8)
     self.assertEqual(self.clock.calls, [
         5.0 * 1, 5.0 * 2, 5.0 * 4, 5.0 * 8, 5.0 * 16, 5.0 * 32, 5.0 * 64,
         5.0 * 128
     ])
     self.assertEqual(len(self.logger.calls), 8)
     for message, func_name, exn_name in self.logger.calls:
         self.assertTrue(
             message.startswith('Retry with exponential backoff:'))
         self.assertEqual(exn_name, 'NotImplementedError\n')
         self.assertEqual(func_name, 'transient_failure')