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

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

Issue 14963002: sync: Report GetUpdate triggers to the server (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review response: lots of renames Created 7 years, 7 months 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
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 case SyncEngineEvent::SYNC_CYCLE_BEGIN: // Fall through. 164 case SyncEngineEvent::SYNC_CYCLE_BEGIN: // Fall through.
165 case SyncEngineEvent::STATUS_CHANGED: 165 case SyncEngineEvent::STATUS_CHANGED:
166 case SyncEngineEvent::SYNC_CYCLE_ENDED: 166 case SyncEngineEvent::SYNC_CYCLE_ENDED:
167 return; 167 return;
168 default: 168 default:
169 CHECK(false) << "Handling unknown error type in unit tests!!"; 169 CHECK(false) << "Handling unknown error type in unit tests!!";
170 } 170 }
171 saw_syncer_event_ = true; 171 saw_syncer_event_ = true;
172 } 172 }
173 173
174 SyncSession* MakeSession() { 174 void SyncShareNudge() {
175 ModelSafeRoutingInfo info; 175 ModelSafeRoutingInfo info;
176 GetModelSafeRoutingInfo(&info); 176 GetModelSafeRoutingInfo(&info);
177 ModelTypeInvalidationMap invalidation_map = 177 ModelTypeInvalidationMap invalidation_map =
178 ModelSafeRoutingInfoToInvalidationMap(info, std::string()); 178 ModelSafeRoutingInfoToInvalidationMap(info, std::string());
179 sessions::SyncSourceInfo source_info(sync_pb::GetUpdatesCallerInfo::UNKNOWN, 179 sessions::SyncSourceInfo source_info(
180 invalidation_map); 180 sync_pb::GetUpdatesCallerInfo::LOCAL,
181 return new SyncSession(context_.get(), this, source_info); 181 invalidation_map);
182 } 182 // Use our dummy nudge tracker. These tests won't notice that it hasn't
183 // been tracking anything.
tim (not reviewing) 2013/05/07 20:34:13 "... because they don't target scheduling logic an
rlarocque 2013/05/07 21:50:57 Done.
184 session_.reset(
185 SyncSession::BuildForNudge(context_.get(),
186 this,
187 source_info,
188 &nudge_tracker_));
183 189
184 void SyncShareNudge() {
185 session_.reset(MakeSession());
186 EXPECT_TRUE(syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END)); 190 EXPECT_TRUE(syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END));
187 } 191 }
188 192
189 void SyncShareConfigure() { 193 void SyncShareConfigure() {
190 session_.reset(MakeSession()); 194 ModelSafeRoutingInfo info;
195 GetModelSafeRoutingInfo(&info);
196 ModelTypeInvalidationMap invalidation_map =
197 ModelSafeRoutingInfoToInvalidationMap(info, std::string());
198 sessions::SyncSourceInfo source_info(
199 sync_pb::GetUpdatesCallerInfo::RECONFIGURATION,
200 invalidation_map);
201 session_.reset(SyncSession::BuildForNonNudge(context_.get(),
202 this,
203 source_info));
191 EXPECT_TRUE( 204 EXPECT_TRUE(
192 syncer_->SyncShare(session_.get(), DOWNLOAD_UPDATES, APPLY_UPDATES)); 205 syncer_->SyncShare(session_.get(), DOWNLOAD_UPDATES, APPLY_UPDATES));
193 } 206 }
194 207
195 virtual void SetUp() { 208 virtual void SetUp() {
196 dir_maker_.SetUp(); 209 dir_maker_.SetUp();
197 mock_server_.reset(new MockConnectionManager(directory())); 210 mock_server_.reset(new MockConnectionManager(directory()));
198 EnableDatatype(BOOKMARKS); 211 EnableDatatype(BOOKMARKS);
199 EnableDatatype(NIGORI); 212 EnableDatatype(NIGORI);
200 EnableDatatype(PREFERENCES); 213 EnableDatatype(PREFERENCES);
(...skipping 12 matching lines...) Expand all
213 226
214 context_.reset( 227 context_.reset(
215 new SyncSessionContext( 228 new SyncSessionContext(
216 mock_server_.get(), directory(), workers, 229 mock_server_.get(), directory(), workers,
217 &extensions_activity_monitor_, throttled_data_type_tracker_.get(), 230 &extensions_activity_monitor_, throttled_data_type_tracker_.get(),
218 listeners, NULL, &traffic_recorder_, 231 listeners, NULL, &traffic_recorder_,
219 true, // enable keystore encryption 232 true, // enable keystore encryption
220 "fake_invalidator_client_id")); 233 "fake_invalidator_client_id"));
221 context_->set_routing_info(routing_info); 234 context_->set_routing_info(routing_info);
222 syncer_ = new Syncer(); 235 syncer_ = new Syncer();
223 session_.reset(MakeSession());
224 236
225 syncable::ReadTransaction trans(FROM_HERE, directory()); 237 syncable::ReadTransaction trans(FROM_HERE, directory());
226 syncable::Directory::ChildHandles children; 238 syncable::Directory::ChildHandles children;
227 directory()->GetChildHandlesById(&trans, trans.root_id(), &children); 239 directory()->GetChildHandlesById(&trans, trans.root_id(), &children);
228 ASSERT_EQ(0u, children.size()); 240 ASSERT_EQ(0u, children.size());
229 saw_syncer_event_ = false; 241 saw_syncer_event_ = false;
230 root_id_ = TestIdFactory::root(); 242 root_id_ = TestIdFactory::root();
231 parent_id_ = ids_.MakeServer("parent id"); 243 parent_id_ = ids_.MakeServer("parent id");
232 child_id_ = ids_.MakeServer("child id"); 244 child_id_ = ids_.MakeServer("child id");
233 directory()->set_store_birthday(mock_server_->store_birthday()); 245 directory()->set_store_birthday(mock_server_->store_birthday());
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 scoped_ptr<SyncSession> session_; 572 scoped_ptr<SyncSession> session_;
561 scoped_ptr<SyncSessionContext> context_; 573 scoped_ptr<SyncSessionContext> context_;
562 bool saw_syncer_event_; 574 bool saw_syncer_event_;
563 base::TimeDelta last_short_poll_interval_received_; 575 base::TimeDelta last_short_poll_interval_received_;
564 base::TimeDelta last_long_poll_interval_received_; 576 base::TimeDelta last_long_poll_interval_received_;
565 base::TimeDelta last_sessions_commit_delay_seconds_; 577 base::TimeDelta last_sessions_commit_delay_seconds_;
566 scoped_refptr<ModelSafeWorker> worker_; 578 scoped_refptr<ModelSafeWorker> worker_;
567 579
568 ModelTypeSet enabled_datatypes_; 580 ModelTypeSet enabled_datatypes_;
569 TrafficRecorder traffic_recorder_; 581 TrafficRecorder traffic_recorder_;
582 sessions::NudgeTracker nudge_tracker_;
570 583
571 DISALLOW_COPY_AND_ASSIGN(SyncerTest); 584 DISALLOW_COPY_AND_ASSIGN(SyncerTest);
572 }; 585 };
573 586
574 TEST_F(SyncerTest, TestCallGatherUnsyncedEntries) { 587 TEST_F(SyncerTest, TestCallGatherUnsyncedEntries) {
575 { 588 {
576 Syncer::UnsyncedMetaHandles handles; 589 Syncer::UnsyncedMetaHandles handles;
577 { 590 {
578 syncable::ReadTransaction trans(FROM_HERE, directory()); 591 syncable::ReadTransaction trans(FROM_HERE, directory());
579 GetUnsyncedEntries(&trans, &handles); 592 GetUnsyncedEntries(&trans, &handles);
(...skipping 1655 matching lines...) Expand 10 before | Expand all | Expand 10 after
2235 MutableEntry entry(&trans, CREATE, BOOKMARKS, trans.root_id(), "bob"); 2248 MutableEntry entry(&trans, CREATE, BOOKMARKS, trans.root_id(), "bob");
2236 ASSERT_TRUE(entry.good()); 2249 ASSERT_TRUE(entry.good());
2237 entry.Put(syncable::IS_DIR, true); 2250 entry.Put(syncable::IS_DIR, true);
2238 entry.Put(syncable::IS_UNSYNCED, true); 2251 entry.Put(syncable::IS_UNSYNCED, true);
2239 entry.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics()); 2252 entry.Put(syncable::SPECIFICS, DefaultBookmarkSpecifics());
2240 } 2253 }
2241 2254
2242 mock_server_->SetMidCommitCallback( 2255 mock_server_->SetMidCommitCallback(
2243 base::Bind(&EntryCreatedInNewFolderTest::CreateFolderInBob, 2256 base::Bind(&EntryCreatedInNewFolderTest::CreateFolderInBob,
2244 base::Unretained(this))); 2257 base::Unretained(this)));
2245 syncer_->SyncShare(session_.get(), COMMIT, SYNCER_END); 2258 SyncShareNudge();
2246 // We loop until no unsynced handles remain, so we will commit both ids. 2259 // We loop until no unsynced handles remain, so we will commit both ids.
2247 EXPECT_EQ(2u, mock_server_->committed_ids().size()); 2260 EXPECT_EQ(2u, mock_server_->committed_ids().size());
2248 { 2261 {
2249 syncable::ReadTransaction trans(FROM_HERE, directory()); 2262 syncable::ReadTransaction trans(FROM_HERE, directory());
2250 Entry parent_entry(&trans, syncable::GET_BY_ID, 2263 Entry parent_entry(&trans, syncable::GET_BY_ID,
2251 GetOnlyEntryWithName(&trans, TestIdFactory::root(), "bob")); 2264 GetOnlyEntryWithName(&trans, TestIdFactory::root(), "bob"));
2252 ASSERT_TRUE(parent_entry.good()); 2265 ASSERT_TRUE(parent_entry.good());
2253 2266
2254 Id child_id = 2267 Id child_id =
2255 GetOnlyEntryWithName(&trans, parent_entry.Get(ID), "bob"); 2268 GetOnlyEntryWithName(&trans, parent_entry.Get(ID), "bob");
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
2473 entry.Put(ID, ids_.FromNumber(20)); 2486 entry.Put(ID, ids_.FromNumber(20));
2474 entry.Put(BASE_VERSION, 1); 2487 entry.Put(BASE_VERSION, 1);
2475 entry.Put(SERVER_VERSION, 1); 2488 entry.Put(SERVER_VERSION, 1);
2476 entry.Put(SERVER_PARENT_ID, ids_.FromNumber(9999)); // Bad parent. 2489 entry.Put(SERVER_PARENT_ID, ids_.FromNumber(9999)); // Bad parent.
2477 entry.Put(IS_UNSYNCED, true); 2490 entry.Put(IS_UNSYNCED, true);
2478 entry.Put(IS_UNAPPLIED_UPDATE, true); 2491 entry.Put(IS_UNAPPLIED_UPDATE, true);
2479 entry.Put(SPECIFICS, DefaultBookmarkSpecifics()); 2492 entry.Put(SPECIFICS, DefaultBookmarkSpecifics());
2480 entry.Put(SERVER_SPECIFICS, DefaultBookmarkSpecifics()); 2493 entry.Put(SERVER_SPECIFICS, DefaultBookmarkSpecifics());
2481 entry.Put(IS_DEL, false); 2494 entry.Put(IS_DEL, false);
2482 } 2495 }
2483 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END); 2496 SyncShareNudge();
2484 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END);
2485 EXPECT_EQ(1, session_->status_controller().TotalNumConflictingItems()); 2497 EXPECT_EQ(1, session_->status_controller().TotalNumConflictingItems());
2486 saw_syncer_event_ = false; 2498 saw_syncer_event_ = false;
2487 } 2499 }
2488 2500
2489 // Original problem synopsis: 2501 // Original problem synopsis:
2490 // Illegal parent 2502 // Illegal parent
2491 // Unexpected error during sync if we: 2503 // Unexpected error during sync if we:
2492 // make a new folder bob 2504 // make a new folder bob
2493 // wait for sync 2505 // wait for sync
2494 // make a new folder fred 2506 // make a new folder fred
2495 // move bob into fred 2507 // move bob into fred
2496 // remove bob 2508 // remove bob
2497 // remove fred 2509 // remove fred
2498 // if no syncing occured midway, bob will have an illegal parent 2510 // if no syncing occured midway, bob will have an illegal parent
2499 TEST_F(SyncerTest, DeletingEntryInFolder) { 2511 TEST_F(SyncerTest, DeletingEntryInFolder) {
2500 // This test is a little fake. 2512 // This test is a little fake.
2501 int64 existing_metahandle; 2513 int64 existing_metahandle;
2502 { 2514 {
2503 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2515 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2504 MutableEntry entry(&trans, CREATE, BOOKMARKS, trans.root_id(), "existing"); 2516 MutableEntry entry(&trans, CREATE, BOOKMARKS, trans.root_id(), "existing");
2505 ASSERT_TRUE(entry.good()); 2517 ASSERT_TRUE(entry.good());
2506 entry.Put(IS_DIR, true); 2518 entry.Put(IS_DIR, true);
2507 entry.Put(SPECIFICS, DefaultBookmarkSpecifics()); 2519 entry.Put(SPECIFICS, DefaultBookmarkSpecifics());
2508 entry.Put(IS_UNSYNCED, true); 2520 entry.Put(IS_UNSYNCED, true);
2509 existing_metahandle = entry.Get(META_HANDLE); 2521 existing_metahandle = entry.Get(META_HANDLE);
2510 } 2522 }
2511 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END); 2523 SyncShareNudge();
2512 { 2524 {
2513 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2525 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2514 MutableEntry newfolder(&trans, CREATE, BOOKMARKS, trans.root_id(), "new"); 2526 MutableEntry newfolder(&trans, CREATE, BOOKMARKS, trans.root_id(), "new");
2515 ASSERT_TRUE(newfolder.good()); 2527 ASSERT_TRUE(newfolder.good());
2516 newfolder.Put(IS_DIR, true); 2528 newfolder.Put(IS_DIR, true);
2517 newfolder.Put(SPECIFICS, DefaultBookmarkSpecifics()); 2529 newfolder.Put(SPECIFICS, DefaultBookmarkSpecifics());
2518 newfolder.Put(IS_UNSYNCED, true); 2530 newfolder.Put(IS_UNSYNCED, true);
2519 2531
2520 MutableEntry existing(&trans, GET_BY_HANDLE, existing_metahandle); 2532 MutableEntry existing(&trans, GET_BY_HANDLE, existing_metahandle);
2521 ASSERT_TRUE(existing.good()); 2533 ASSERT_TRUE(existing.good());
2522 existing.Put(PARENT_ID, newfolder.Get(ID)); 2534 existing.Put(PARENT_ID, newfolder.Get(ID));
2523 existing.Put(IS_UNSYNCED, true); 2535 existing.Put(IS_UNSYNCED, true);
2524 EXPECT_TRUE(existing.Get(ID).ServerKnows()); 2536 EXPECT_TRUE(existing.Get(ID).ServerKnows());
2525 2537
2526 newfolder.Put(IS_DEL, true); 2538 newfolder.Put(IS_DEL, true);
2527 existing.Put(IS_DEL, true); 2539 existing.Put(IS_DEL, true);
2528 } 2540 }
2529 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END); 2541 SyncShareNudge();
2530 EXPECT_EQ(0, status().num_server_conflicts()); 2542 EXPECT_EQ(0, status().num_server_conflicts());
2531 } 2543 }
2532 2544
2533 TEST_F(SyncerTest, DeletingEntryWithLocalEdits) { 2545 TEST_F(SyncerTest, DeletingEntryWithLocalEdits) {
2534 int64 newfolder_metahandle; 2546 int64 newfolder_metahandle;
2535 2547
2536 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10, 2548 mock_server_->AddUpdateDirectory(1, 0, "bob", 1, 10,
2537 foreign_cache_guid(), "-1"); 2549 foreign_cache_guid(), "-1");
2538 SyncShareNudge(); 2550 SyncShareNudge();
2539 { 2551 {
2540 WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 2552 WriteTransaction trans(FROM_HERE, UNITTEST, directory());
2541 MutableEntry newfolder( 2553 MutableEntry newfolder(
2542 &trans, CREATE, BOOKMARKS, ids_.FromNumber(1), "local"); 2554 &trans, CREATE, BOOKMARKS, ids_.FromNumber(1), "local");
2543 ASSERT_TRUE(newfolder.good()); 2555 ASSERT_TRUE(newfolder.good());
2544 newfolder.Put(IS_UNSYNCED, true); 2556 newfolder.Put(IS_UNSYNCED, true);
2545 newfolder.Put(IS_DIR, true); 2557 newfolder.Put(IS_DIR, true);
2546 newfolder.Put(SPECIFICS, DefaultBookmarkSpecifics()); 2558 newfolder.Put(SPECIFICS, DefaultBookmarkSpecifics());
2547 newfolder_metahandle = newfolder.Get(META_HANDLE); 2559 newfolder_metahandle = newfolder.Get(META_HANDLE);
2548 } 2560 }
2549 mock_server_->AddUpdateDirectory(1, 0, "bob", 2, 20, 2561 mock_server_->AddUpdateDirectory(1, 0, "bob", 2, 20,
2550 foreign_cache_guid(), "-1"); 2562 foreign_cache_guid(), "-1");
2551 mock_server_->SetLastUpdateDeleted(); 2563 mock_server_->SetLastUpdateDeleted();
2552 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, APPLY_UPDATES); 2564 SyncShareConfigure();
2553 { 2565 {
2554 syncable::ReadTransaction trans(FROM_HERE, directory()); 2566 syncable::ReadTransaction trans(FROM_HERE, directory());
2555 Entry entry(&trans, syncable::GET_BY_HANDLE, newfolder_metahandle); 2567 Entry entry(&trans, syncable::GET_BY_HANDLE, newfolder_metahandle);
2556 ASSERT_TRUE(entry.good()); 2568 ASSERT_TRUE(entry.good());
2557 } 2569 }
2558 } 2570 }
2559 2571
2560 TEST_F(SyncerTest, FolderSwapUpdate) { 2572 TEST_F(SyncerTest, FolderSwapUpdate) {
2561 mock_server_->AddUpdateDirectory(7801, 0, "bob", 1, 10, 2573 mock_server_->AddUpdateDirectory(7801, 0, "bob", 1, 10,
2562 foreign_cache_guid(), "-7801"); 2574 foreign_cache_guid(), "-7801");
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after
3197 const int depth = 400; 3209 const int depth = 400;
3198 syncable::Id folder_id = ids_.FromNumber(1); 3210 syncable::Id folder_id = ids_.FromNumber(1);
3199 3211
3200 // First we an item in a folder in the root. However the folder won't come 3212 // First we an item in a folder in the root. However the folder won't come
3201 // till much later. 3213 // till much later.
3202 syncable::Id stuck_entry_id = TestIdFactory::FromNumber(99999); 3214 syncable::Id stuck_entry_id = TestIdFactory::FromNumber(99999);
3203 mock_server_->AddUpdateDirectory(stuck_entry_id, 3215 mock_server_->AddUpdateDirectory(stuck_entry_id,
3204 folder_id, "stuck", 1, 1, 3216 folder_id, "stuck", 1, 1,
3205 foreign_cache_guid(), "-99999"); 3217 foreign_cache_guid(), "-99999");
3206 mock_server_->SetChangesRemaining(depth - 1); 3218 mock_server_->SetChangesRemaining(depth - 1);
3207 syncer_->SyncShare(session_.get(), SYNCER_BEGIN, SYNCER_END); 3219 SyncShareNudge();
3208 3220
3209 // Buffer up a very long series of downloads. 3221 // Buffer up a very long series of downloads.
3210 // We should never be stuck (conflict resolution shouldn't 3222 // We should never be stuck (conflict resolution shouldn't
3211 // kick in so long as we're making forward progress). 3223 // kick in so long as we're making forward progress).
3212 for (int i = 0; i < depth; i++) { 3224 for (int i = 0; i < depth; i++) {
3213 mock_server_->NextUpdateBatch(); 3225 mock_server_->NextUpdateBatch();
3214 mock_server_->SetNewTimestamp(i + 1); 3226 mock_server_->SetNewTimestamp(i + 1);
3215 mock_server_->SetChangesRemaining(depth - i); 3227 mock_server_->SetChangesRemaining(depth - i);
3216 } 3228 }
3217 3229
(...skipping 1574 matching lines...) Expand 10 before | Expand all | Expand 10 after
4792 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id); 4804 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id);
4793 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); 4805 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count);
4794 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); 4806 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count);
4795 } else { 4807 } else {
4796 EXPECT_TRUE(final_monitor_records.empty()) 4808 EXPECT_TRUE(final_monitor_records.empty())
4797 << "Should not restore records after successful bookmark commit."; 4809 << "Should not restore records after successful bookmark commit.";
4798 } 4810 }
4799 } 4811 }
4800 4812
4801 } // namespace syncer 4813 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698