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)
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), 7)
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)
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)
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)
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), 7) self.assertEqual(self.clock.calls[0], 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), 7) 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')
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), 4) self.assertEqual(self.clock.calls, [5.0 * 1, 5.0 * 2, 5.0 * 4, 5.0 * 8,]) self.assertEqual(len(self.logger.calls), 4) 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')
def test_with_stop_after_secs(self, _, stop_after_secs): max_delay_secs = 10 self.assertRaises(NotImplementedError, retry.with_exponential_backoff( num_retries=10000, initial_delay_secs=10.0, clock=self.clock, fuzz=False, max_delay_secs=max_delay_secs, stop_after_secs=stop_after_secs)( self.permanent_failure), 10, b=20) total_delay = sum(self.clock.calls) self.assertLessEqual(total_delay, stop_after_secs) self.assertGreaterEqual(total_delay, stop_after_secs - max_delay_secs)