-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Track retry mode and gzip feature ids #3481
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,10 @@ | |
from botocore.config import Config | ||
from botocore.exceptions import ClientError | ||
from tests import BaseSessionTest, ClientHTTPStubber, mock | ||
from tests.functional.test_useragent import ( | ||
get_captured_ua_strings, | ||
parse_registered_feature_ids, | ||
) | ||
|
||
RETRY_MODES = ('legacy', 'standard', 'adaptive') | ||
|
||
|
@@ -264,6 +268,20 @@ def test_can_clobber_max_attempts_on_session(self): | |
with self.assert_will_retry_n_times(client, 0): | ||
client.list_repositories() | ||
|
||
def test_user_agent_has_legacy_mode_feature_id(self): | ||
client = self.session.create_client('dynamodb', self.region) | ||
with ClientHTTPStubber(client) as http_stubber: | ||
# Add two failed responses followed by a success | ||
http_stubber.add_response(status=500, body=b'{}') | ||
http_stubber.add_response(status=500, body=b'{}') | ||
http_stubber.add_response(status=200, body=b'{}') | ||
client.list_tables() | ||
ua_strings = get_captured_ua_strings(http_stubber) | ||
# Confirm all requests register `'RETRY_MODE_LEGACY': 'D'` | ||
for ua_string in ua_strings: | ||
feature_list = parse_registered_feature_ids(ua_string) | ||
assert 'D' in feature_list | ||
|
||
|
||
class TestRetriesV2(BaseRetryTest): | ||
def create_client_with_retry_mode( | ||
|
@@ -349,3 +367,35 @@ def test_can_exhaust_default_retry_quota(self): | |
self.assertTrue( | ||
e.exception.response['ResponseMetadata'].get('RetryQuotaReached') | ||
) | ||
|
||
def test_user_agent_has_standard_mode_feature_id(self): | ||
client = self.create_client_with_retry_mode( | ||
'dynamodb', retry_mode='standard' | ||
) | ||
with ClientHTTPStubber(client) as http_stubber: | ||
# Add two failed responses followed by a success | ||
http_stubber.add_response(status=502, body=b'{}') | ||
http_stubber.add_response(status=502, body=b'{}') | ||
http_stubber.add_response(status=200, body=b'{}') | ||
client.list_tables() | ||
ua_strings = get_captured_ua_strings(http_stubber) | ||
# Confirm all requests register `'RETRY_MODE_STANDARD': 'E'` | ||
for ua_string in ua_strings: | ||
feature_list = parse_registered_feature_ids(ua_string) | ||
assert 'E' in feature_list | ||
|
||
def test_user_agent_has_adaptive_mode_feature_id(self): | ||
client = self.create_client_with_retry_mode( | ||
'dynamodb', retry_mode='adaptive' | ||
) | ||
with ClientHTTPStubber(client) as http_stubber: | ||
# Add two failed responses followed by a success | ||
http_stubber.add_response(status=502, body=b'{}') | ||
http_stubber.add_response(status=502, body=b'{}') | ||
http_stubber.add_response(status=200, body=b'{}') | ||
client.list_tables() | ||
ua_strings = get_captured_ua_strings(http_stubber) | ||
# Confirm all requests register `'RETRY_MODE_ADAPTIVE': 'F'` | ||
for ua_string in ua_strings: | ||
feature_list = parse_registered_feature_ids(ua_string) | ||
assert 'F' in feature_list | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit; this seems like something we could/should be reusing rather than rewriting the same test many times if it can be parameterized. When you find yourself copy pasting scaffolding, unless there's something truly unique about it, try to find opportunities to reuse. A simple way to do this is to either implement a standalone function, or a method on BaseRetryTest to help for this case. It could look something like: def _get_ua_strings_from_retries(self, client):
with ClientHTTPStubber(client) as http_stubber:
# Add two failed responses followed by a success
http_stubber.add_response(status=502, body=b'{}')
http_stubber.add_response(status=502, body=b'{}')
http_stubber.add_response(status=200, body=b'{}')
client.list_tables()
ua_strings = get_captured_ua_strings(http_stubber)
return [parse_registered_feature_ids(ua_string) for ua_string in ua_strings] and your test(s) would look something like: def test_user_agent_has_standard_mode_feature_id(self):
client = self.create_client_with_retry_mode(
'dynamodb', retry_mode='standard'
)
feature_lists = self._get_ua_strings_from_retries(client)
# Confirm all requests register `'RETRY_MODE_ADAPTIVE': 'E'`
assert all('E' in feature_list for feature_list in feature_lists)
def test_user_agent_has_adaptive_mode_feature_id(self):
client = self.create_client_with_retry_mode(
'dynamodb', retry_mode='adaptive'
)
feature_lists = self._get_ua_strings_from_retries(client)
# Confirm all requests register `'RETRY_MODE_ADAPTIVE': 'F'`
assert all('F' in feature_list for feature_list in feature_lists) You can also parametrize these as well with pytest if you're not using the base unittest parent class. That's a separate consideration though. I don't think this is blocking, but it's something to consider for development. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it, I didn't catch that repeated logic but will keep that in mind for future development. I added a reusable helper to simplify testing if we add new retry modes in the future. |
Uh oh!
There was an error while loading. Please reload this page.