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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 void SyncShareAsDelegate( | 189 |
190 SyncSchedulerImpl::SyncSessionJob::SyncSessionJobPurpose purpose) { | 190 void SyncShareAsDelegate(SyncSessionJob::Purpose purpose) { |
191 SyncerStep start; | 191 SyncerStep start; |
192 SyncerStep end; | 192 SyncerStep end; |
193 SyncSchedulerImpl::SetSyncerStepsForPurpose(purpose, &start, &end); | 193 SyncSessionJob::GetSyncerStepsForPurpose(purpose, &start, &end); |
194 | 194 |
195 session_.reset(MakeSession()); | 195 session_.reset(MakeSession()); |
196 syncer_->SyncShare(session_.get(), start, end); | 196 EXPECT_TRUE(syncer_->SyncShare(session_.get(), start, end)); |
197 } | 197 } |
198 | 198 |
199 void SyncShareNudge() { | 199 void SyncShareNudge() { |
200 session_.reset(MakeSession()); | 200 session_.reset(MakeSession()); |
201 SyncShareAsDelegate(SyncSchedulerImpl::SyncSessionJob::NUDGE); | 201 SyncShareAsDelegate(SyncSessionJob::NUDGE); |
202 } | 202 } |
203 | 203 |
204 void SyncShareConfigure() { | 204 void SyncShareConfigure() { |
205 session_.reset(MakeSession()); | 205 session_.reset(MakeSession()); |
206 SyncShareAsDelegate(SyncSchedulerImpl::SyncSessionJob::CONFIGURATION); | 206 SyncShareAsDelegate(SyncSessionJob::CONFIGURATION); |
207 } | 207 } |
208 | 208 |
209 virtual void SetUp() { | 209 virtual void SetUp() { |
210 dir_maker_.SetUp(); | 210 dir_maker_.SetUp(); |
211 mock_server_.reset(new MockConnectionManager(directory())); | 211 mock_server_.reset(new MockConnectionManager(directory())); |
212 EnableDatatype(BOOKMARKS); | 212 EnableDatatype(BOOKMARKS); |
213 EnableDatatype(NIGORI); | 213 EnableDatatype(NIGORI); |
214 EnableDatatype(PREFERENCES); | 214 EnableDatatype(PREFERENCES); |
215 EnableDatatype(NIGORI); | 215 EnableDatatype(NIGORI); |
216 worker_ = new FakeModelWorker(GROUP_PASSIVE); | 216 worker_ = new FakeModelWorker(GROUP_PASSIVE); |
(...skipping 2314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2531 } | 2531 } |
2532 } | 2532 } |
2533 ASSERT_EQ(items_to_commit, directory()->unsynced_entity_count()); | 2533 ASSERT_EQ(items_to_commit, directory()->unsynced_entity_count()); |
2534 | 2534 |
2535 // The second commit should fail. It will be preceded by one successful | 2535 // The second commit should fail. It will be preceded by one successful |
2536 // GetUpdate and one succesful commit. | 2536 // GetUpdate and one succesful commit. |
2537 mock_server_->FailNthPostBufferToPathCall(3); | 2537 mock_server_->FailNthPostBufferToPathCall(3); |
2538 SyncShareNudge(); | 2538 SyncShareNudge(); |
2539 | 2539 |
2540 EXPECT_EQ(1U, mock_server_->commit_messages().size()); | 2540 EXPECT_EQ(1U, mock_server_->commit_messages().size()); |
2541 EXPECT_FALSE(session_->Succeeded()); | |
2542 EXPECT_EQ(SYNC_SERVER_ERROR, | 2541 EXPECT_EQ(SYNC_SERVER_ERROR, |
2543 session_->status_controller().model_neutral_state().commit_result); | 2542 session_->status_controller().model_neutral_state().commit_result); |
2544 EXPECT_EQ(items_to_commit - kDefaultMaxCommitBatchSize, | 2543 EXPECT_EQ(items_to_commit - kDefaultMaxCommitBatchSize, |
2545 directory()->unsynced_entity_count()); | 2544 directory()->unsynced_entity_count()); |
2546 } | 2545 } |
2547 | 2546 |
2548 // Test that a single conflict response from the server will cause us to exit | 2547 // Test that a single conflict response from the server will cause us to exit |
2549 // the commit loop immediately. | 2548 // the commit loop immediately. |
2550 TEST_F(SyncerTest, CommitManyItemsInOneGo_CommitConflict) { | 2549 TEST_F(SyncerTest, CommitManyItemsInOneGo_CommitConflict) { |
2551 uint32 num_batches = 2; | 2550 uint32 num_batches = 2; |
(...skipping 10 matching lines...) Expand all Loading... |
2562 } | 2561 } |
2563 } | 2562 } |
2564 ASSERT_EQ(items_to_commit, directory()->unsynced_entity_count()); | 2563 ASSERT_EQ(items_to_commit, directory()->unsynced_entity_count()); |
2565 | 2564 |
2566 // Return a CONFLICT response for the first item. | 2565 // Return a CONFLICT response for the first item. |
2567 mock_server_->set_conflict_n_commits(1); | 2566 mock_server_->set_conflict_n_commits(1); |
2568 SyncShareNudge(); | 2567 SyncShareNudge(); |
2569 | 2568 |
2570 // We should stop looping at the first sign of trouble. | 2569 // We should stop looping at the first sign of trouble. |
2571 EXPECT_EQ(1U, mock_server_->commit_messages().size()); | 2570 EXPECT_EQ(1U, mock_server_->commit_messages().size()); |
2572 EXPECT_FALSE(session_->Succeeded()); | 2571 EXPECT_FALSE(session_->HasMoreToSync()); |
2573 EXPECT_EQ(items_to_commit - (kDefaultMaxCommitBatchSize - 1), | 2572 EXPECT_EQ(items_to_commit - (kDefaultMaxCommitBatchSize - 1), |
2574 directory()->unsynced_entity_count()); | 2573 directory()->unsynced_entity_count()); |
2575 } | 2574 } |
2576 | 2575 |
2577 TEST_F(SyncerTest, HugeConflict) { | 2576 TEST_F(SyncerTest, HugeConflict) { |
2578 int item_count = 300; // We should be able to do 300 or 3000 w/o issue. | 2577 int item_count = 300; // We should be able to do 300 or 3000 w/o issue. |
2579 | 2578 |
2580 syncable::Id parent_id = ids_.NewServerId(); | 2579 syncable::Id parent_id = ids_.NewServerId(); |
2581 syncable::Id last_id = parent_id; | 2580 syncable::Id last_id = parent_id; |
2582 vector<syncable::Id> tree_ids; | 2581 vector<syncable::Id> tree_ids; |
(...skipping 2131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4714 | 4713 |
4715 TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) { | 4714 TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) { |
4716 Add(mid_id_); | 4715 Add(mid_id_); |
4717 Add(low_id_); | 4716 Add(low_id_); |
4718 Add(high_id_); | 4717 Add(high_id_); |
4719 SyncShareNudge(); | 4718 SyncShareNudge(); |
4720 ExpectLocalOrderIsByServerId(); | 4719 ExpectLocalOrderIsByServerId(); |
4721 } | 4720 } |
4722 | 4721 |
4723 } // namespace syncer | 4722 } // namespace syncer |
OLD | NEW |