Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(203)

Side by Side Diff: sync/engine/syncer_unittest.cc

Issue 11192071: sync: Merge apply updates and resolve conflicts (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Retry (base files were missing) Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sync/engine/syncer_proto_util_unittest.cc ('k') | sync/engine/update_applicator.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // 4 //
5 // Syncer unit tests. Unfortunately a lot of these tests 5 // Syncer unit tests. Unfortunately a lot of these tests
6 // are outdated and need to be reworked and updated. 6 // are outdated and need to be reworked and updated.
7 7
8 #include <algorithm> 8 #include <algorithm>
9 #include <limits> 9 #include <limits>
10 #include <list> 10 #include <list>
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 GetModelSafeRoutingInfo(&info); 179 GetModelSafeRoutingInfo(&info);
180 GetWorkers(&workers); 180 GetWorkers(&workers);
181 ModelTypeInvalidationMap invalidation_map = 181 ModelTypeInvalidationMap invalidation_map =
182 ModelSafeRoutingInfoToInvalidationMap(info, std::string()); 182 ModelSafeRoutingInfoToInvalidationMap(info, std::string());
183 return new SyncSession(context_.get(), this, 183 return new SyncSession(context_.get(), this,
184 sessions::SyncSourceInfo(sync_pb::GetUpdatesCallerInfo::UNKNOWN, 184 sessions::SyncSourceInfo(sync_pb::GetUpdatesCallerInfo::UNKNOWN,
185 invalidation_map), 185 invalidation_map),
186 info, workers); 186 info, workers);
187 } 187 }
188 188
189 bool SyncShareAsDelegate( 189 void SyncShareAsDelegate(
190 SyncSchedulerImpl::SyncSessionJob::SyncSessionJobPurpose purpose) { 190 SyncSchedulerImpl::SyncSessionJob::SyncSessionJobPurpose purpose) {
191 SyncerStep start; 191 SyncerStep start;
192 SyncerStep end; 192 SyncerStep end;
193 SyncSchedulerImpl::SetSyncerStepsForPurpose(purpose, &start, &end); 193 SyncSchedulerImpl::SetSyncerStepsForPurpose(purpose, &start, &end);
194 194
195 session_.reset(MakeSession()); 195 session_.reset(MakeSession());
196 syncer_->SyncShare(session_.get(), start, end); 196 syncer_->SyncShare(session_.get(), start, end);
197 return session_->HasMoreToSync();
198 } 197 }
199 198
200 bool SyncShareNudge() { 199 void SyncShareNudge() {
201 session_.reset(MakeSession()); 200 session_.reset(MakeSession());
202 return SyncShareAsDelegate(SyncSchedulerImpl::SyncSessionJob::NUDGE); 201 SyncShareAsDelegate(SyncSchedulerImpl::SyncSessionJob::NUDGE);
203 } 202 }
204 203
205 bool SyncShareConfigure() { 204 void SyncShareConfigure() {
206 session_.reset(MakeSession()); 205 session_.reset(MakeSession());
207 return SyncShareAsDelegate( 206 SyncShareAsDelegate(SyncSchedulerImpl::SyncSessionJob::CONFIGURATION);
208 SyncSchedulerImpl::SyncSessionJob::CONFIGURATION);
209 }
210
211 void LoopSyncShare() {
212 bool should_loop = false;
213 int loop_iterations = 0;
214 do {
215 ASSERT_LT(++loop_iterations, 100) << "infinite loop detected. please fix";
216 should_loop = SyncShareNudge();
217 } while (should_loop);
218 } 207 }
219 208
220 virtual void SetUp() { 209 virtual void SetUp() {
221 dir_maker_.SetUp(); 210 dir_maker_.SetUp();
222 mock_server_.reset(new MockConnectionManager(directory())); 211 mock_server_.reset(new MockConnectionManager(directory()));
223 EnableDatatype(BOOKMARKS); 212 EnableDatatype(BOOKMARKS);
224 EnableDatatype(NIGORI); 213 EnableDatatype(NIGORI);
225 EnableDatatype(PREFERENCES); 214 EnableDatatype(PREFERENCES);
226 EnableDatatype(NIGORI); 215 EnableDatatype(NIGORI);
227 worker_ = new FakeModelWorker(GROUP_PASSIVE); 216 worker_ = new FakeModelWorker(GROUP_PASSIVE);
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 case MOVED_FROM_ROOT: 396 case MOVED_FROM_ROOT:
408 entry.Put(SERVER_PARENT_ID, trans.root_id()); 397 entry.Put(SERVER_PARENT_ID, trans.root_id());
409 break; 398 break;
410 default: 399 default:
411 FAIL() << "Bad value in CommitOrderingTest list"; 400 FAIL() << "Bad value in CommitOrderingTest list";
412 } 401 }
413 } 402 }
414 test++; 403 test++;
415 } 404 }
416 } 405 }
417 LoopSyncShare(); 406 SyncShareNudge();
418 ASSERT_TRUE(expected_positions.size() == 407 ASSERT_TRUE(expected_positions.size() ==
419 mock_server_->committed_ids().size()); 408 mock_server_->committed_ids().size());
420 // If this test starts failing, be aware other sort orders could be valid. 409 // If this test starts failing, be aware other sort orders could be valid.
421 for (size_t i = 0; i < expected_positions.size(); ++i) { 410 for (size_t i = 0; i < expected_positions.size(); ++i) {
422 EXPECT_EQ(1u, expected_positions.count(i)); 411 EXPECT_EQ(1u, expected_positions.count(i));
423 EXPECT_TRUE(expected_positions[i] == mock_server_->committed_ids()[i]); 412 EXPECT_TRUE(expected_positions[i] == mock_server_->committed_ids()[i]);
424 } 413 }
425 } 414 }
426 415
427 void DoTruncationTest(const vector<int64>& unsynced_handle_view, 416 void DoTruncationTest(const vector<int64>& unsynced_handle_view,
(...skipping 1595 matching lines...) Expand 10 before | Expand all | Expand 10 after
2023 ASSERT_TRUE(A.good()); 2012 ASSERT_TRUE(A.good());
2024 A.Put(IS_UNSYNCED, true); 2013 A.Put(IS_UNSYNCED, true);
2025 A.Put(IS_UNAPPLIED_UPDATE, true); 2014 A.Put(IS_UNAPPLIED_UPDATE, true);
2026 A.Put(SERVER_VERSION, 20); 2015 A.Put(SERVER_VERSION, 20);
2027 2016
2028 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2)); 2017 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2));
2029 ASSERT_TRUE(B.good()); 2018 ASSERT_TRUE(B.good());
2030 B.Put(IS_UNAPPLIED_UPDATE, true); 2019 B.Put(IS_UNAPPLIED_UPDATE, true);
2031 B.Put(SERVER_VERSION, 20); 2020 B.Put(SERVER_VERSION, 20);
2032 } 2021 }
2033 LoopSyncShare(); 2022 SyncShareNudge();
2034 saw_syncer_event_ = false; 2023 saw_syncer_event_ = false;
2035 mock_server_->set_conflict_all_commits(false); 2024 mock_server_->set_conflict_all_commits(false);
2036 2025
2037 { 2026 {
2038 syncable::ReadTransaction trans(FROM_HERE, directory()); 2027 syncable::ReadTransaction trans(FROM_HERE, directory());
2039 2028
2040 Entry A(&trans, GET_BY_ID, ids_.FromNumber(1)); 2029 Entry A(&trans, GET_BY_ID, ids_.FromNumber(1));
2041 ASSERT_TRUE(A.good()); 2030 ASSERT_TRUE(A.good());
2042 EXPECT_TRUE(A.Get(IS_UNSYNCED) == false); 2031 EXPECT_TRUE(A.Get(IS_UNSYNCED) == false);
2043 EXPECT_TRUE(A.Get(IS_UNAPPLIED_UPDATE) == false); 2032 EXPECT_TRUE(A.Get(IS_UNAPPLIED_UPDATE) == false);
(...skipping 19 matching lines...) Expand all
2063 ASSERT_TRUE(A.good()); 2052 ASSERT_TRUE(A.good());
2064 A.Put(IS_UNSYNCED, true); 2053 A.Put(IS_UNSYNCED, true);
2065 A.Put(IS_UNAPPLIED_UPDATE, true); 2054 A.Put(IS_UNAPPLIED_UPDATE, true);
2066 A.Put(SERVER_VERSION, 20); 2055 A.Put(SERVER_VERSION, 20);
2067 2056
2068 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2)); 2057 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2));
2069 ASSERT_TRUE(B.good()); 2058 ASSERT_TRUE(B.good());
2070 B.Put(IS_UNAPPLIED_UPDATE, true); 2059 B.Put(IS_UNAPPLIED_UPDATE, true);
2071 B.Put(SERVER_VERSION, 20); 2060 B.Put(SERVER_VERSION, 20);
2072 } 2061 }
2073 LoopSyncShare(); 2062 SyncShareNudge();
2074 saw_syncer_event_ = false; 2063 saw_syncer_event_ = false;
2075 mock_server_->set_conflict_all_commits(false); 2064 mock_server_->set_conflict_all_commits(false);
2076 2065
2077 { 2066 {
2078 syncable::ReadTransaction trans(FROM_HERE, directory()); 2067 syncable::ReadTransaction trans(FROM_HERE, directory());
2079 2068
2080 Entry A(&trans, GET_BY_ID, ids_.FromNumber(1)); 2069 Entry A(&trans, GET_BY_ID, ids_.FromNumber(1));
2081 ASSERT_TRUE(A.good()); 2070 ASSERT_TRUE(A.good());
2082 EXPECT_TRUE(A.Get(IS_UNSYNCED) == false); 2071 EXPECT_TRUE(A.Get(IS_UNSYNCED) == false);
2083 EXPECT_TRUE(A.Get(IS_UNAPPLIED_UPDATE) == false); 2072 EXPECT_TRUE(A.Get(IS_UNAPPLIED_UPDATE) == false);
2084 EXPECT_TRUE(A.Get(SERVER_VERSION) == 20); 2073 EXPECT_TRUE(A.Get(SERVER_VERSION) == 20);
2085 2074
2086 Entry B(&trans, GET_BY_ID, ids_.FromNumber(2)); 2075 Entry B(&trans, GET_BY_ID, ids_.FromNumber(2));
2087 ASSERT_TRUE(B.good()); 2076 ASSERT_TRUE(B.good());
2088 EXPECT_TRUE(B.Get(IS_UNSYNCED) == false); 2077 EXPECT_TRUE(B.Get(IS_UNSYNCED) == false);
2089 EXPECT_TRUE(B.Get(IS_UNAPPLIED_UPDATE) == false); 2078 EXPECT_TRUE(B.Get(IS_UNAPPLIED_UPDATE) == false);
2090 EXPECT_TRUE(B.Get(SERVER_VERSION) == 20); 2079 EXPECT_TRUE(B.Get(SERVER_VERSION) == 20);
2091 } 2080 }
2092 } 2081 }
2093 2082
2094 TEST_F(SyncerTest, ReverseFolderOrderingTest) { 2083 TEST_F(SyncerTest, ReverseFolderOrderingTest) {
2095 mock_server_->AddUpdateDirectory(4, 3, "ggchild", 10, 10); 2084 mock_server_->AddUpdateDirectory(4, 3, "ggchild", 10, 10);
2096 mock_server_->AddUpdateDirectory(3, 2, "gchild", 10, 10); 2085 mock_server_->AddUpdateDirectory(3, 2, "gchild", 10, 10);
2097 mock_server_->AddUpdateDirectory(5, 4, "gggchild", 10, 10); 2086 mock_server_->AddUpdateDirectory(5, 4, "gggchild", 10, 10);
2098 mock_server_->AddUpdateDirectory(2, 1, "child", 10, 10); 2087 mock_server_->AddUpdateDirectory(2, 1, "child", 10, 10);
2099 mock_server_->AddUpdateDirectory(1, 0, "parent", 10, 10); 2088 mock_server_->AddUpdateDirectory(1, 0, "parent", 10, 10);
2100 LoopSyncShare(); 2089 SyncShareNudge();
2101 syncable::ReadTransaction trans(FROM_HERE, directory()); 2090 syncable::ReadTransaction trans(FROM_HERE, directory());
2102 2091
2103 Id child_id = GetOnlyEntryWithName( 2092 Id child_id = GetOnlyEntryWithName(
2104 &trans, ids_.FromNumber(4), "gggchild"); 2093 &trans, ids_.FromNumber(4), "gggchild");
2105 Entry child(&trans, GET_BY_ID, child_id); 2094 Entry child(&trans, GET_BY_ID, child_id);
2106 ASSERT_TRUE(child.good()); 2095 ASSERT_TRUE(child.good());
2107 } 2096 }
2108 2097
2109 class EntryCreatedInNewFolderTest : public SyncerTest { 2098 class EntryCreatedInNewFolderTest : public SyncerTest {
2110 public: 2099 public:
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
2211 parent.Put(syncable::BASE_VERSION, 5); 2200 parent.Put(syncable::BASE_VERSION, 5);
2212 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 2201 parent.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
2213 MutableEntry child(&wtrans, syncable::CREATE, parent_id_, "Pete.htm"); 2202 MutableEntry child(&wtrans, syncable::CREATE, parent_id_, "Pete.htm");
2214 ASSERT_TRUE(child.good()); 2203 ASSERT_TRUE(child.good());
2215 child.Put(syncable::ID, child_id_); 2204 child.Put(syncable::ID, child_id_);
2216 child.Put(syncable::BASE_VERSION, 10); 2205 child.Put(syncable::BASE_VERSION, 10);
2217 WriteTestDataToEntry(&wtrans, &child); 2206 WriteTestDataToEntry(&wtrans, &child);
2218 } 2207 }
2219 mock_server_->AddUpdateBookmark(child_id_, parent_id_, "Pete2.htm", 11, 10); 2208 mock_server_->AddUpdateBookmark(child_id_, parent_id_, "Pete2.htm", 11, 10);
2220 mock_server_->set_conflict_all_commits(true); 2209 mock_server_->set_conflict_all_commits(true);
2221 LoopSyncShare(); 2210 SyncShareNudge();
2222 syncable::Directory::ChildHandles children; 2211 syncable::Directory::ChildHandles children;
2223 { 2212 {
2224 syncable::ReadTransaction trans(FROM_HERE, directory()); 2213 syncable::ReadTransaction trans(FROM_HERE, directory());
2225 directory()->GetChildHandlesById(&trans, parent_id_, &children); 2214 directory()->GetChildHandlesById(&trans, parent_id_, &children);
2226 // We expect the conflict resolver to preserve the local entry. 2215 // We expect the conflict resolver to preserve the local entry.
2227 Entry child(&trans, syncable::GET_BY_ID, child_id_); 2216 Entry child(&trans, syncable::GET_BY_ID, child_id_);
2228 ASSERT_TRUE(child.good()); 2217 ASSERT_TRUE(child.good());
2229 EXPECT_TRUE(child.Get(syncable::IS_UNSYNCED)); 2218 EXPECT_TRUE(child.Get(syncable::IS_UNSYNCED));
2230 EXPECT_FALSE(child.Get(syncable::IS_UNAPPLIED_UPDATE)); 2219 EXPECT_FALSE(child.Get(syncable::IS_UNAPPLIED_UPDATE));
2231 EXPECT_TRUE(child.Get(SPECIFICS).has_bookmark()); 2220 EXPECT_TRUE(child.Get(SPECIFICS).has_bookmark());
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
2513 string nameutf8 = base::StringPrintf("%d", i); 2502 string nameutf8 = base::StringPrintf("%d", i);
2514 string name(nameutf8.begin(), nameutf8.end()); 2503 string name(nameutf8.begin(), nameutf8.end());
2515 MutableEntry e(&trans, CREATE, trans.root_id(), name); 2504 MutableEntry e(&trans, CREATE, trans.root_id(), name);
2516 e.Put(IS_UNSYNCED, true); 2505 e.Put(IS_UNSYNCED, true);
2517 e.Put(IS_DIR, true); 2506 e.Put(IS_DIR, true);
2518 e.Put(SPECIFICS, DefaultBookmarkSpecifics()); 2507 e.Put(SPECIFICS, DefaultBookmarkSpecifics());
2519 } 2508 }
2520 } 2509 }
2521 ASSERT_EQ(items_to_commit, directory()->unsynced_entity_count()); 2510 ASSERT_EQ(items_to_commit, directory()->unsynced_entity_count());
2522 2511
2523 EXPECT_FALSE(SyncShareNudge()); 2512 SyncShareNudge();
2524 EXPECT_EQ(num_batches, mock_server_->commit_messages().size()); 2513 EXPECT_EQ(num_batches, mock_server_->commit_messages().size());
2525 EXPECT_EQ(0, directory()->unsynced_entity_count()); 2514 EXPECT_EQ(0, directory()->unsynced_entity_count());
2526 } 2515 }
2527 2516
2528 // Test that a single failure to contact the server will cause us to exit the 2517 // Test that a single failure to contact the server will cause us to exit the
2529 // commit loop immediately. 2518 // commit loop immediately.
2530 TEST_F(SyncerTest, CommitManyItemsInOneGo_PostBufferFail) { 2519 TEST_F(SyncerTest, CommitManyItemsInOneGo_PostBufferFail) {
2531 uint32 num_batches = 3; 2520 uint32 num_batches = 3;
2532 uint32 items_to_commit = kDefaultMaxCommitBatchSize * num_batches; 2521 uint32 items_to_commit = kDefaultMaxCommitBatchSize * num_batches;
2533 { 2522 {
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after
3058 EXPECT_TRUE(child.good()); 3047 EXPECT_TRUE(child.good());
3059 EXPECT_TRUE(child.Get(IS_UNAPPLIED_UPDATE)); 3048 EXPECT_TRUE(child.Get(IS_UNAPPLIED_UPDATE));
3060 EXPECT_TRUE(child.Get(IS_DEL)); 3049 EXPECT_TRUE(child.Get(IS_DEL));
3061 EXPECT_FALSE(child.Get(IS_UNSYNCED)); 3050 EXPECT_FALSE(child.Get(IS_UNSYNCED));
3062 } 3051 }
3063 3052
3064 // And finally the folder. 3053 // And finally the folder.
3065 mock_server_->AddUpdateDirectory(folder_id, 3054 mock_server_->AddUpdateDirectory(folder_id,
3066 TestIdFactory::root(), "folder", 1, 1); 3055 TestIdFactory::root(), "folder", 1, 1);
3067 mock_server_->SetChangesRemaining(0); 3056 mock_server_->SetChangesRemaining(0);
3068 LoopSyncShare(); 3057 SyncShareNudge();
3069 LoopSyncShare(); 3058 SyncShareNudge();
3070 // Check that everything is as expected after the commit. 3059 // Check that everything is as expected after the commit.
3071 { 3060 {
3072 syncable::ReadTransaction trans(FROM_HERE, directory()); 3061 syncable::ReadTransaction trans(FROM_HERE, directory());
3073 Entry entry(&trans, GET_BY_ID, folder_id); 3062 Entry entry(&trans, GET_BY_ID, folder_id);
3074 ASSERT_TRUE(entry.good()); 3063 ASSERT_TRUE(entry.good());
3075 Entry child(&trans, GET_BY_ID, stuck_entry_id); 3064 Entry child(&trans, GET_BY_ID, stuck_entry_id);
3076 EXPECT_EQ(entry.Get(ID), child.Get(PARENT_ID)); 3065 EXPECT_EQ(entry.Get(ID), child.Get(PARENT_ID));
3077 EXPECT_EQ("stuck", child.Get(NON_UNIQUE_NAME)); 3066 EXPECT_EQ("stuck", child.Get(NON_UNIQUE_NAME));
3078 EXPECT_TRUE(child.good()); 3067 EXPECT_TRUE(child.good());
3079 } 3068 }
(...skipping 1645 matching lines...) Expand 10 before | Expand all | Expand 10 after
4725 4714
4726 TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) { 4715 TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) {
4727 Add(mid_id_); 4716 Add(mid_id_);
4728 Add(low_id_); 4717 Add(low_id_);
4729 Add(high_id_); 4718 Add(high_id_);
4730 SyncShareNudge(); 4719 SyncShareNudge();
4731 ExpectLocalOrderIsByServerId(); 4720 ExpectLocalOrderIsByServerId();
4732 } 4721 }
4733 4722
4734 } // namespace syncer 4723 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/engine/syncer_proto_util_unittest.cc ('k') | sync/engine/update_applicator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698