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 bool SyncShareAsDelegate( | 189 bool SyncShareAsDelegate(SyncSessionJob::Purpose purpose) { |
190 SyncSchedulerImpl::SyncSessionJob::SyncSessionJobPurpose purpose) { | |
191 SyncerStep start; | 190 SyncerStep start; |
192 SyncerStep end; | 191 SyncerStep end; |
193 SyncSchedulerImpl::SetSyncerStepsForPurpose(purpose, &start, &end); | 192 SyncSessionJob::GetSyncerStepsForPurpose(purpose, &start, &end); |
194 | 193 |
195 session_.reset(MakeSession()); | 194 session_.reset(MakeSession()); |
196 syncer_->SyncShare(session_.get(), start, end); | 195 EXPECT_TRUE(syncer_->SyncShare(session_.get(), start, end)); |
197 return session_->HasMoreToSync(); | 196 return session_->HasMoreToSync(); |
198 } | 197 } |
199 | 198 |
200 bool SyncShareNudge() { | 199 bool SyncShareNudge() { |
201 session_.reset(MakeSession()); | 200 session_.reset(MakeSession()); |
202 return SyncShareAsDelegate(SyncSchedulerImpl::SyncSessionJob::NUDGE); | 201 return SyncShareAsDelegate(SyncSessionJob::NUDGE); |
203 } | 202 } |
204 | 203 |
205 bool SyncShareConfigure() { | 204 bool SyncShareConfigure() { |
206 session_.reset(MakeSession()); | 205 session_.reset(MakeSession()); |
207 return SyncShareAsDelegate( | 206 return SyncShareAsDelegate(SyncSessionJob::CONFIGURATION); |
208 SyncSchedulerImpl::SyncSessionJob::CONFIGURATION); | |
209 } | 207 } |
210 | 208 |
211 void LoopSyncShare() { | 209 void LoopSyncShare() { |
212 bool should_loop = false; | 210 bool should_loop = false; |
213 int loop_iterations = 0; | 211 int loop_iterations = 0; |
214 do { | 212 do { |
215 ASSERT_LT(++loop_iterations, 100) << "infinite loop detected. please fix"; | 213 ASSERT_LT(++loop_iterations, 100) << "infinite loop detected. please fix"; |
216 should_loop = SyncShareNudge(); | 214 should_loop = SyncShareNudge(); |
217 } while (should_loop); | 215 } while (should_loop); |
218 } | 216 } |
(...skipping 2323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2542 } | 2540 } |
2543 } | 2541 } |
2544 ASSERT_EQ(items_to_commit, directory()->unsynced_entity_count()); | 2542 ASSERT_EQ(items_to_commit, directory()->unsynced_entity_count()); |
2545 | 2543 |
2546 // The second commit should fail. It will be preceded by one successful | 2544 // The second commit should fail. It will be preceded by one successful |
2547 // GetUpdate and one succesful commit. | 2545 // GetUpdate and one succesful commit. |
2548 mock_server_->FailNthPostBufferToPathCall(3); | 2546 mock_server_->FailNthPostBufferToPathCall(3); |
2549 SyncShareNudge(); | 2547 SyncShareNudge(); |
2550 | 2548 |
2551 EXPECT_EQ(1U, mock_server_->commit_messages().size()); | 2549 EXPECT_EQ(1U, mock_server_->commit_messages().size()); |
2552 EXPECT_FALSE(session_->Succeeded()); | |
2553 EXPECT_EQ(SYNC_SERVER_ERROR, | 2550 EXPECT_EQ(SYNC_SERVER_ERROR, |
2554 session_->status_controller().model_neutral_state().commit_result); | 2551 session_->status_controller().model_neutral_state().commit_result); |
2555 EXPECT_EQ(items_to_commit - kDefaultMaxCommitBatchSize, | 2552 EXPECT_EQ(items_to_commit - kDefaultMaxCommitBatchSize, |
2556 directory()->unsynced_entity_count()); | 2553 directory()->unsynced_entity_count()); |
2557 } | 2554 } |
2558 | 2555 |
2559 // Test that a single conflict response from the server will cause us to exit | 2556 // Test that a single conflict response from the server will cause us to exit |
2560 // the commit loop immediately. | 2557 // the commit loop immediately. |
2561 TEST_F(SyncerTest, CommitManyItemsInOneGo_CommitConflict) { | 2558 TEST_F(SyncerTest, CommitManyItemsInOneGo_CommitConflict) { |
2562 uint32 num_batches = 2; | 2559 uint32 num_batches = 2; |
(...skipping 10 matching lines...) Expand all Loading... |
2573 } | 2570 } |
2574 } | 2571 } |
2575 ASSERT_EQ(items_to_commit, directory()->unsynced_entity_count()); | 2572 ASSERT_EQ(items_to_commit, directory()->unsynced_entity_count()); |
2576 | 2573 |
2577 // Return a CONFLICT response for the first item. | 2574 // Return a CONFLICT response for the first item. |
2578 mock_server_->set_conflict_n_commits(1); | 2575 mock_server_->set_conflict_n_commits(1); |
2579 SyncShareNudge(); | 2576 SyncShareNudge(); |
2580 | 2577 |
2581 // We should stop looping at the first sign of trouble. | 2578 // We should stop looping at the first sign of trouble. |
2582 EXPECT_EQ(1U, mock_server_->commit_messages().size()); | 2579 EXPECT_EQ(1U, mock_server_->commit_messages().size()); |
2583 EXPECT_FALSE(session_->Succeeded()); | 2580 EXPECT_FALSE(session_->HasMoreToSync()); |
2584 EXPECT_EQ(items_to_commit - (kDefaultMaxCommitBatchSize - 1), | 2581 EXPECT_EQ(items_to_commit - (kDefaultMaxCommitBatchSize - 1), |
2585 directory()->unsynced_entity_count()); | 2582 directory()->unsynced_entity_count()); |
2586 } | 2583 } |
2587 | 2584 |
2588 TEST_F(SyncerTest, HugeConflict) { | 2585 TEST_F(SyncerTest, HugeConflict) { |
2589 int item_count = 300; // We should be able to do 300 or 3000 w/o issue. | 2586 int item_count = 300; // We should be able to do 300 or 3000 w/o issue. |
2590 | 2587 |
2591 syncable::Id parent_id = ids_.NewServerId(); | 2588 syncable::Id parent_id = ids_.NewServerId(); |
2592 syncable::Id last_id = parent_id; | 2589 syncable::Id last_id = parent_id; |
2593 vector<syncable::Id> tree_ids; | 2590 vector<syncable::Id> tree_ids; |
(...skipping 2131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4725 | 4722 |
4726 TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) { | 4723 TEST_F(SyncerPositionTiebreakingTest, MidLowHigh) { |
4727 Add(mid_id_); | 4724 Add(mid_id_); |
4728 Add(low_id_); | 4725 Add(low_id_); |
4729 Add(high_id_); | 4726 Add(high_id_); |
4730 SyncShareNudge(); | 4727 SyncShareNudge(); |
4731 ExpectLocalOrderIsByServerId(); | 4728 ExpectLocalOrderIsByServerId(); |
4732 } | 4729 } |
4733 | 4730 |
4734 } // namespace syncer | 4731 } // namespace syncer |
OLD | NEW |