Skip to content

Commit 74e3a7e

Browse files
committed
Adding retries for failed copy_blob() calls in system tests.
Fixes #2289.
1 parent 6b42be9 commit 74e3a7e

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

system_tests/storage.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,19 @@
3131
from retry import RetryResult
3232

3333

34-
retry_429 = RetryErrors(exceptions.TooManyRequests)
3534
HTTP = httplib2.Http()
36-
_helpers.PROJECT = TESTS_PROJECT
35+
36+
37+
def _bad_copy(bad_request):
38+
"""Predicate: pass only exceptions for a failed copyTo."""
39+
err_msg = bad_request.message
40+
return (err_msg.startswith('No file found in request. (POST') and
41+
'copyTo' in err_msg)
42+
43+
44+
retry_429 = RetryErrors(exceptions.TooManyRequests)
45+
retry_bad_copy = RetryErrors(exceptions.BadRequest,
46+
error_predicate=_bad_copy)
3747

3848

3949
class Config(object):
@@ -47,6 +57,7 @@ class Config(object):
4757

4858

4959
def setUpModule():
60+
_helpers.PROJECT = TESTS_PROJECT
5061
Config.CLIENT = storage.Client()
5162
bucket_name = 'new' + unique_resource_id()
5263
# In the **very** rare case the bucket name is reserved, this
@@ -191,7 +202,8 @@ def test_copy_existing_file(self):
191202
blob.upload_from_filename(filename)
192203
self.case_blobs_to_delete.append(blob)
193204

194-
new_blob = self.bucket.copy_blob(blob, self.bucket, 'CloudLogoCopy')
205+
new_blob = retry_bad_copy(self.bucket.copy_blob)(
206+
blob, self.bucket, 'CloudLogoCopy')
195207
self.case_blobs_to_delete.append(new_blob)
196208

197209
base_contents = blob.download_as_string()
@@ -217,7 +229,8 @@ def setUpClass(cls):
217229

218230
# Copy main blob onto remaining in FILENAMES.
219231
for filename in cls.FILENAMES[1:]:
220-
new_blob = cls.bucket.copy_blob(blob, cls.bucket, filename)
232+
new_blob = retry_bad_copy(cls.bucket.copy_blob)(
233+
blob, cls.bucket, filename)
221234
cls.suite_blobs_to_delete.append(new_blob)
222235

223236
@classmethod
@@ -278,7 +291,8 @@ def setUpClass(cls):
278291
blob.upload_from_filename(simple_path)
279292
cls.suite_blobs_to_delete = [blob]
280293
for filename in cls.FILENAMES[1:]:
281-
new_blob = cls.bucket.copy_blob(blob, cls.bucket, filename)
294+
new_blob = retry_bad_copy(cls.bucket.copy_blob)(
295+
blob, cls.bucket, filename)
282296
cls.suite_blobs_to_delete.append(new_blob)
283297

284298
@classmethod

0 commit comments

Comments
 (0)