diff options
author | zea@chromium.org <zea@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-10 23:57:57 +0000 |
---|---|---|
committer | zea@chromium.org <zea@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-10 23:57:57 +0000 |
commit | 866d04490b7479cc6d8553de9c1f5d15bf5bfa6b (patch) | |
tree | c692cdc2fe55ecad364fb8faa27ff4629f31b499 /sync/engine/directory_update_handler_unittest.cc | |
parent | 49fbef9e739a9d0ea1c4f1f83e0eec1aee57fb9b (diff) | |
download | chromium_src-866d04490b7479cc6d8553de9c1f5d15bf5bfa6b.zip chromium_src-866d04490b7479cc6d8553de9c1f5d15bf5bfa6b.tar.gz chromium_src-866d04490b7479cc6d8553de9c1f5d15bf5bfa6b.tar.bz2 |
[Sync] Add support for retrying a getupdates due to a context change
We detect a context conflict using the version value, and if detected force the
getupdates to retry.
BUG=360280
Review URL: https://codereview.chromium.org/232003005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@263134 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync/engine/directory_update_handler_unittest.cc')
-rw-r--r-- | sync/engine/directory_update_handler_unittest.cc | 91 |
1 files changed, 86 insertions, 5 deletions
diff --git a/sync/engine/directory_update_handler_unittest.cc b/sync/engine/directory_update_handler_unittest.cc index 6d1b35a..ec8cc35 100644 --- a/sync/engine/directory_update_handler_unittest.cc +++ b/sync/engine/directory_update_handler_unittest.cc @@ -195,14 +195,14 @@ TEST_F(DirectoryUpdateHandlerProcessUpdateTest, // Test the receipt of a non-bookmark item. TEST_F(DirectoryUpdateHandlerProcessUpdateTest, ReceiveNonBookmarkItem) { - DirectoryUpdateHandler handler(dir(), PREFERENCES, ui_worker()); + DirectoryUpdateHandler handler(dir(), AUTOFILL, ui_worker()); sync_pb::GetUpdatesResponse gu_response; sessions::StatusController status; std::string root = syncable::GetNullId().GetServerId(); syncable::Id server_id = syncable::Id::CreateFromServerId("xyz"); scoped_ptr<sync_pb::SyncEntity> e = - CreateUpdate(SyncableIdToProto(server_id), root, PREFERENCES); + CreateUpdate(SyncableIdToProto(server_id), root, AUTOFILL); e->set_server_defined_unique_tag("9PGRuKdX5sHyGMB17CvYTXuC43I="); // Add it to the applicable updates list. @@ -283,7 +283,9 @@ TEST_F(DirectoryUpdateHandlerProcessUpdateTest, GarbageCollectionByVersion) { updates.push_back(e2.get()); // Process and apply updates. - handler.ProcessGetUpdatesResponse(progress, context, updates, &status); + EXPECT_EQ( + SYNCER_OK, + handler.ProcessGetUpdatesResponse(progress, context, updates, &status)); handler.ApplyUpdates(&status); // Verify none is deleted because they are unapplied during GC. @@ -293,14 +295,93 @@ TEST_F(DirectoryUpdateHandlerProcessUpdateTest, GarbageCollectionByVersion) { // Process and apply again. Old entry is deleted but not root. progress.mutable_gc_directive()->set_version_watermark(kDefaultVersion + 20); - handler.ProcessGetUpdatesResponse( - progress, context, SyncEntityList(), &status); + EXPECT_EQ(SYNCER_OK, + handler.ProcessGetUpdatesResponse( + progress, context, SyncEntityList(), &status)); handler.ApplyUpdates(&status); EXPECT_TRUE(EntryExists(type_root->id_string())); EXPECT_FALSE(EntryExists(e1->id_string())); EXPECT_TRUE(EntryExists(e2->id_string())); } +TEST_F(DirectoryUpdateHandlerProcessUpdateTest, ContextVersion) { + DirectoryUpdateHandler handler(dir(), SYNCED_NOTIFICATIONS, ui_worker()); + sessions::StatusController status; + int field_number = GetSpecificsFieldNumberFromModelType(SYNCED_NOTIFICATIONS); + + sync_pb::DataTypeProgressMarker progress; + progress.set_data_type_id( + GetSpecificsFieldNumberFromModelType(SYNCED_NOTIFICATIONS)); + progress.set_token("token"); + + sync_pb::DataTypeContext old_context; + old_context.set_version(1); + old_context.set_context("data"); + old_context.set_data_type_id(field_number); + + scoped_ptr<sync_pb::SyncEntity> type_root = + CreateUpdate(SyncableIdToProto(syncable::Id::CreateFromServerId("root")), + syncable::GetNullId().GetServerId(), + SYNCED_NOTIFICATIONS); + type_root->set_server_defined_unique_tag( + ModelTypeToRootTag(SYNCED_NOTIFICATIONS)); + type_root->set_folder(true); + scoped_ptr<sync_pb::SyncEntity> e1 = + CreateUpdate(SyncableIdToProto(syncable::Id::CreateFromServerId("e1")), + type_root->id_string(), + SYNCED_NOTIFICATIONS); + + SyncEntityList updates; + updates.push_back(type_root.get()); + updates.push_back(e1.get()); + + // The first response should be processed fine. + EXPECT_EQ(SYNCER_OK, + handler.ProcessGetUpdatesResponse( + progress, old_context, updates, &status)); + handler.ApplyUpdates(&status); + + EXPECT_TRUE(EntryExists(type_root->id_string())); + EXPECT_TRUE(EntryExists(e1->id_string())); + + { + sync_pb::DataTypeContext dir_context; + syncable::ReadTransaction trans(FROM_HERE, dir()); + trans.directory()->GetDataTypeContext( + &trans, SYNCED_NOTIFICATIONS, &dir_context); + EXPECT_EQ(old_context.SerializeAsString(), dir_context.SerializeAsString()); + } + + sync_pb::DataTypeContext new_context; + new_context.set_version(0); + new_context.set_context("old"); + new_context.set_data_type_id(field_number); + + scoped_ptr<sync_pb::SyncEntity> e2 = + CreateUpdate(SyncableIdToProto(syncable::Id::CreateFromServerId("e2")), + type_root->id_string(), + SYNCED_NOTIFICATIONS); + updates.clear(); + updates.push_back(e2.get()); + + // The second response, with an old context version, should result in an + // error and the updates should be dropped. + EXPECT_EQ(DATATYPE_TRIGGERED_RETRY, + handler.ProcessGetUpdatesResponse( + progress, new_context, updates, &status)); + handler.ApplyUpdates(&status); + + EXPECT_FALSE(EntryExists(e2->id_string())); + + { + sync_pb::DataTypeContext dir_context; + syncable::ReadTransaction trans(FROM_HERE, dir()); + trans.directory()->GetDataTypeContext( + &trans, SYNCED_NOTIFICATIONS, &dir_context); + EXPECT_EQ(old_context.SerializeAsString(), dir_context.SerializeAsString()); + } +} + // A test harness for tests that focus on applying updates. // // Update application is performed when we want to take updates that were |