| 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 #include "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/callback.h" | 6 #include "base/callback.h" |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/test/test_timeouts.h" | 10 #include "base/test/test_timeouts.h" |
| 11 #include "sync/engine/sync_scheduler.h" | 11 #include "sync/engine/sync_scheduler.h" |
| 12 #include "sync/engine/syncer.h" | 12 #include "sync/engine/syncer.h" |
| 13 #include "sync/engine/throttled_data_type_tracker.h" | 13 #include "sync/engine/throttled_data_type_tracker.h" |
| 14 #include "sync/sessions/test_util.h" | 14 #include "sync/sessions/test_util.h" |
| 15 #include "sync/test/callback_counter.h" | |
| 16 #include "sync/test/engine/fake_model_worker.h" | 15 #include "sync/test/engine/fake_model_worker.h" |
| 17 #include "sync/test/engine/mock_connection_manager.h" | 16 #include "sync/test/engine/mock_connection_manager.h" |
| 18 #include "sync/test/engine/test_directory_setter_upper.h" | 17 #include "sync/test/engine/test_directory_setter_upper.h" |
| 19 #include "sync/test/fake_extensions_activity_monitor.h" | 18 #include "sync/test/fake_extensions_activity_monitor.h" |
| 20 #include "testing/gmock/include/gmock/gmock.h" | 19 #include "testing/gmock/include/gmock/gmock.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 22 | 21 |
| 23 using base::TimeDelta; | 22 using base::TimeDelta; |
| 24 using base::TimeTicks; | 23 using base::TimeTicks; |
| 25 using testing::_; | 24 using testing::_; |
| 26 using testing::AtLeast; | 25 using testing::AtLeast; |
| 27 using testing::DoAll; | 26 using testing::DoAll; |
| 28 using testing::Eq; | 27 using testing::Eq; |
| 29 using testing::Invoke; | 28 using testing::Invoke; |
| 30 using testing::Mock; | 29 using testing::Mock; |
| 31 using testing::Not; | |
| 32 using testing::Return; | 30 using testing::Return; |
| 33 using testing::WithArg; | 31 using testing::WithArg; |
| 34 | 32 |
| 35 namespace syncer { | 33 namespace syncer { |
| 36 using sessions::SyncSession; | 34 using sessions::SyncSession; |
| 37 using sessions::SyncSessionContext; | 35 using sessions::SyncSessionContext; |
| 38 using sessions::SyncSessionSnapshot; | 36 using sessions::SyncSessionSnapshot; |
| 39 using sync_pb::GetUpdatesCallerInfo; | 37 using sync_pb::GetUpdatesCallerInfo; |
| 40 | 38 |
| 41 class MockSyncer : public Syncer { | 39 class MockSyncer : public Syncer { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 63 } | 61 } |
| 64 | 62 |
| 65 void PumpLoop() { | 63 void PumpLoop() { |
| 66 // Do it this way instead of RunAllPending to pump loop exactly once | 64 // Do it this way instead of RunAllPending to pump loop exactly once |
| 67 // (necessary in the presence of timers; see comment in | 65 // (necessary in the presence of timers; see comment in |
| 68 // QuitLoopNow). | 66 // QuitLoopNow). |
| 69 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(&QuitLoopNow)); | 67 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(&QuitLoopNow)); |
| 70 RunLoop(); | 68 RunLoop(); |
| 71 } | 69 } |
| 72 | 70 |
| 73 ModelSafeRoutingInfo TypesToRoutingInfo(const ModelTypeSet& types) { | |
| 74 ModelSafeRoutingInfo routes; | |
| 75 for (ModelTypeSet::Iterator iter = types.First(); iter.Good(); iter.Inc()) { | |
| 76 routes[iter.Get()] = GROUP_PASSIVE; | |
| 77 } | |
| 78 return routes; | |
| 79 } | |
| 80 | |
| 81 // Convenient to use in tests wishing to analyze SyncShare calls over time. | 71 // Convenient to use in tests wishing to analyze SyncShare calls over time. |
| 82 static const size_t kMinNumSamples = 5; | 72 static const size_t kMinNumSamples = 5; |
| 83 class SyncSchedulerTest : public testing::Test { | 73 class SyncSchedulerTest : public testing::Test { |
| 84 public: | 74 public: |
| 85 SyncSchedulerTest() | 75 SyncSchedulerTest() |
| 86 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 76 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 87 context_(NULL), | 77 context_(NULL), |
| 88 syncer_(NULL), | 78 syncer_(NULL), |
| 89 delay_(NULL) {} | 79 delay_(NULL) {} |
| 90 | 80 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 EXPECT_EQ(GetUpdatesCallerInfo::PERIODIC, | 144 EXPECT_EQ(GetUpdatesCallerInfo::PERIODIC, |
| 155 records.snapshots[i].source().updates_source); | 145 records.snapshots[i].source().updates_source); |
| 156 } | 146 } |
| 157 } | 147 } |
| 158 | 148 |
| 159 void DoQuitLoopNow() { | 149 void DoQuitLoopNow() { |
| 160 QuitLoopNow(); | 150 QuitLoopNow(); |
| 161 } | 151 } |
| 162 | 152 |
| 163 void StartSyncScheduler(SyncScheduler::Mode mode) { | 153 void StartSyncScheduler(SyncScheduler::Mode mode) { |
| 164 scheduler()->Start(mode); | 154 scheduler()->Start(mode, base::Closure()); |
| 165 } | 155 } |
| 166 | 156 |
| 167 // This stops the scheduler synchronously. | 157 // This stops the scheduler synchronously. |
| 168 void StopSyncScheduler() { | 158 void StopSyncScheduler() { |
| 169 scheduler()->RequestStop(base::Bind(&SyncSchedulerTest::DoQuitLoopNow, | 159 scheduler()->RequestStop(base::Bind(&SyncSchedulerTest::DoQuitLoopNow, |
| 170 weak_ptr_factory_.GetWeakPtr())); | 160 weak_ptr_factory_.GetWeakPtr())); |
| 171 RunLoop(); | 161 RunLoop(); |
| 172 } | 162 } |
| 173 | 163 |
| 174 bool RunAndGetBackoff() { | 164 bool RunAndGetBackoff() { |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, | 283 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, |
| 294 records2.snapshots[0].source().updates_source); | 284 records2.snapshots[0].source().updates_source); |
| 295 } | 285 } |
| 296 | 286 |
| 297 // Make sure a regular config command is scheduled fine in the absence of any | 287 // Make sure a regular config command is scheduled fine in the absence of any |
| 298 // errors. | 288 // errors. |
| 299 TEST_F(SyncSchedulerTest, Config) { | 289 TEST_F(SyncSchedulerTest, Config) { |
| 300 SyncShareRecords records; | 290 SyncShareRecords records; |
| 301 const ModelTypeSet model_types(syncer::BOOKMARKS); | 291 const ModelTypeSet model_types(syncer::BOOKMARKS); |
| 302 | 292 |
| 303 EXPECT_CALL(*syncer(), | 293 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 304 SyncShare(_,_,_)) | |
| 305 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)) | |
| 306 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 294 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 307 WithArg<0>(RecordSyncShare(&records)))); | 295 WithArg<0>(RecordSyncShare(&records)))); |
| 308 | 296 |
| 309 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 297 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
| 310 | 298 |
| 311 CallbackCounter counter; | 299 scheduler()->ScheduleConfiguration( |
| 312 ConfigurationParams params( | 300 model_types, GetUpdatesCallerInfo::RECONFIGURATION); |
| 313 GetUpdatesCallerInfo::RECONFIGURATION, | |
| 314 model_types, | |
| 315 TypesToRoutingInfo(model_types), | |
| 316 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY, | |
| 317 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); | |
| 318 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params)); | |
| 319 ASSERT_EQ(1, counter.times_called()); | |
| 320 | 301 |
| 321 ASSERT_EQ(1U, records.snapshots.size()); | 302 ASSERT_EQ(1U, records.snapshots.size()); |
| 322 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types, | 303 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types, |
| 323 records.snapshots[0].source().types)); | 304 records.snapshots[0].source().types)); |
| 324 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, | 305 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, |
| 325 records.snapshots[0].source().updates_source); | 306 records.snapshots[0].source().updates_source); |
| 326 } | 307 } |
| 327 | 308 |
| 328 // Simulate a failure and make sure the config request is retried. | 309 // Simulate a failure and make sure the config request is retried. |
| 329 TEST_F(SyncSchedulerTest, ConfigWithBackingOff) { | 310 TEST_F(SyncSchedulerTest, ConfigWithBackingOff) { |
| 330 UseMockDelayProvider(); | 311 UseMockDelayProvider(); |
| 331 EXPECT_CALL(*delay(), GetDelay(_)) | 312 EXPECT_CALL(*delay(), GetDelay(_)) |
| 332 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(1))); | 313 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(1))); |
| 333 SyncShareRecords records; | 314 SyncShareRecords records; |
| 334 const ModelTypeSet model_types(syncer::BOOKMARKS); | 315 const ModelTypeSet model_types(syncer::BOOKMARKS); |
| 335 | 316 |
| 336 EXPECT_CALL(*syncer(), | 317 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 337 SyncShare(_,_,_)) | |
| 338 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)) | |
| 339 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), | 318 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), |
| 340 WithArg<0>(RecordSyncShare(&records)))) | 319 WithArg<0>(RecordSyncShare(&records)))) |
| 341 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 320 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 342 WithArg<0>(RecordSyncShare(&records)))); | 321 WithArg<0>(RecordSyncShare(&records)))); |
| 343 | 322 |
| 344 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 323 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
| 345 | 324 |
| 346 ASSERT_EQ(0U, records.snapshots.size()); | 325 ASSERT_EQ(0U, records.snapshots.size()); |
| 347 CallbackCounter counter; | 326 scheduler()->ScheduleConfiguration( |
| 348 ConfigurationParams params( | 327 model_types, GetUpdatesCallerInfo::RECONFIGURATION); |
| 349 GetUpdatesCallerInfo::RECONFIGURATION, | |
| 350 model_types, | |
| 351 TypesToRoutingInfo(model_types), | |
| 352 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY, | |
| 353 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); | |
| 354 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params)); | |
| 355 ASSERT_EQ(0, counter.times_called()); | |
| 356 | 328 |
| 357 ASSERT_EQ(1U, records.snapshots.size()); | 329 ASSERT_EQ(1U, records.snapshots.size()); |
| 358 RunLoop(); | 330 RunLoop(); |
| 359 | 331 |
| 360 ASSERT_EQ(2U, records.snapshots.size()); | 332 ASSERT_EQ(2U, records.snapshots.size()); |
| 361 ASSERT_EQ(1, counter.times_called()); | |
| 362 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types, | 333 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types, |
| 363 records.snapshots[1].source().types)); | 334 records.snapshots[1].source().types)); |
| 364 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, | 335 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, |
| 365 records.snapshots[1].source().updates_source); | 336 records.snapshots[1].source().updates_source); |
| 366 } | 337 } |
| 367 | 338 |
| 339 // Issue 2 config commands. Second one right after the first has failed |
| 340 // and make sure LATEST is executed. |
| 341 TEST_F(SyncSchedulerTest, MultipleConfigWithBackingOff) { |
| 342 const ModelTypeSet |
| 343 model_types1(syncer::BOOKMARKS), |
| 344 model_types2(syncer::AUTOFILL); |
| 345 UseMockDelayProvider(); |
| 346 EXPECT_CALL(*delay(), GetDelay(_)) |
| 347 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(30))); |
| 348 SyncShareRecords records; |
| 349 |
| 350 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 351 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), |
| 352 WithArg<0>(RecordSyncShare(&records)))) |
| 353 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), |
| 354 WithArg<0>(RecordSyncShare(&records)))) |
| 355 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 356 WithArg<0>(RecordSyncShare(&records)))); |
| 357 |
| 358 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
| 359 |
| 360 ASSERT_EQ(0U, records.snapshots.size()); |
| 361 scheduler()->ScheduleConfiguration( |
| 362 model_types1, GetUpdatesCallerInfo::RECONFIGURATION); |
| 363 |
| 364 ASSERT_EQ(1U, records.snapshots.size()); |
| 365 scheduler()->ScheduleConfiguration( |
| 366 model_types2, GetUpdatesCallerInfo::RECONFIGURATION); |
| 367 |
| 368 // A canary job gets posted when we go into exponential backoff. |
| 369 RunLoop(); |
| 370 |
| 371 ASSERT_EQ(2U, records.snapshots.size()); |
| 372 RunLoop(); |
| 373 |
| 374 ASSERT_EQ(3U, records.snapshots.size()); |
| 375 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types2, |
| 376 records.snapshots[2].source().types)); |
| 377 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, |
| 378 records.snapshots[2].source().updates_source); |
| 379 } |
| 380 |
| 368 // Issue a nudge when the config has failed. Make sure both the config and | 381 // Issue a nudge when the config has failed. Make sure both the config and |
| 369 // nudge are executed. | 382 // nudge are executed. |
| 370 TEST_F(SyncSchedulerTest, NudgeWithConfigWithBackingOff) { | 383 TEST_F(SyncSchedulerTest, NudgeWithConfigWithBackingOff) { |
| 371 const ModelTypeSet model_types(syncer::BOOKMARKS); | 384 const ModelTypeSet model_types(syncer::BOOKMARKS); |
| 372 UseMockDelayProvider(); | 385 UseMockDelayProvider(); |
| 373 EXPECT_CALL(*delay(), GetDelay(_)) | 386 EXPECT_CALL(*delay(), GetDelay(_)) |
| 374 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(50))); | 387 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(50))); |
| 375 SyncShareRecords records; | 388 SyncShareRecords records; |
| 376 | 389 |
| 377 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 390 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 378 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), | 391 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), |
| 379 WithArg<0>(RecordSyncShare(&records)))) | 392 WithArg<0>(RecordSyncShare(&records)))) |
| 380 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), | 393 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), |
| 381 WithArg<0>(RecordSyncShare(&records)))) | 394 WithArg<0>(RecordSyncShare(&records)))) |
| 382 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 395 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 383 WithArg<0>(RecordSyncShare(&records)))) | 396 WithArg<0>(RecordSyncShare(&records)))) |
| 384 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 397 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 385 WithArg<0>(RecordSyncShare(&records)))); | 398 WithArg<0>(RecordSyncShare(&records)))); |
| 386 | 399 |
| 387 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 400 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
| 388 | 401 |
| 389 ASSERT_EQ(0U, records.snapshots.size()); | 402 ASSERT_EQ(0U, records.snapshots.size()); |
| 390 CallbackCounter counter; | 403 scheduler()->ScheduleConfiguration( |
| 391 ConfigurationParams params( | 404 model_types, GetUpdatesCallerInfo::RECONFIGURATION); |
| 392 GetUpdatesCallerInfo::RECONFIGURATION, | 405 |
| 393 model_types, | |
| 394 TypesToRoutingInfo(model_types), | |
| 395 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY, | |
| 396 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); | |
| 397 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params)); | |
| 398 ASSERT_EQ(0, counter.times_called()); | |
| 399 ASSERT_EQ(1U, records.snapshots.size()); | 406 ASSERT_EQ(1U, records.snapshots.size()); |
| 400 | |
| 401 scheduler()->ScheduleNudgeAsync( | 407 scheduler()->ScheduleNudgeAsync( |
| 402 zero(), NUDGE_SOURCE_LOCAL, model_types, FROM_HERE); | 408 zero(), NUDGE_SOURCE_LOCAL, model_types, FROM_HERE); |
| 403 RunLoop(); | 409 RunLoop(); |
| 410 |
| 404 ASSERT_EQ(2U, records.snapshots.size()); | 411 ASSERT_EQ(2U, records.snapshots.size()); |
| 405 ASSERT_EQ(0, counter.times_called()); | |
| 406 | |
| 407 RunLoop(); | 412 RunLoop(); |
| 408 ASSERT_EQ(3U, records.snapshots.size()); | |
| 409 ASSERT_EQ(1, counter.times_called()); | |
| 410 | 413 |
| 411 // Now change the mode so nudge can execute. | 414 // Now change the mode so nudge can execute. |
| 415 ASSERT_EQ(3U, records.snapshots.size()); |
| 412 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 416 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
| 413 | 417 |
| 414 ASSERT_EQ(4U, records.snapshots.size()); | 418 ASSERT_EQ(4U, records.snapshots.size()); |
| 415 | 419 |
| 416 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types, | 420 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types, |
| 417 records.snapshots[2].source().types)); | 421 records.snapshots[2].source().types)); |
| 418 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, | 422 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, |
| 419 records.snapshots[2].source().updates_source); | 423 records.snapshots[2].source().updates_source); |
| 420 | 424 |
| 421 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types, | 425 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types, |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 706 QuitLoopNowAction())); | 710 QuitLoopNowAction())); |
| 707 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 711 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
| 708 | 712 |
| 709 scheduler()->ScheduleNudgeAsync( | 713 scheduler()->ScheduleNudgeAsync( |
| 710 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(), FROM_HERE); | 714 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(), FROM_HERE); |
| 711 | 715 |
| 712 // We should detect the failure on the second sync share, and go into backoff. | 716 // We should detect the failure on the second sync share, and go into backoff. |
| 713 EXPECT_TRUE(RunAndGetBackoff()); | 717 EXPECT_TRUE(RunAndGetBackoff()); |
| 714 } | 718 } |
| 715 | 719 |
| 716 // Test that no syncing occurs when throttled (although CleanupDisabledTypes | 720 // Test that no syncing occurs when throttled. |
| 717 // is allowed). | |
| 718 TEST_F(SyncSchedulerTest, ThrottlingDoesThrottle) { | 721 TEST_F(SyncSchedulerTest, ThrottlingDoesThrottle) { |
| 719 const ModelTypeSet types(syncer::BOOKMARKS); | 722 const ModelTypeSet types(syncer::BOOKMARKS); |
| 720 TimeDelta poll(TimeDelta::FromMilliseconds(5)); | 723 TimeDelta poll(TimeDelta::FromMilliseconds(5)); |
| 721 TimeDelta throttle(TimeDelta::FromMinutes(10)); | 724 TimeDelta throttle(TimeDelta::FromMinutes(10)); |
| 722 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 725 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
| 723 | 726 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 724 EXPECT_CALL(*syncer(), | |
| 725 SyncShare(_, CLEANUP_DISABLED_TYPES, CLEANUP_DISABLED_TYPES)) | |
| 726 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)); | |
| 727 EXPECT_CALL(*syncer(), SyncShare(_,Not(CLEANUP_DISABLED_TYPES), | |
| 728 Not(CLEANUP_DISABLED_TYPES))) | |
| 729 .WillOnce(WithArg<0>(sessions::test_util::SimulateThrottled(throttle))) | 727 .WillOnce(WithArg<0>(sessions::test_util::SimulateThrottled(throttle))) |
| 730 .WillRepeatedly(AddFailureAndQuitLoopNow()); | 728 .WillRepeatedly(AddFailureAndQuitLoopNow()); |
| 731 | 729 |
| 732 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 730 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
| 733 | 731 |
| 734 scheduler()->ScheduleNudgeAsync( | 732 scheduler()->ScheduleNudgeAsync( |
| 735 zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE); | 733 zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE); |
| 736 PumpLoop(); | 734 PumpLoop(); |
| 737 | 735 |
| 738 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 736 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
| 739 | 737 |
| 740 CallbackCounter counter; | 738 scheduler()->ScheduleConfiguration( |
| 741 ConfigurationParams params( | 739 types, GetUpdatesCallerInfo::RECONFIGURATION); |
| 742 GetUpdatesCallerInfo::RECONFIGURATION, | |
| 743 types, | |
| 744 TypesToRoutingInfo(types), | |
| 745 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY, | |
| 746 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); | |
| 747 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params)); | |
| 748 ASSERT_EQ(0, counter.times_called()); | |
| 749 } | 740 } |
| 750 | 741 |
| 751 TEST_F(SyncSchedulerTest, ThrottlingExpires) { | 742 TEST_F(SyncSchedulerTest, ThrottlingExpires) { |
| 752 SyncShareRecords records; | 743 SyncShareRecords records; |
| 753 TimeDelta poll(TimeDelta::FromMilliseconds(15)); | 744 TimeDelta poll(TimeDelta::FromMilliseconds(15)); |
| 754 TimeDelta throttle1(TimeDelta::FromMilliseconds(150)); | 745 TimeDelta throttle1(TimeDelta::FromMilliseconds(150)); |
| 755 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 746 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
| 756 | 747 |
| 757 ::testing::InSequence seq; | 748 ::testing::InSequence seq; |
| 758 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 749 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 771 StopSyncScheduler(); | 762 StopSyncScheduler(); |
| 772 AnalyzePollRun(records, kMinNumSamples, optimal_start, poll); | 763 AnalyzePollRun(records, kMinNumSamples, optimal_start, poll); |
| 773 } | 764 } |
| 774 | 765 |
| 775 // Test nudges / polls don't run in config mode and config tasks do. | 766 // Test nudges / polls don't run in config mode and config tasks do. |
| 776 TEST_F(SyncSchedulerTest, ConfigurationMode) { | 767 TEST_F(SyncSchedulerTest, ConfigurationMode) { |
| 777 TimeDelta poll(TimeDelta::FromMilliseconds(15)); | 768 TimeDelta poll(TimeDelta::FromMilliseconds(15)); |
| 778 SyncShareRecords records; | 769 SyncShareRecords records; |
| 779 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 770 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
| 780 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 771 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 781 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)) | |
| 782 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 772 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 783 WithArg<0>(RecordSyncShare(&records)))); | 773 WithArg<0>(RecordSyncShare(&records)))); |
| 784 | 774 |
| 785 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 775 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
| 786 | 776 |
| 787 const ModelTypeSet nudge_types(syncer::AUTOFILL); | 777 const ModelTypeSet nudge_types(syncer::AUTOFILL); |
| 788 scheduler()->ScheduleNudgeAsync( | 778 scheduler()->ScheduleNudgeAsync( |
| 789 zero(), NUDGE_SOURCE_LOCAL, nudge_types, FROM_HERE); | 779 zero(), NUDGE_SOURCE_LOCAL, nudge_types, FROM_HERE); |
| 790 scheduler()->ScheduleNudgeAsync( | 780 scheduler()->ScheduleNudgeAsync( |
| 791 zero(), NUDGE_SOURCE_LOCAL, nudge_types, FROM_HERE); | 781 zero(), NUDGE_SOURCE_LOCAL, nudge_types, FROM_HERE); |
| 792 | 782 |
| 793 const ModelTypeSet config_types(syncer::BOOKMARKS); | 783 const ModelTypeSet config_types(syncer::BOOKMARKS); |
| 794 | 784 |
| 795 CallbackCounter counter; | 785 scheduler()->ScheduleConfiguration( |
| 796 ConfigurationParams params( | 786 config_types, GetUpdatesCallerInfo::RECONFIGURATION); |
| 797 GetUpdatesCallerInfo::RECONFIGURATION, | |
| 798 config_types, | |
| 799 TypesToRoutingInfo(config_types), | |
| 800 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY, | |
| 801 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); | |
| 802 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params)); | |
| 803 ASSERT_EQ(1, counter.times_called()); | |
| 804 | 787 |
| 805 ASSERT_EQ(1U, records.snapshots.size()); | 788 ASSERT_EQ(1U, records.snapshots.size()); |
| 806 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(config_types, | 789 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(config_types, |
| 807 records.snapshots[0].source().types)); | 790 records.snapshots[0].source().types)); |
| 808 } | 791 } |
| 809 | 792 |
| 810 class BackoffTriggersSyncSchedulerTest : public SyncSchedulerTest { | 793 class BackoffTriggersSyncSchedulerTest : public SyncSchedulerTest { |
| 811 void SetUp() { | 794 void SetUp() { |
| 812 SyncSchedulerTest::SetUp(); | 795 SyncSchedulerTest::SetUp(); |
| 813 UseMockDelayProvider(); | 796 UseMockDelayProvider(); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 862 } | 845 } |
| 863 | 846 |
| 864 // Test that no polls or extraneous nudges occur when in backoff. | 847 // Test that no polls or extraneous nudges occur when in backoff. |
| 865 TEST_F(SyncSchedulerTest, BackoffDropsJobs) { | 848 TEST_F(SyncSchedulerTest, BackoffDropsJobs) { |
| 866 SyncShareRecords r; | 849 SyncShareRecords r; |
| 867 TimeDelta poll(TimeDelta::FromMilliseconds(5)); | 850 TimeDelta poll(TimeDelta::FromMilliseconds(5)); |
| 868 const ModelTypeSet types(syncer::BOOKMARKS); | 851 const ModelTypeSet types(syncer::BOOKMARKS); |
| 869 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 852 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
| 870 UseMockDelayProvider(); | 853 UseMockDelayProvider(); |
| 871 | 854 |
| 872 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 855 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(1) |
| 873 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), | 856 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), |
| 874 RecordSyncShareMultiple(&r, 1U))); | 857 RecordSyncShareMultiple(&r, 1U))); |
| 875 EXPECT_CALL(*delay(), GetDelay(_)). | 858 EXPECT_CALL(*delay(), GetDelay(_)). |
| 876 WillRepeatedly(Return(TimeDelta::FromDays(1))); | 859 WillRepeatedly(Return(TimeDelta::FromDays(1))); |
| 877 | 860 |
| 878 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 861 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
| 879 | 862 |
| 880 // This nudge should fail and put us into backoff. Thanks to our mock | 863 // This nudge should fail and put us into backoff. Thanks to our mock |
| 881 // GetDelay() setup above, this will be a long backoff. | 864 // GetDelay() setup above, this will be a long backoff. |
| 882 scheduler()->ScheduleNudgeAsync(zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE); | 865 scheduler()->ScheduleNudgeAsync(zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 904 r.snapshots[1].source().updates_source); | 887 r.snapshots[1].source().updates_source); |
| 905 | 888 |
| 906 // Cleanup is not affected by backoff, but it should not relieve it either. | 889 // Cleanup is not affected by backoff, but it should not relieve it either. |
| 907 EXPECT_CALL(*syncer(), | 890 EXPECT_CALL(*syncer(), |
| 908 SyncShare(_, CLEANUP_DISABLED_TYPES, CLEANUP_DISABLED_TYPES)) | 891 SyncShare(_, CLEANUP_DISABLED_TYPES, CLEANUP_DISABLED_TYPES)) |
| 909 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)); | 892 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)); |
| 910 EXPECT_CALL(*delay(), GetDelay(_)).Times(0); | 893 EXPECT_CALL(*delay(), GetDelay(_)).Times(0); |
| 911 | 894 |
| 912 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 895 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
| 913 | 896 |
| 914 CallbackCounter counter; | 897 scheduler()->CleanupDisabledTypes(); |
| 915 ConfigurationParams params( | 898 scheduler()->ScheduleConfiguration( |
| 916 GetUpdatesCallerInfo::RECONFIGURATION, | 899 types, GetUpdatesCallerInfo::RECONFIGURATION); |
| 917 types, | |
| 918 TypesToRoutingInfo(types), | |
| 919 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY, | |
| 920 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); | |
| 921 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params)); | |
| 922 ASSERT_EQ(0, counter.times_called()); | |
| 923 | 900 |
| 924 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 901 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
| 925 | 902 |
| 926 scheduler()->ScheduleNudgeAsync( | 903 scheduler()->ScheduleNudgeAsync( |
| 927 zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE); | 904 zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE); |
| 928 scheduler()->ScheduleNudgeAsync( | 905 scheduler()->ScheduleNudgeAsync( |
| 929 zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE); | 906 zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE); |
| 930 PumpLoop(); | 907 PumpLoop(); |
| 931 } | 908 } |
| 932 | 909 |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1071 | 1048 |
| 1072 scheduler()->ScheduleNudgeAsync( | 1049 scheduler()->ScheduleNudgeAsync( |
| 1073 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(), FROM_HERE); | 1050 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(), FROM_HERE); |
| 1074 PumpLoop(); | 1051 PumpLoop(); |
| 1075 // Pump again to run job. | 1052 // Pump again to run job. |
| 1076 PumpLoop(); | 1053 PumpLoop(); |
| 1077 | 1054 |
| 1078 StopSyncScheduler(); | 1055 StopSyncScheduler(); |
| 1079 Mock::VerifyAndClearExpectations(syncer()); | 1056 Mock::VerifyAndClearExpectations(syncer()); |
| 1080 | 1057 |
| 1081 // Configuration (always includes a cleanup disabled types). | |
| 1082 EXPECT_CALL(*syncer(), | |
| 1083 SyncShare(_, CLEANUP_DISABLED_TYPES, CLEANUP_DISABLED_TYPES)) | |
| 1084 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)); | |
| 1085 EXPECT_CALL(*syncer(), SyncShare(_, DOWNLOAD_UPDATES, APPLY_UPDATES)) | 1058 EXPECT_CALL(*syncer(), SyncShare(_, DOWNLOAD_UPDATES, APPLY_UPDATES)) |
| 1086 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)); | 1059 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)); |
| 1087 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 1060 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
| 1088 | 1061 |
| 1089 syncer::ModelTypeSet model_types(syncer::BOOKMARKS); | 1062 scheduler()->ScheduleConfiguration( |
| 1090 CallbackCounter counter; | 1063 ModelTypeSet(), GetUpdatesCallerInfo::RECONFIGURATION); |
| 1091 ConfigurationParams params( | 1064 |
| 1092 GetUpdatesCallerInfo::RECONFIGURATION, | |
| 1093 model_types, | |
| 1094 TypesToRoutingInfo(model_types), | |
| 1095 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY, | |
| 1096 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); | |
| 1097 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params)); | |
| 1098 ASSERT_EQ(1, counter.times_called()); | |
| 1099 // Runs directly so no need to pump the loop. | |
| 1100 StopSyncScheduler(); | 1065 StopSyncScheduler(); |
| 1101 Mock::VerifyAndClearExpectations(syncer()); | 1066 Mock::VerifyAndClearExpectations(syncer()); |
| 1102 | 1067 |
| 1103 // Cleanup disabled types. Because no types are being configured, we just | 1068 // Cleanup disabled types. |
| 1104 // perform the cleanup. | |
| 1105 EXPECT_CALL(*syncer(), | 1069 EXPECT_CALL(*syncer(), |
| 1106 SyncShare(_, CLEANUP_DISABLED_TYPES, CLEANUP_DISABLED_TYPES)). | 1070 SyncShare(_, CLEANUP_DISABLED_TYPES, CLEANUP_DISABLED_TYPES)) |
| 1107 WillOnce(Invoke(sessions::test_util::SimulateSuccess)); | 1071 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)); |
| 1108 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 1072 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
| 1109 | 1073 |
| 1110 CallbackCounter counter2; | 1074 scheduler()->CleanupDisabledTypes(); |
| 1111 ConfigurationParams params2( | 1075 |
| 1112 GetUpdatesCallerInfo::RECONFIGURATION, | |
| 1113 ModelTypeSet(), | |
| 1114 ModelSafeRoutingInfo(), | |
| 1115 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY, | |
| 1116 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter2))); | |
| 1117 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params2)); | |
| 1118 ASSERT_EQ(1, counter2.times_called()); | |
| 1119 StopSyncScheduler(); | 1076 StopSyncScheduler(); |
| 1120 Mock::VerifyAndClearExpectations(syncer()); | 1077 Mock::VerifyAndClearExpectations(syncer()); |
| 1121 | 1078 |
| 1122 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | |
| 1123 | |
| 1124 // Poll. | 1079 // Poll. |
| 1125 EXPECT_CALL(*syncer(), SyncShare(_, SYNCER_BEGIN, SYNCER_END)) | 1080 EXPECT_CALL(*syncer(), SyncShare(_, SYNCER_BEGIN, SYNCER_END)) |
| 1126 .Times(AtLeast(1)) | 1081 .Times(AtLeast(1)) |
| 1127 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 1082 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 1128 QuitLoopNowAction())); | 1083 QuitLoopNowAction())); |
| 1129 const TimeDelta poll(TimeDelta::FromMilliseconds(10)); | 1084 const TimeDelta poll(TimeDelta::FromMilliseconds(10)); |
| 1130 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 1085 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
| 1131 | 1086 |
| 1132 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 1087 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
| 1133 | 1088 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1178 PumpLoop(); | 1133 PumpLoop(); |
| 1179 // Pump again to run job. | 1134 // Pump again to run job. |
| 1180 PumpLoop(); | 1135 PumpLoop(); |
| 1181 | 1136 |
| 1182 StopSyncScheduler(); | 1137 StopSyncScheduler(); |
| 1183 | 1138 |
| 1184 EXPECT_TRUE(expected == context()->previous_session_routing_info()); | 1139 EXPECT_TRUE(expected == context()->previous_session_routing_info()); |
| 1185 } | 1140 } |
| 1186 | 1141 |
| 1187 } // namespace syncer | 1142 } // namespace syncer |
| OLD | NEW |