Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle case where S3 returns a 200 error response #298

Merged
merged 2 commits into from
Jun 2, 2014
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add more tests for s3 200 error responses
  • Loading branch information
jamesls committed Jun 2, 2014
commit 26f883cbd593eccca031dd20384941ccba741e2f
40 changes: 38 additions & 2 deletions tests/unit/test_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,9 @@ def test_retry_on_socket_errors(self):
self.assertEqual(self.total_calls, 3)


class TestResetStreamOnRetry(unittest.TestCase):
class TestS3ResetStreamOnRetry(unittest.TestCase):
def setUp(self):
super(TestResetStreamOnRetry, self).setUp()
super(TestS3ResetStreamOnRetry, self).setUp()
self.total_calls = 0
self.auth = Mock()
self.session = create_session(include_builtin_handlers=False)
Expand Down Expand Up @@ -393,6 +393,42 @@ def test_reset_stream_on_retry(self):
self.assertEqual(payload.literal_value.total_resets, 2)


class TestS3Retry200SpecialCases(unittest.TestCase):
def setUp(self):
super(TestS3Retry200SpecialCases, self).setUp()
self.total_calls = 0
self.auth = Mock()
self.session = create_session(include_builtin_handlers=True)
self.service = Mock()
self.service.endpoint_prefix = 's3'
self.service.session = self.session
self.endpoint = RestEndpoint(
self.service, 'us-east-1', 'https://s3.amazonaws.com/',
auth=self.auth)
self.http_session = Mock()
self.endpoint.http_session = self.http_session
self.get_response_patch = patch('botocore.response.get_response')
self.get_response = self.get_response_patch.start()
self.retried_on_exception = None

def tearDown(self):
self.get_response_patch.stop()

def test_retry_special_case_s3_200_response(self):
# Test for:
# http://docs.aws.amazon.com/AmazonS3/latest/API/RESTObjectCOPY.html
op = Mock()
op.name = 'CopyObject'
op.http = {'uri': '', 'method': 'PUT'}
http_response = Mock()
http_response.status_code = 200
parsed = {'Errors': [{'Code': 'InternalError', 'Message': 'foo'}]}
self.get_response.return_value = (http_response, parsed)
self.endpoint.make_request(op, {'headers': {}, 'payload': None})
# The response code should have been switched to 500.
self.assertEqual(http_response.status_code, 500)


class TestRestEndpoint(unittest.TestCase):

def test_encode_uri_params_unicode(self):
Expand Down
35 changes: 35 additions & 0 deletions tests/unit/test_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,5 +126,40 @@ def test_200_response_with_no_error_left_untouched(self):
self.assertEqual(http_response.status_code, 200)


class TestRetryHandlerOrder(BaseSessionTest):
def get_handler_names(self, responses):
names = []
for response in responses:
handler = response[0]
if hasattr(handler, '__name__'):
names.append(handler.__name__)
elif hasattr(handler, '__class__'):
names.append(handler.__class__.__name__)
else:
names.append(str(handler))
return names

def test_s3_special_case_is_before_other_retry(self):
service = self.session.get_service('s3')
operation = service.get_operation('CopyObject')
responses = self.session.emit(
'needs-retry.s3.CopyObject',
response=(mock.Mock(), mock.Mock()), endpoint=mock.Mock(), operation=operation,
attempts=1, caught_exception=None)
# This is implementation specific, but we're trying to verify that
# the check_for_200_error is before any of the retry logic in
# botocore.retryhandlers.
# Technically, as long as the relative order is preserved, we don't
# care about the absolute order.
names = self.get_handler_names(responses)
self.assertIn('check_for_200_error', names)
self.assertIn('RetryHandler', names)
s3_200_handler = names.index('check_for_200_error')
general_retry_handler = names.index('RetryHandler')
self.assertTrue(s3_200_handler < general_retry_handler,
"S3 200 error handler was suppose to be before "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grammar: supposed

"the general retry handler, but it was not.")


if __name__ == '__main__':
unittest.main()