aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/core/platform/cloud/gcs_file_system_test.cc
diff options
context:
space:
mode:
authorGravatar Alexey Surkov <surkov@google.com>2017-03-16 13:32:38 -0800
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2017-03-16 14:50:23 -0700
commita8cd6ff8f1176ea3e7cfd15276051f98e7476500 (patch)
tree1eeb3244ec94f404c1742ef4ea6eae33647ec0b2 /tensorflow/core/platform/cloud/gcs_file_system_test.cc
parent791c3ebc0b80fe3879bc7c878938c504667a9e1d (diff)
Smarter retry logic for non-idempotent file operations such as RenameFile, DeleteFile or DeleteDir.
Change: 150369708
Diffstat (limited to 'tensorflow/core/platform/cloud/gcs_file_system_test.cc')
-rw-r--r--tensorflow/core/platform/cloud/gcs_file_system_test.cc47
1 files changed, 47 insertions, 0 deletions
diff --git a/tensorflow/core/platform/cloud/gcs_file_system_test.cc b/tensorflow/core/platform/cloud/gcs_file_system_test.cc
index 3d6b33f704..7fb70acf11 100644
--- a/tensorflow/core/platform/cloud/gcs_file_system_test.cc
+++ b/tensorflow/core/platform/cloud/gcs_file_system_test.cc
@@ -1113,6 +1113,53 @@ TEST(GcsFileSystemTest, RenameFile_Object) {
fs.RenameFile("gs://bucket/path/src.txt", "gs://bucket/path/dst.txt"));
}
+/// Tests the scenario when deletion returns a failure, but actually succeeds.
+TEST(GcsFileSystemTest, RenameFile_Object_DeletionRetried) {
+ std::vector<HttpRequest*> requests(
+ {// IsDirectory is checking whether there are children objects.
+ new FakeHttpRequest(
+ "Uri: https://www.googleapis.com/storage/v1/b/bucket/o?"
+ "fields=items%2Fname%2CnextPageToken&prefix=path%2Fsrc.txt%2F"
+ "&maxResults=1\n"
+ "Auth Token: fake_token\n",
+ "{}"),
+ // IsDirectory is checking if the path exists as an object.
+ new FakeHttpRequest(
+ "Uri: https://www.googleapis.com/storage/v1/b/bucket/o/"
+ "path%2Fsrc.txt?fields=size%2Cupdated\n"
+ "Auth Token: fake_token\n",
+ strings::StrCat("{\"size\": \"1010\","
+ "\"updated\": \"2016-04-29T23:15:24.896Z\"}")),
+ // Copying to the new location.
+ new FakeHttpRequest(
+ "Uri: https://www.googleapis.com/storage/v1/b/bucket/o/"
+ "path%2Fsrc.txt/rewriteTo/b/bucket/o/path%2Fdst.txt\n"
+ "Auth Token: fake_token\n"
+ "Post: yes\n",
+ "{\"done\": true}"),
+ // Deleting the original file - the deletion returns a failure.
+ new FakeHttpRequest(
+ "Uri: https://www.googleapis.com/storage/v1/b/bucket/o/"
+ "path%2Fsrc.txt\n"
+ "Auth Token: fake_token\n"
+ "Delete: yes\n",
+ "", errors::Unavailable("503"), 503),
+ // Deleting the original file again - the deletion returns NOT_FOUND.
+ new FakeHttpRequest(
+ "Uri: https://www.googleapis.com/storage/v1/b/bucket/o/"
+ "path%2Fsrc.txt\n"
+ "Auth Token: fake_token\n"
+ "Delete: yes\n",
+ "", errors::NotFound("404"), 404)});
+ GcsFileSystem fs(std::unique_ptr<AuthProvider>(new FakeAuthProvider),
+ std::unique_ptr<HttpRequest::Factory>(
+ new FakeHttpRequestFactory(&requests)),
+ 0 /* read ahead bytes */, 0 /* initial retry delay */);
+
+ TF_EXPECT_OK(
+ fs.RenameFile("gs://bucket/path/src.txt", "gs://bucket/path/dst.txt"));
+}
+
/// Tests the case when rewrite couldn't complete in one RPC.
TEST(GcsFileSystemTest, RenameFile_Object_Incomplete) {
std::vector<HttpRequest*> requests(