forked from googledatalab/datalab
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Storage object deletion waits for consistency. (googledatalab#354)
* Storage object deletion waits for consistency. Fixes googledatalab#344. GCS object deletions are eventually consistent, in that deleting an object in a globally-available bucket may result in the object still appearing when listing objects in the bucket: https://cloud.google.com/storage/docs/consistency#eventually_consistent_operations This is a detail, but can lead to confusion for users: someone following the examples in the tutorial notebooks may see rare-but-regular failures about an object they just deleted continuing to exist. (We've seen this running the notebooks as automated tests.) This PR teaches an object to poll the bucket until it no longer appears. This is controllable by `wait_for_deletion`, and defaults to **on**. I've added two tests: first is a mock-based unit test, which works; the second is intended as a first step towards integration tests. In this case, we assume that the user running the test has ambient credentials that `google.datalab` will discover.
- Loading branch information
1 parent
f1522f7
commit 3c7e44d
Showing
4 changed files
with
98 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
"""Integration tests for google.datalab.storage.""" | ||
|
||
from __future__ import absolute_import | ||
from __future__ import division | ||
from __future__ import print_function | ||
|
||
import logging | ||
import random | ||
import string | ||
import unittest | ||
|
||
import google.datalab | ||
from google.datalab import storage | ||
|
||
|
||
class StorageTest(unittest.TestCase): | ||
|
||
def setUp(self): | ||
self._context = google.datalab.Context.default() | ||
logging.info('Using project: %s', self._context.project_id) | ||
|
||
suffix = ''.join(random.choice(string.lowercase) for _ in range(8)) | ||
self._test_bucket_name = '{}-{}'.format(self._context.project_id, suffix) | ||
logging.info('test bucket: %s', self._test_bucket_name) | ||
|
||
def test_object_deletion_consistency(self): | ||
b = storage.Bucket(self._test_bucket_name, context=self._context) | ||
b.create() | ||
o = b.object('sample') | ||
o.write_stream('contents', 'text/plain') | ||
o.delete() | ||
b.delete() | ||
|
||
|
||
if __name__ == '__main__': | ||
logging.basicConfig(level=logging.INFO) | ||
unittest.main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters