Skip to content

Commit 3072014

Browse files
authored
Merge pull request #2290 from dhermes/fix-2289
Adding retries for failed copy_blob() calls in system tests.
2 parents d42b020 + a1cd987 commit 3072014

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

system_tests/storage.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,21 @@
2929
from retry import RetryResult
3030

3131

32-
retry_429 = RetryErrors(exceptions.TooManyRequests)
3332
HTTP = httplib2.Http()
3433

3534

35+
def _bad_copy(bad_request):
36+
"""Predicate: pass only exceptions for a failed copyTo."""
37+
err_msg = bad_request.message
38+
return (err_msg.startswith('No file found in request. (POST') and
39+
'copyTo' in err_msg)
40+
41+
42+
retry_429 = RetryErrors(exceptions.TooManyRequests)
43+
retry_bad_copy = RetryErrors(exceptions.BadRequest,
44+
error_predicate=_bad_copy)
45+
46+
3647
class Config(object):
3748
"""Run-time configuration to be modified at set-up.
3849
@@ -188,7 +199,8 @@ def test_copy_existing_file(self):
188199
blob.upload_from_filename(filename)
189200
self.case_blobs_to_delete.append(blob)
190201

191-
new_blob = self.bucket.copy_blob(blob, self.bucket, 'CloudLogoCopy')
202+
new_blob = retry_bad_copy(self.bucket.copy_blob)(
203+
blob, self.bucket, 'CloudLogoCopy')
192204
self.case_blobs_to_delete.append(new_blob)
193205

194206
base_contents = blob.download_as_string()
@@ -214,7 +226,8 @@ def setUpClass(cls):
214226

215227
# Copy main blob onto remaining in FILENAMES.
216228
for filename in cls.FILENAMES[1:]:
217-
new_blob = cls.bucket.copy_blob(blob, cls.bucket, filename)
229+
new_blob = retry_bad_copy(cls.bucket.copy_blob)(
230+
blob, cls.bucket, filename)
218231
cls.suite_blobs_to_delete.append(new_blob)
219232

220233
@classmethod
@@ -275,7 +288,8 @@ def setUpClass(cls):
275288
blob.upload_from_filename(simple_path)
276289
cls.suite_blobs_to_delete = [blob]
277290
for filename in cls.FILENAMES[1:]:
278-
new_blob = cls.bucket.copy_blob(blob, cls.bucket, filename)
291+
new_blob = retry_bad_copy(cls.bucket.copy_blob)(
292+
blob, cls.bucket, filename)
279293
cls.suite_blobs_to_delete.append(new_blob)
280294

281295
@classmethod

0 commit comments

Comments
 (0)