| OLD | NEW |
| 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 Loading... |
| 178 std::vector<ModelSafeWorker*> workers; | 178 std::vector<ModelSafeWorker*> workers; |
| 179 GetModelSafeRoutingInfo(&info); | 179 GetModelSafeRoutingInfo(&info); |
| 180 GetWorkers(&workers); | 180 GetWorkers(&workers); |
| 181 ModelTypeStateMap types = | 181 ModelTypeStateMap types = |
| 182 ModelSafeRoutingInfoToStateMap(info, std::string()); | 182 ModelSafeRoutingInfoToStateMap(info, std::string()); |
| 183 return new SyncSession(context_.get(), this, | 183 return new SyncSession(context_.get(), this, |
| 184 sessions::SyncSourceInfo(sync_pb::GetUpdatesCallerInfo::UNKNOWN, types), | 184 sessions::SyncSourceInfo(sync_pb::GetUpdatesCallerInfo::UNKNOWN, types), |
| 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 2304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2522 } | 2520 } |
| 2523 } | 2521 } |
| 2524 ASSERT_EQ(items_to_commit, directory()->unsynced_entity_count()); | 2522 ASSERT_EQ(items_to_commit, directory()->unsynced_entity_count()); |
| 2525 | 2523 |
| 2526 // The second commit should fail. It will be preceded by one successful | 2524 // The second commit should fail. It will be preceded by one successful |
| 2527 // GetUpdate and one succesful commit. | 2525 // GetUpdate and one succesful commit. |
| 2528 mock_server_->FailNthPostBufferToPathCall(3); | 2526 mock_server_->FailNthPostBufferToPathCall(3); |
| 2529 SyncShareNudge(); | 2527 SyncShareNudge(); |
| 2530 | 2528 |
| 2531 EXPECT_EQ(1U, mock_server_->commit_messages().size()); | 2529 EXPECT_EQ(1U, mock_server_->commit_messages().size()); |
| 2532 EXPECT_FALSE(session_->Succeeded()); | |
| 2533 EXPECT_EQ(SYNC_SERVER_ERROR, | 2530 EXPECT_EQ(SYNC_SERVER_ERROR, |
| 2534 session_->status_controller().model_neutral_state().commit_result); | 2531 session_->status_controller().model_neutral_state().commit_result); |
| 2535 EXPECT_EQ(items_to_commit - kDefaultMaxCommitBatchSize, | 2532 EXPECT_EQ(items_to_commit - kDefaultMaxCommitBatchSize, |
| 2536 directory()->unsynced_entity_count()); | 2533 directory()->unsynced_entity_count()); |
| 2537 } | 2534 } |
| 2538 | 2535 |
| 2539 // Test that a single conflict response from the server will cause us to exit | 2536 // Test that a single conflict response from the server will cause us to exit |
| 2540 // the commit loop immediately. | 2537 // the commit loop immediately. |
| 2541 TEST_F(SyncerTest, CommitManyItemsInOneGo_CommitConflict) { | 2538 TEST_F(SyncerTest, CommitManyItemsInOneGo_CommitConflict) { |
| 2542 uint32 num_batches = 2; | 2539 uint32 num_batches = 2; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2553 } | 2550 } |
| 2554 } | 2551 } |
| 2555 ASSERT_EQ(items_to_commit, directory()->unsynced_entity_count()); | 2552 ASSERT_EQ(items_to_commit, directory()->unsynced_entity_count()); |
| 2556 | 2553 |
| 2557 // Return a CONFLICT response for the first item. | 2554 // Return a CONFLICT response for the first item. |
| 2558 mock_server_->set_conflict_n_commits(1); | 2555 mock_server_->set_conflict_n_commits(1); |
| 2559 SyncShareNudge(); | 2556 SyncShareNudge(); |
| 2560 | 2557 |
| 2561 // We should stop looping at the first sign of trouble. | 2558 // We should stop looping at the first sign of trouble. |
| 2562 EXPECT_EQ(1U, mock_server_->commit_messages().size()); | 2559 EXPECT_EQ(1U, mock_server_->commit_messages().size()); |
| 2563 EXPECT_FALSE(session_->Succeeded()); | 2560 EXPECT_FALSE(session_->HasMoreToSync()); |
| 2564 EXPECT_EQ(items_to_commit - (kDefaultMaxCommitBatchSize - 1), | 2561 EXPECT_EQ(items_to_commit - (kDefaultMaxCommitBatchSize - 1), |
| 2565 directory()->unsynced_entity_count()); | 2562 directory()->unsynced_entity_count()); |
| 2566 } | 2563 } |
| 2567 | 2564 |
| 2568 TEST_F(SyncerTest, HugeConflict) { | 2565 TEST_F(SyncerTest, HugeConflict) { |
| 2569 int item_count = 300; // We should be able to do 300 or 3000 w/o issue. | 2566 int item_count = 300; // We should be able to do 300 or 3000 w/o issue. |
| 2570 | 2567 |
| 2571 syncable::Id parent_id = ids_.NewServerId(); | 2568 syncable::Id parent_id = ids_.NewServerId(); |
| 2572 syncable::Id last_id = parent_id; | 2569 syncable::Id last_id = parent_id; |
| 2573 vector<syncable::Id> tree_ids; | 2570 vector<syncable::Id> tree_ids; |
| (...skipping 2118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4692 | 4689 |
| 4693 TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) { | 4690 TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) { |
| 4694 Add(mid_id_); | 4691 Add(mid_id_); |
| 4695 Add(low_id_); | 4692 Add(low_id_); |
| 4696 Add(high_id_); | 4693 Add(high_id_); |
| 4697 SyncShareNudge(); | 4694 SyncShareNudge(); |
| 4698 ExpectLocalOrderIsByServerId(); | 4695 ExpectLocalOrderIsByServerId(); |
| 4699 } | 4696 } |
| 4700 | 4697 |
| 4701 } // namespace syncer | 4698 } // namespace syncer |
| OLD | NEW |