def test_ssl_error(self): """ Test that we retry on ssl.SSLError. This is a case that was seen in the field. """ def raise_ssl_error(): self.num_calls += 1 if self.num_calls <= 5: raise ssl.SSLError('Test') aws_service.retry_boto(raise_ssl_error, initial_sleep_seconds=0.0)()
def test_no_regexp(self): """ Test that we raise the underlying exception when the error code regexp is not specified. """ function = aws_service.retry_boto(self._fail_for_n_calls) with self.assertRaises(EC2ResponseError): function(1)
def test_five_failures(self): """ Test that we handle failing 5 times and succeeding the 6th time. """ function = aws_service.retry_boto( self._fail_for_n_calls, r'InvalidInstanceID\.NotFound', initial_sleep_seconds=0.0 ) function(5)
def test_regexp_does_not_match(self): """ Test that we raise the underlying exception when the error code does not match. """ function = aws_service.retry_boto( self._fail_for_n_calls, r'InvalidVolumeID.\NotFound', initial_sleep_seconds=0.0 ) with self.assertRaises(EC2ResponseError): function(1)
def test_503(self): """ Test that we retry when AWS returns a 503 status. """ function = aws_service.retry_boto( self._fail_for_n_calls, initial_sleep_seconds=0.0) function(5, status=503)
def retry(self, function, error_code_regexp=None, timeout=None): return aws_service.retry_boto( function, error_code_regexp=error_code_regexp )