-
Notifications
You must be signed in to change notification settings - Fork 167
feat: add preconditions and retry configuration to blob.create_resumable_upload_session #484
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 all 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 |
|---|---|---|
|
|
@@ -25,6 +25,7 @@ | |
| import pytest | ||
| import six | ||
| from six.moves import http_client | ||
| from six.moves.urllib.parse import urlencode | ||
|
|
||
| from google.cloud.storage.retry import DEFAULT_RETRY | ||
| from google.cloud.storage.retry import DEFAULT_RETRY_IF_ETAG_IN_JSON | ||
|
|
@@ -2041,8 +2042,6 @@ def _do_multipart_success( | |
| mtls=False, | ||
| retry=None, | ||
| ): | ||
| from six.moves.urllib.parse import urlencode | ||
|
|
||
| bucket = _Bucket(name="w00t", user_project=user_project) | ||
| blob = self._make_one(u"blob-name", bucket=bucket, kms_key_name=kms_key_name) | ||
| self.assertIsNone(blob.chunk_size) | ||
|
|
@@ -2286,7 +2285,6 @@ def _initiate_resumable_helper( | |
| mtls=False, | ||
| retry=None, | ||
| ): | ||
| from six.moves.urllib.parse import urlencode | ||
| from google.resumable_media.requests import ResumableUpload | ||
| from google.cloud.storage.blob import _DEFAULT_CHUNKSIZE | ||
|
|
||
|
|
@@ -3248,7 +3246,15 @@ def test_upload_from_string_w_text_w_num_retries(self): | |
| self._upload_from_string_helper(data, num_retries=2) | ||
|
|
||
| def _create_resumable_upload_session_helper( | ||
| self, origin=None, side_effect=None, timeout=None | ||
| self, | ||
| origin=None, | ||
| side_effect=None, | ||
| timeout=None, | ||
| if_generation_match=None, | ||
| if_generation_not_match=None, | ||
| if_metageneration_match=None, | ||
| if_metageneration_not_match=None, | ||
| retry=None, | ||
| ): | ||
| bucket = _Bucket(name="alex-trebek") | ||
| blob = self._make_one("blob-name", bucket=bucket) | ||
|
|
@@ -3280,6 +3286,11 @@ def _create_resumable_upload_session_helper( | |
| size=size, | ||
| origin=origin, | ||
| client=client, | ||
| if_generation_match=if_generation_match, | ||
| if_generation_not_match=if_generation_not_match, | ||
| if_metageneration_match=if_metageneration_match, | ||
| if_metageneration_not_match=if_metageneration_not_match, | ||
| retry=retry, | ||
| **timeout_kwarg | ||
| ) | ||
|
|
||
|
|
@@ -3289,10 +3300,23 @@ def _create_resumable_upload_session_helper( | |
|
|
||
| # Check the mocks. | ||
| upload_url = ( | ||
| "https://storage.googleapis.com/upload/storage/v1" | ||
| + bucket.path | ||
| + "/o?uploadType=resumable" | ||
| "https://storage.googleapis.com/upload/storage/v1" + bucket.path + "/o" | ||
| ) | ||
|
|
||
| qs_params = [("uploadType", "resumable")] | ||
| if if_generation_match is not None: | ||
| qs_params.append(("ifGenerationMatch", if_generation_match)) | ||
|
|
||
| if if_generation_not_match is not None: | ||
| qs_params.append(("ifGenerationNotMatch", if_generation_not_match)) | ||
|
|
||
| if if_metageneration_match is not None: | ||
| qs_params.append(("ifMetagenerationMatch", if_metageneration_match)) | ||
|
|
||
| if if_metageneration_not_match is not None: | ||
| qs_params.append(("ifMetaGenerationNotMatch", if_metageneration_not_match)) | ||
|
|
||
| upload_url += "?" + urlencode(qs_params) | ||
| payload = b'{"name": "blob-name"}' | ||
| expected_headers = { | ||
| "content-type": "application/json; charset=UTF-8", | ||
|
|
@@ -3318,6 +3342,26 @@ def test_create_resumable_upload_session_with_custom_timeout(self): | |
| def test_create_resumable_upload_session_with_origin(self): | ||
| self._create_resumable_upload_session_helper(origin="http://google.com") | ||
|
|
||
| def test_create_resumable_upload_session_with_generation_match(self): | ||
| self._create_resumable_upload_session_helper( | ||
| if_generation_match=123456, if_metageneration_match=2 | ||
| ) | ||
|
|
||
| def test_create_resumable_upload_session_with_generation_not_match(self): | ||
| self._create_resumable_upload_session_helper( | ||
| if_generation_not_match=0, if_metageneration_not_match=3 | ||
| ) | ||
|
|
||
| def test_create_resumable_upload_session_with_conditional_retry_success(self): | ||
| self._create_resumable_upload_session_helper( | ||
| retry=DEFAULT_RETRY_IF_GENERATION_SPECIFIED, if_generation_match=123456 | ||
| ) | ||
|
|
||
| def test_create_resumable_upload_session_with_conditional_retry_failure(self): | ||
| self._create_resumable_upload_session_helper( | ||
| retry=DEFAULT_RETRY_IF_GENERATION_SPECIFIED | ||
| ) | ||
|
Contributor
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. How does this test verify that retries don't happen?
Contributor
Author
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. @tritone, I've tested the retry behaviors against the emulator that things are working as intended. The unit test asserts if the mock call was made with the corresponding url and query params.
Contributor
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. Sounds good! |
||
|
|
||
| def test_create_resumable_upload_session_with_failure(self): | ||
| from google.resumable_media import InvalidResponse | ||
| from google.cloud import exceptions | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.