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

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

Issue 10917234: sync: make scheduling logic and job ownership more obvious. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: tweak Created 8 years, 2 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 | Annotate | Revision Log
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 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 GetModelSafeRoutingInfo(&info); 178 GetModelSafeRoutingInfo(&info);
179 GetWorkers(&workers); 179 GetWorkers(&workers);
180 ModelTypeInvalidationMap invalidation_map = 180 ModelTypeInvalidationMap invalidation_map =
181 ModelSafeRoutingInfoToInvalidationMap(info, std::string()); 181 ModelSafeRoutingInfoToInvalidationMap(info, std::string());
182 return new SyncSession(context_.get(), this, 182 return new SyncSession(context_.get(), this,
183 sessions::SyncSourceInfo(sync_pb::GetUpdatesCallerInfo::UNKNOWN, 183 sessions::SyncSourceInfo(sync_pb::GetUpdatesCallerInfo::UNKNOWN,
184 invalidation_map), 184 invalidation_map),
185 info, workers); 185 info, workers);
186 } 186 }
187 187
188 bool SyncShareAsDelegate( 188 bool SyncShareAsDelegate(SyncSessionJob::Purpose purpose) {
189 SyncSchedulerImpl::SyncSessionJob::SyncSessionJobPurpose purpose) {
190 SyncerStep start; 189 SyncerStep start;
191 SyncerStep end; 190 SyncerStep end;
192 SyncSchedulerImpl::SetSyncerStepsForPurpose(purpose, &start, &end); 191 SyncSessionJob::GetSyncerStepsForPurpose(purpose, &start, &end);
193 192
194 session_.reset(MakeSession()); 193 session_.reset(MakeSession());
195 syncer_->SyncShare(session_.get(), start, end); 194 EXPECT_TRUE(syncer_->SyncShare(session_.get(), start, end));
196 return session_->HasMoreToSync(); 195 return session_->HasMoreToSync();
197 } 196 }
198 197
199 bool SyncShareNudge() { 198 bool SyncShareNudge() {
200 session_.reset(MakeSession()); 199 session_.reset(MakeSession());
201 return SyncShareAsDelegate(SyncSchedulerImpl::SyncSessionJob::NUDGE); 200 return SyncShareAsDelegate(SyncSessionJob::NUDGE);
202 } 201 }
203 202
204 bool SyncShareConfigure() { 203 bool SyncShareConfigure() {
205 session_.reset(MakeSession()); 204 session_.reset(MakeSession());
206 return SyncShareAsDelegate( 205 return SyncShareAsDelegate(SyncSessionJob::CONFIGURATION);
207 SyncSchedulerImpl::SyncSessionJob::CONFIGURATION);
208 } 206 }
209 207
210 void LoopSyncShare() { 208 void LoopSyncShare() {
211 bool should_loop = false; 209 bool should_loop = false;
212 int loop_iterations = 0; 210 int loop_iterations = 0;
213 do { 211 do {
214 ASSERT_LT(++loop_iterations, 100) << "infinite loop detected. please fix"; 212 ASSERT_LT(++loop_iterations, 100) << "infinite loop detected. please fix";
215 should_loop = SyncShareNudge(); 213 should_loop = SyncShareNudge();
216 } while (should_loop); 214 } while (should_loop);
217 } 215 }
(...skipping 2289 matching lines...) Expand 10 before | Expand all | Expand 10 after
2507 } 2505 }
2508 } 2506 }
2509 ASSERT_EQ(items_to_commit, directory()->unsynced_entity_count()); 2507 ASSERT_EQ(items_to_commit, directory()->unsynced_entity_count());
2510 2508
2511 // The second commit should fail. It will be preceded by one successful 2509 // The second commit should fail. It will be preceded by one successful
2512 // GetUpdate and one succesful commit. 2510 // GetUpdate and one succesful commit.
2513 mock_server_->FailNthPostBufferToPathCall(3); 2511 mock_server_->FailNthPostBufferToPathCall(3);
2514 SyncShareNudge(); 2512 SyncShareNudge();
2515 2513
2516 EXPECT_EQ(1U, mock_server_->commit_messages().size()); 2514 EXPECT_EQ(1U, mock_server_->commit_messages().size());
2517 EXPECT_FALSE(session_->Succeeded());
2518 EXPECT_EQ(SYNC_SERVER_ERROR, 2515 EXPECT_EQ(SYNC_SERVER_ERROR,
2519 session_->status_controller().model_neutral_state().commit_result); 2516 session_->status_controller().model_neutral_state().commit_result);
2520 EXPECT_EQ(items_to_commit - kDefaultMaxCommitBatchSize, 2517 EXPECT_EQ(items_to_commit - kDefaultMaxCommitBatchSize,
2521 directory()->unsynced_entity_count()); 2518 directory()->unsynced_entity_count());
2522 } 2519 }
2523 2520
2524 // Test that a single conflict response from the server will cause us to exit 2521 // Test that a single conflict response from the server will cause us to exit
2525 // the commit loop immediately. 2522 // the commit loop immediately.
2526 TEST_F(SyncerTest, CommitManyItemsInOneGo_CommitConflict) { 2523 TEST_F(SyncerTest, CommitManyItemsInOneGo_CommitConflict) {
2527 uint32 num_batches = 2; 2524 uint32 num_batches = 2;
(...skipping 10 matching lines...) Expand all
2538 } 2535 }
2539 } 2536 }
2540 ASSERT_EQ(items_to_commit, directory()->unsynced_entity_count()); 2537 ASSERT_EQ(items_to_commit, directory()->unsynced_entity_count());
2541 2538
2542 // Return a CONFLICT response for the first item. 2539 // Return a CONFLICT response for the first item.
2543 mock_server_->set_conflict_n_commits(1); 2540 mock_server_->set_conflict_n_commits(1);
2544 SyncShareNudge(); 2541 SyncShareNudge();
2545 2542
2546 // We should stop looping at the first sign of trouble. 2543 // We should stop looping at the first sign of trouble.
2547 EXPECT_EQ(1U, mock_server_->commit_messages().size()); 2544 EXPECT_EQ(1U, mock_server_->commit_messages().size());
2548 EXPECT_FALSE(session_->Succeeded()); 2545 EXPECT_FALSE(session_->HasMoreToSync());
2549 EXPECT_EQ(items_to_commit - (kDefaultMaxCommitBatchSize - 1), 2546 EXPECT_EQ(items_to_commit - (kDefaultMaxCommitBatchSize - 1),
2550 directory()->unsynced_entity_count()); 2547 directory()->unsynced_entity_count());
2551 } 2548 }
2552 2549
2553 TEST_F(SyncerTest, HugeConflict) { 2550 TEST_F(SyncerTest, HugeConflict) {
2554 int item_count = 300; // We should be able to do 300 or 3000 w/o issue. 2551 int item_count = 300; // We should be able to do 300 or 3000 w/o issue.
2555 2552
2556 syncable::Id parent_id = ids_.NewServerId(); 2553 syncable::Id parent_id = ids_.NewServerId();
2557 syncable::Id last_id = parent_id; 2554 syncable::Id last_id = parent_id;
2558 vector<syncable::Id> tree_ids; 2555 vector<syncable::Id> tree_ids;
(...skipping 2118 matching lines...) Expand 10 before | Expand all | Expand 10 after
4677 4674
4678 TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) { 4675 TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) {
4679 Add(mid_id_); 4676 Add(mid_id_);
4680 Add(low_id_); 4677 Add(low_id_);
4681 Add(high_id_); 4678 Add(high_id_);
4682 SyncShareNudge(); 4679 SyncShareNudge();
4683 ExpectLocalOrderIsByServerId(); 4680 ExpectLocalOrderIsByServerId();
4684 } 4681 }
4685 4682
4686 } // namespace syncer 4683 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698