Skip to content

Commit fe2b6db

Browse files
committed
Adding a retry for storage list_blobs().
The storage API is not guaranteed to be strongly consistent, so we retry to allow for eventual consistency.
1 parent e407bfb commit fe2b6db

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

system_tests/storage.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -305,13 +305,24 @@ def test_first_level(self):
305305
self.assertEqual(iterator.prefixes, set(['parent/child/']))
306306

307307
def test_second_level(self):
308-
iterator = self.bucket.list_blobs(delimiter='/',
309-
prefix='parent/child/')
310-
response = iterator.get_next_page_response()
311-
blobs = list(iterator.get_items_from_response(response))
312-
self.assertEqual([blob.name for blob in blobs],
313-
['parent/child/file21.txt',
314-
'parent/child/file22.txt'])
308+
expected_names = [
309+
'parent/child/file21.txt',
310+
'parent/child/file22.txt',
311+
]
312+
313+
def _all_in_list(pair):
314+
_, blobs = pair
315+
return [blob.name for blob in blobs] == expected_names
316+
317+
def _all_blobs():
318+
iterator = self.bucket.list_blobs(delimiter='/',
319+
prefix='parent/child/')
320+
response = iterator.get_next_page_response()
321+
blobs = list(iterator.get_items_from_response(response))
322+
return iterator, blobs
323+
324+
retry = RetryResult(_all_in_list)
325+
iterator, _ = retry(_all_blobs)()
315326
self.assertEqual(iterator.page_number, 1)
316327
self.assertTrue(iterator.next_page_token is None)
317328
self.assertEqual(iterator.prefixes,

0 commit comments

Comments
 (0)