| 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 "components/sync/engine_impl/sync_scheduler_impl.h" | 5 #include "components/sync/engine_impl/sync_scheduler_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 RunLoop(); | 82 RunLoop(); |
| 83 } | 83 } |
| 84 | 84 |
| 85 void PumpLoopFor(base::TimeDelta time) { | 85 void PumpLoopFor(base::TimeDelta time) { |
| 86 // Allow the loop to run for the specified amount of time. | 86 // Allow the loop to run for the specified amount of time. |
| 87 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 87 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 88 FROM_HERE, base::Bind(&QuitLoopNow), time); | 88 FROM_HERE, base::Bind(&QuitLoopNow), time); |
| 89 RunLoop(); | 89 RunLoop(); |
| 90 } | 90 } |
| 91 | 91 |
| 92 ModelSafeRoutingInfo TypesToRoutingInfo(ModelTypeSet types) { | |
| 93 ModelSafeRoutingInfo routes; | |
| 94 for (ModelTypeSet::Iterator iter = types.First(); iter.Good(); iter.Inc()) { | |
| 95 routes[iter.Get()] = GROUP_PASSIVE; | |
| 96 } | |
| 97 return routes; | |
| 98 } | |
| 99 | |
| 100 static const size_t kMinNumSamples = 5; | 92 static const size_t kMinNumSamples = 5; |
| 101 | 93 |
| 102 // Test harness for the SyncScheduler. Test the delays and backoff timers used | 94 // Test harness for the SyncScheduler. Test the delays and backoff timers used |
| 103 // in response to various events. | 95 // in response to various events. |
| 104 // | 96 // |
| 105 // These tests execute in real time with real timers. We try to keep the | 97 // These tests execute in real time with real timers. We try to keep the |
| 106 // delays short, but there is a limit to how short we can make them. The | 98 // delays short, but there is a limit to how short we can make them. The |
| 107 // timers on some platforms (ie. Windows) have a timer resolution greater than | 99 // timers on some platforms (ie. Windows) have a timer resolution greater than |
| 108 // 1ms. Using 1ms delays may result in test flakiness. | 100 // 1ms. Using 1ms delays may result in test flakiness. |
| 109 // | 101 // |
| (...skipping 12 matching lines...) Expand all Loading... |
| 122 | 114 |
| 123 MOCK_METHOD1(GetDelay, TimeDelta(const TimeDelta&)); | 115 MOCK_METHOD1(GetDelay, TimeDelta(const TimeDelta&)); |
| 124 }; | 116 }; |
| 125 | 117 |
| 126 void SetUp() override { | 118 void SetUp() override { |
| 127 test_user_share_.SetUp(); | 119 test_user_share_.SetUp(); |
| 128 syncer_ = new testing::StrictMock<MockSyncer>(); | 120 syncer_ = new testing::StrictMock<MockSyncer>(); |
| 129 delay_ = nullptr; | 121 delay_ = nullptr; |
| 130 extensions_activity_ = new ExtensionsActivity(); | 122 extensions_activity_ = new ExtensionsActivity(); |
| 131 | 123 |
| 132 routing_info_[THEMES] = GROUP_UI; | |
| 133 routing_info_[TYPED_URLS] = GROUP_DB; | |
| 134 routing_info_[THEMES] = GROUP_UI; | |
| 135 routing_info_[NIGORI] = GROUP_PASSIVE; | |
| 136 | |
| 137 workers_.clear(); | 124 workers_.clear(); |
| 138 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_UI))); | 125 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_UI))); |
| 139 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_DB))); | 126 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_DB))); |
| 140 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_PASSIVE))); | 127 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_PASSIVE))); |
| 141 | 128 |
| 142 connection_ = base::MakeUnique<MockConnectionManager>(directory(), | 129 connection_ = base::MakeUnique<MockConnectionManager>(directory(), |
| 143 &cancelation_signal_); | 130 &cancelation_signal_); |
| 144 connection_->SetServerReachable(); | 131 connection_->SetServerReachable(); |
| 145 | 132 |
| 146 model_type_registry_ = base::MakeUnique<ModelTypeRegistry>( | 133 model_type_registry_ = base::MakeUnique<ModelTypeRegistry>( |
| 147 workers_, test_user_share_.user_share(), &mock_nudge_handler_, | 134 workers_, test_user_share_.user_share(), &mock_nudge_handler_, |
| 148 UssMigrator()); | 135 UssMigrator()); |
| 136 model_type_registry_->RegisterDirectoryType(NIGORI, GROUP_PASSIVE); |
| 137 model_type_registry_->RegisterDirectoryType(THEMES, GROUP_UI); |
| 138 model_type_registry_->RegisterDirectoryType(TYPED_URLS, GROUP_DB); |
| 149 | 139 |
| 150 context_ = base::MakeUnique<SyncCycleContext>( | 140 context_ = base::MakeUnique<SyncCycleContext>( |
| 151 connection_.get(), directory(), extensions_activity_.get(), | 141 connection_.get(), directory(), extensions_activity_.get(), |
| 152 std::vector<SyncEngineEventListener*>(), nullptr, | 142 std::vector<SyncEngineEventListener*>(), nullptr, |
| 153 model_type_registry_.get(), | 143 model_type_registry_.get(), |
| 154 true, // enable keystore encryption | 144 true, // enable keystore encryption |
| 155 false, // force enable pre-commit GU avoidance | 145 false, // force enable pre-commit GU avoidance |
| 156 "fake_invalidator_client_id"); | 146 "fake_invalidator_client_id"); |
| 157 context_->SetRoutingInfo(routing_info_); | |
| 158 context_->set_notifications_enabled(true); | 147 context_->set_notifications_enabled(true); |
| 159 context_->set_account_name("Test"); | 148 context_->set_account_name("Test"); |
| 160 scheduler_ = base::MakeUnique<SyncSchedulerImpl>( | 149 scheduler_ = base::MakeUnique<SyncSchedulerImpl>( |
| 161 "TestSyncScheduler", BackoffDelayProvider::FromDefaults(), context(), | 150 "TestSyncScheduler", BackoffDelayProvider::FromDefaults(), context(), |
| 162 syncer_, false); | 151 syncer_, false); |
| 163 scheduler_->SetDefaultNudgeDelay(default_delay()); | 152 scheduler_->SetDefaultNudgeDelay(default_delay()); |
| 164 } | 153 } |
| 165 | 154 |
| 166 SyncSchedulerImpl* scheduler() { return scheduler_.get(); } | 155 SyncSchedulerImpl* scheduler() { return scheduler_.get(); } |
| 167 const ModelSafeRoutingInfo& routing_info() { return routing_info_; } | |
| 168 MockSyncer* syncer() { return syncer_; } | 156 MockSyncer* syncer() { return syncer_; } |
| 169 MockDelayProvider* delay() { return delay_; } | 157 MockDelayProvider* delay() { return delay_; } |
| 170 MockConnectionManager* connection() { return connection_.get(); } | 158 MockConnectionManager* connection() { return connection_.get(); } |
| 171 TimeDelta default_delay() { return TimeDelta::FromSeconds(0); } | 159 TimeDelta default_delay() { return TimeDelta::FromSeconds(0); } |
| 172 TimeDelta long_delay() { return TimeDelta::FromSeconds(60); } | 160 TimeDelta long_delay() { return TimeDelta::FromSeconds(60); } |
| 173 TimeDelta timeout() { return TestTimeouts::action_timeout(); } | 161 TimeDelta timeout() { return TestTimeouts::action_timeout(); } |
| 174 | 162 |
| 175 void TearDown() override { | 163 void TearDown() override { |
| 176 PumpLoop(); | 164 PumpLoop(); |
| 177 scheduler_.reset(); | 165 scheduler_.reset(); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 CancelationSignal cancelation_signal_; | 290 CancelationSignal cancelation_signal_; |
| 303 std::unique_ptr<MockConnectionManager> connection_; | 291 std::unique_ptr<MockConnectionManager> connection_; |
| 304 std::unique_ptr<ModelTypeRegistry> model_type_registry_; | 292 std::unique_ptr<ModelTypeRegistry> model_type_registry_; |
| 305 std::unique_ptr<SyncCycleContext> context_; | 293 std::unique_ptr<SyncCycleContext> context_; |
| 306 std::unique_ptr<SyncSchedulerImpl> scheduler_; | 294 std::unique_ptr<SyncSchedulerImpl> scheduler_; |
| 307 MockNudgeHandler mock_nudge_handler_; | 295 MockNudgeHandler mock_nudge_handler_; |
| 308 MockSyncer* syncer_; | 296 MockSyncer* syncer_; |
| 309 MockDelayProvider* delay_; | 297 MockDelayProvider* delay_; |
| 310 std::vector<scoped_refptr<ModelSafeWorker>> workers_; | 298 std::vector<scoped_refptr<ModelSafeWorker>> workers_; |
| 311 scoped_refptr<ExtensionsActivity> extensions_activity_; | 299 scoped_refptr<ExtensionsActivity> extensions_activity_; |
| 312 ModelSafeRoutingInfo routing_info_; | |
| 313 base::WeakPtrFactory<SyncSchedulerImplTest> weak_ptr_factory_; | 300 base::WeakPtrFactory<SyncSchedulerImplTest> weak_ptr_factory_; |
| 314 }; | 301 }; |
| 315 | 302 |
| 316 void RecordSyncShareImpl(SyncShareTimes* times) { | 303 void RecordSyncShareImpl(SyncShareTimes* times) { |
| 317 times->push_back(TimeTicks::Now()); | 304 times->push_back(TimeTicks::Now()); |
| 318 } | 305 } |
| 319 | 306 |
| 320 ACTION_P2(RecordSyncShare, times, success) { | 307 ACTION_P2(RecordSyncShare, times, success) { |
| 321 RecordSyncShareImpl(times); | 308 RecordSyncShareImpl(times); |
| 322 if (base::MessageLoop::current()->is_running()) | 309 if (base::MessageLoop::current()->is_running()) |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) | 373 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) |
| 387 .WillOnce(DoAll(Invoke(test_util::SimulateConfigureSuccess), | 374 .WillOnce(DoAll(Invoke(test_util::SimulateConfigureSuccess), |
| 388 RecordSyncShare(×, true))); | 375 RecordSyncShare(×, true))); |
| 389 | 376 |
| 390 StartSyncConfiguration(); | 377 StartSyncConfiguration(); |
| 391 | 378 |
| 392 CallbackCounter ready_counter; | 379 CallbackCounter ready_counter; |
| 393 CallbackCounter retry_counter; | 380 CallbackCounter retry_counter; |
| 394 ConfigurationParams params( | 381 ConfigurationParams params( |
| 395 GetUpdatesCallerInfo::RECONFIGURATION, model_types, | 382 GetUpdatesCallerInfo::RECONFIGURATION, model_types, |
| 396 TypesToRoutingInfo(model_types), | |
| 397 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), | 383 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), |
| 398 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); | 384 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); |
| 399 scheduler()->ScheduleConfiguration(params); | 385 scheduler()->ScheduleConfiguration(params); |
| 400 PumpLoop(); | 386 PumpLoop(); |
| 401 ASSERT_EQ(1, ready_counter.times_called()); | 387 ASSERT_EQ(1, ready_counter.times_called()); |
| 402 ASSERT_EQ(0, retry_counter.times_called()); | 388 ASSERT_EQ(0, retry_counter.times_called()); |
| 403 } | 389 } |
| 404 | 390 |
| 405 // Simulate a failure and make sure the config request is retried. | 391 // Simulate a failure and make sure the config request is retried. |
| 406 TEST_F(SyncSchedulerImplTest, ConfigWithBackingOff) { | 392 TEST_F(SyncSchedulerImplTest, ConfigWithBackingOff) { |
| 407 UseMockDelayProvider(); | 393 UseMockDelayProvider(); |
| 408 EXPECT_CALL(*delay(), GetDelay(_)) | 394 EXPECT_CALL(*delay(), GetDelay(_)) |
| 409 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(20))); | 395 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(20))); |
| 410 SyncShareTimes times; | 396 SyncShareTimes times; |
| 411 const ModelTypeSet model_types(THEMES); | 397 const ModelTypeSet model_types(THEMES); |
| 412 | 398 |
| 413 StartSyncConfiguration(); | 399 StartSyncConfiguration(); |
| 414 | 400 |
| 415 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) | 401 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) |
| 416 .WillOnce(DoAll(Invoke(test_util::SimulateConfigureFailed), | 402 .WillOnce(DoAll(Invoke(test_util::SimulateConfigureFailed), |
| 417 RecordSyncShare(×, false))) | 403 RecordSyncShare(×, false))) |
| 418 .WillOnce(DoAll(Invoke(test_util::SimulateConfigureFailed), | 404 .WillOnce(DoAll(Invoke(test_util::SimulateConfigureFailed), |
| 419 RecordSyncShare(×, false))); | 405 RecordSyncShare(×, false))); |
| 420 | 406 |
| 421 CallbackCounter ready_counter; | 407 CallbackCounter ready_counter; |
| 422 CallbackCounter retry_counter; | 408 CallbackCounter retry_counter; |
| 423 ConfigurationParams params( | 409 ConfigurationParams params( |
| 424 GetUpdatesCallerInfo::RECONFIGURATION, model_types, | 410 GetUpdatesCallerInfo::RECONFIGURATION, model_types, |
| 425 TypesToRoutingInfo(model_types), | |
| 426 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), | 411 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), |
| 427 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); | 412 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); |
| 428 scheduler()->ScheduleConfiguration(params); | 413 scheduler()->ScheduleConfiguration(params); |
| 429 RunLoop(); | 414 RunLoop(); |
| 430 ASSERT_EQ(0, ready_counter.times_called()); | 415 ASSERT_EQ(0, ready_counter.times_called()); |
| 431 ASSERT_EQ(1, retry_counter.times_called()); | 416 ASSERT_EQ(1, retry_counter.times_called()); |
| 432 | 417 |
| 433 // RunLoop() will trigger TryCanaryJob which will retry configuration. | 418 // RunLoop() will trigger TryCanaryJob which will retry configuration. |
| 434 // Since retry_task was already called it shouldn't be called again. | 419 // Since retry_task was already called it shouldn't be called again. |
| 435 RunLoop(); | 420 RunLoop(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 461 // retry_task or dereference configuration params. | 446 // retry_task or dereference configuration params. |
| 462 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) | 447 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) |
| 463 .WillOnce(DoAll(Invoke(test_util::SimulateConfigureFailed), | 448 .WillOnce(DoAll(Invoke(test_util::SimulateConfigureFailed), |
| 464 StopScheduler(scheduler()), | 449 StopScheduler(scheduler()), |
| 465 RecordSyncShare(×, false))); | 450 RecordSyncShare(×, false))); |
| 466 | 451 |
| 467 CallbackCounter ready_counter; | 452 CallbackCounter ready_counter; |
| 468 CallbackCounter retry_counter; | 453 CallbackCounter retry_counter; |
| 469 ConfigurationParams params( | 454 ConfigurationParams params( |
| 470 GetUpdatesCallerInfo::RECONFIGURATION, model_types, | 455 GetUpdatesCallerInfo::RECONFIGURATION, model_types, |
| 471 TypesToRoutingInfo(model_types), | |
| 472 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), | 456 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), |
| 473 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); | 457 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); |
| 474 scheduler()->ScheduleConfiguration(params); | 458 scheduler()->ScheduleConfiguration(params); |
| 475 PumpLoop(); | 459 PumpLoop(); |
| 476 ASSERT_EQ(0, ready_counter.times_called()); | 460 ASSERT_EQ(0, ready_counter.times_called()); |
| 477 ASSERT_EQ(0, retry_counter.times_called()); | 461 ASSERT_EQ(0, retry_counter.times_called()); |
| 478 } | 462 } |
| 479 | 463 |
| 480 // Verify that in the absence of valid auth token the command will fail. | 464 // Verify that in the absence of valid auth token the command will fail. |
| 481 TEST_F(SyncSchedulerImplTest, ConfigNoAuthToken) { | 465 TEST_F(SyncSchedulerImplTest, ConfigNoAuthToken) { |
| 482 SyncShareTimes times; | 466 SyncShareTimes times; |
| 483 const ModelTypeSet model_types(THEMES); | 467 const ModelTypeSet model_types(THEMES); |
| 484 | 468 |
| 485 connection()->ResetAuthToken(); | 469 connection()->ResetAuthToken(); |
| 486 | 470 |
| 487 StartSyncConfiguration(); | 471 StartSyncConfiguration(); |
| 488 | 472 |
| 489 CallbackCounter ready_counter; | 473 CallbackCounter ready_counter; |
| 490 CallbackCounter retry_counter; | 474 CallbackCounter retry_counter; |
| 491 ConfigurationParams params( | 475 ConfigurationParams params( |
| 492 GetUpdatesCallerInfo::RECONFIGURATION, model_types, | 476 GetUpdatesCallerInfo::RECONFIGURATION, model_types, |
| 493 TypesToRoutingInfo(model_types), | |
| 494 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), | 477 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), |
| 495 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); | 478 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); |
| 496 scheduler()->ScheduleConfiguration(params); | 479 scheduler()->ScheduleConfiguration(params); |
| 497 PumpLoop(); | 480 PumpLoop(); |
| 498 ASSERT_EQ(0, ready_counter.times_called()); | 481 ASSERT_EQ(0, ready_counter.times_called()); |
| 499 ASSERT_EQ(1, retry_counter.times_called()); | 482 ASSERT_EQ(1, retry_counter.times_called()); |
| 500 } | 483 } |
| 501 | 484 |
| 502 // Verify that in the absence of valid auth token the command will pass if local | 485 // Verify that in the absence of valid auth token the command will pass if local |
| 503 // sync backend is used. | 486 // sync backend is used. |
| 504 TEST_F(SyncSchedulerImplTest, ConfigNoAuthTokenLocalSync) { | 487 TEST_F(SyncSchedulerImplTest, ConfigNoAuthTokenLocalSync) { |
| 505 SyncShareTimes times; | 488 SyncShareTimes times; |
| 506 const ModelTypeSet model_types(THEMES); | 489 const ModelTypeSet model_types(THEMES); |
| 507 | 490 |
| 508 NewSchedulerForLocalBackend(); | 491 NewSchedulerForLocalBackend(); |
| 509 connection()->ResetAuthToken(); | 492 connection()->ResetAuthToken(); |
| 510 | 493 |
| 511 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) | 494 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) |
| 512 .WillOnce(DoAll(Invoke(test_util::SimulateConfigureSuccess), | 495 .WillOnce(DoAll(Invoke(test_util::SimulateConfigureSuccess), |
| 513 RecordSyncShare(×, true))); | 496 RecordSyncShare(×, true))); |
| 514 | 497 |
| 515 StartSyncConfiguration(); | 498 StartSyncConfiguration(); |
| 516 | 499 |
| 517 CallbackCounter ready_counter; | 500 CallbackCounter ready_counter; |
| 518 CallbackCounter retry_counter; | 501 CallbackCounter retry_counter; |
| 519 ConfigurationParams params( | 502 ConfigurationParams params( |
| 520 GetUpdatesCallerInfo::RECONFIGURATION, model_types, | 503 GetUpdatesCallerInfo::RECONFIGURATION, model_types, |
| 521 TypesToRoutingInfo(model_types), | |
| 522 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), | 504 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), |
| 523 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); | 505 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); |
| 524 scheduler()->ScheduleConfiguration(params); | 506 scheduler()->ScheduleConfiguration(params); |
| 525 PumpLoop(); | 507 PumpLoop(); |
| 526 ASSERT_EQ(1, ready_counter.times_called()); | 508 ASSERT_EQ(1, ready_counter.times_called()); |
| 527 ASSERT_EQ(0, retry_counter.times_called()); | 509 ASSERT_EQ(0, retry_counter.times_called()); |
| 528 } | 510 } |
| 529 | 511 |
| 530 // Issue a nudge when the config has failed. Make sure both the config and | 512 // Issue a nudge when the config has failed. Make sure both the config and |
| 531 // nudge are executed. | 513 // nudge are executed. |
| 532 TEST_F(SyncSchedulerImplTest, NudgeWithConfigWithBackingOff) { | 514 TEST_F(SyncSchedulerImplTest, NudgeWithConfigWithBackingOff) { |
| 533 const ModelTypeSet model_types(THEMES); | 515 const ModelTypeSet model_types(THEMES); |
| 534 UseMockDelayProvider(); | 516 UseMockDelayProvider(); |
| 535 EXPECT_CALL(*delay(), GetDelay(_)) | 517 EXPECT_CALL(*delay(), GetDelay(_)) |
| 536 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(50))); | 518 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(50))); |
| 537 SyncShareTimes times; | 519 SyncShareTimes times; |
| 538 | 520 |
| 539 StartSyncConfiguration(); | 521 StartSyncConfiguration(); |
| 540 | 522 |
| 541 // Request a configure and make sure it fails. | 523 // Request a configure and make sure it fails. |
| 542 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) | 524 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) |
| 543 .WillOnce(DoAll(Invoke(test_util::SimulateConfigureFailed), | 525 .WillOnce(DoAll(Invoke(test_util::SimulateConfigureFailed), |
| 544 RecordSyncShare(×, false))); | 526 RecordSyncShare(×, false))); |
| 545 CallbackCounter ready_counter; | 527 CallbackCounter ready_counter; |
| 546 CallbackCounter retry_counter; | 528 CallbackCounter retry_counter; |
| 547 ConfigurationParams params( | 529 ConfigurationParams params( |
| 548 GetUpdatesCallerInfo::RECONFIGURATION, model_types, | 530 GetUpdatesCallerInfo::RECONFIGURATION, model_types, |
| 549 TypesToRoutingInfo(model_types), | |
| 550 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), | 531 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), |
| 551 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); | 532 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); |
| 552 scheduler()->ScheduleConfiguration(params); | 533 scheduler()->ScheduleConfiguration(params); |
| 553 RunLoop(); | 534 RunLoop(); |
| 554 ASSERT_EQ(0, ready_counter.times_called()); | 535 ASSERT_EQ(0, ready_counter.times_called()); |
| 555 ASSERT_EQ(1, retry_counter.times_called()); | 536 ASSERT_EQ(1, retry_counter.times_called()); |
| 556 Mock::VerifyAndClearExpectations(syncer()); | 537 Mock::VerifyAndClearExpectations(syncer()); |
| 557 | 538 |
| 558 // Ask for a nudge while dealing with repeated configure failure. | 539 // Ask for a nudge while dealing with repeated configure failure. |
| 559 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) | 540 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) |
| (...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 StartSyncScheduler(base::Time()); | 781 StartSyncScheduler(base::Time()); |
| 801 | 782 |
| 802 scheduler()->ScheduleLocalNudge(types, FROM_HERE); | 783 scheduler()->ScheduleLocalNudge(types, FROM_HERE); |
| 803 PumpLoop(); | 784 PumpLoop(); |
| 804 | 785 |
| 805 StartSyncConfiguration(); | 786 StartSyncConfiguration(); |
| 806 | 787 |
| 807 CallbackCounter ready_counter; | 788 CallbackCounter ready_counter; |
| 808 CallbackCounter retry_counter; | 789 CallbackCounter retry_counter; |
| 809 ConfigurationParams params( | 790 ConfigurationParams params( |
| 810 GetUpdatesCallerInfo::RECONFIGURATION, types, TypesToRoutingInfo(types), | 791 GetUpdatesCallerInfo::RECONFIGURATION, types, |
| 811 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), | 792 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), |
| 812 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); | 793 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); |
| 813 scheduler()->ScheduleConfiguration(params); | 794 scheduler()->ScheduleConfiguration(params); |
| 814 PumpLoop(); | 795 PumpLoop(); |
| 815 ASSERT_EQ(0, ready_counter.times_called()); | 796 ASSERT_EQ(0, ready_counter.times_called()); |
| 816 ASSERT_EQ(1, retry_counter.times_called()); | 797 ASSERT_EQ(1, retry_counter.times_called()); |
| 817 } | 798 } |
| 818 | 799 |
| 819 TEST_F(SyncSchedulerImplTest, ThrottlingExpiresFromPoll) { | 800 TEST_F(SyncSchedulerImplTest, ThrottlingExpiresFromPoll) { |
| 820 SyncShareTimes times; | 801 SyncShareTimes times; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 884 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) | 865 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) |
| 885 .WillOnce(DoAll(Invoke(test_util::SimulateConfigureSuccess), | 866 .WillOnce(DoAll(Invoke(test_util::SimulateConfigureSuccess), |
| 886 QuitLoopNowAction(true))); | 867 QuitLoopNowAction(true))); |
| 887 | 868 |
| 888 const ModelTypeSet types(THEMES); | 869 const ModelTypeSet types(THEMES); |
| 889 StartSyncConfiguration(); | 870 StartSyncConfiguration(); |
| 890 | 871 |
| 891 CallbackCounter ready_counter; | 872 CallbackCounter ready_counter; |
| 892 CallbackCounter retry_counter; | 873 CallbackCounter retry_counter; |
| 893 ConfigurationParams params( | 874 ConfigurationParams params( |
| 894 GetUpdatesCallerInfo::RECONFIGURATION, types, TypesToRoutingInfo(types), | 875 GetUpdatesCallerInfo::RECONFIGURATION, types, |
| 895 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), | 876 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), |
| 896 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); | 877 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); |
| 897 scheduler()->ScheduleConfiguration(params); | 878 scheduler()->ScheduleConfiguration(params); |
| 898 PumpLoop(); | 879 PumpLoop(); |
| 899 EXPECT_EQ(0, ready_counter.times_called()); | 880 EXPECT_EQ(0, ready_counter.times_called()); |
| 900 EXPECT_EQ(1, retry_counter.times_called()); | 881 EXPECT_EQ(1, retry_counter.times_called()); |
| 901 EXPECT_TRUE(scheduler()->IsCurrentlyThrottled()); | 882 EXPECT_TRUE(scheduler()->IsCurrentlyThrottled()); |
| 902 | 883 |
| 903 RunLoop(); | 884 RunLoop(); |
| 904 EXPECT_FALSE(scheduler()->IsCurrentlyThrottled()); | 885 EXPECT_FALSE(scheduler()->IsCurrentlyThrottled()); |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1205 const ModelTypeSet config_types(THEMES); | 1186 const ModelTypeSet config_types(THEMES); |
| 1206 | 1187 |
| 1207 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) | 1188 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) |
| 1208 .WillOnce(DoAll(Invoke(test_util::SimulateConfigureSuccess), | 1189 .WillOnce(DoAll(Invoke(test_util::SimulateConfigureSuccess), |
| 1209 RecordSyncShare(×, true))) | 1190 RecordSyncShare(×, true))) |
| 1210 .RetiresOnSaturation(); | 1191 .RetiresOnSaturation(); |
| 1211 CallbackCounter ready_counter; | 1192 CallbackCounter ready_counter; |
| 1212 CallbackCounter retry_counter; | 1193 CallbackCounter retry_counter; |
| 1213 ConfigurationParams params( | 1194 ConfigurationParams params( |
| 1214 GetUpdatesCallerInfo::RECONFIGURATION, config_types, | 1195 GetUpdatesCallerInfo::RECONFIGURATION, config_types, |
| 1215 TypesToRoutingInfo(config_types), | |
| 1216 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), | 1196 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), |
| 1217 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); | 1197 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); |
| 1218 scheduler()->ScheduleConfiguration(params); | 1198 scheduler()->ScheduleConfiguration(params); |
| 1219 RunLoop(); | 1199 RunLoop(); |
| 1220 ASSERT_EQ(1, ready_counter.times_called()); | 1200 ASSERT_EQ(1, ready_counter.times_called()); |
| 1221 ASSERT_EQ(0, retry_counter.times_called()); | 1201 ASSERT_EQ(0, retry_counter.times_called()); |
| 1222 | 1202 |
| 1223 Mock::VerifyAndClearExpectations(syncer()); | 1203 Mock::VerifyAndClearExpectations(syncer()); |
| 1224 | 1204 |
| 1225 // Switch to NORMAL_MODE to ensure NUDGES were properly saved and run. | 1205 // Switch to NORMAL_MODE to ensure NUDGES were properly saved and run. |
| 1226 scheduler()->OnReceivedLongPollIntervalUpdate(TimeDelta::FromDays(1)); | 1206 scheduler()->OnReceivedLongPollIntervalUpdate(TimeDelta::FromDays(1)); |
| 1227 SyncShareTimes times2; | 1207 SyncShareTimes times2; |
| 1228 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 1208 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 1229 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), | 1209 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), |
| 1230 RecordSyncShare(×2, true))); | 1210 RecordSyncShare(×2, true))); |
| 1231 | 1211 |
| 1232 // TODO(tim): Figure out how to remove this dangerous need to reset | |
| 1233 // routing info between mode switches. | |
| 1234 context()->SetRoutingInfo(routing_info()); | |
| 1235 StartSyncScheduler(base::Time()); | 1212 StartSyncScheduler(base::Time()); |
| 1236 | 1213 |
| 1237 RunLoop(); | 1214 RunLoop(); |
| 1238 Mock::VerifyAndClearExpectations(syncer()); | 1215 Mock::VerifyAndClearExpectations(syncer()); |
| 1239 } | 1216 } |
| 1240 | 1217 |
| 1241 class BackoffTriggersSyncSchedulerImplTest : public SyncSchedulerImplTest { | 1218 class BackoffTriggersSyncSchedulerImplTest : public SyncSchedulerImplTest { |
| 1242 void SetUp() override { | 1219 void SetUp() override { |
| 1243 SyncSchedulerImplTest::SetUp(); | 1220 SyncSchedulerImplTest::SetUp(); |
| 1244 UseMockDelayProvider(); | 1221 UseMockDelayProvider(); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1300 .WillOnce(DoAll(Invoke(test_util::SimulateGetEncryptionKeyFailed), | 1277 .WillOnce(DoAll(Invoke(test_util::SimulateGetEncryptionKeyFailed), |
| 1301 Return(false))) | 1278 Return(false))) |
| 1302 .WillRepeatedly(DoAll(Invoke(test_util::SimulateGetEncryptionKeyFailed), | 1279 .WillRepeatedly(DoAll(Invoke(test_util::SimulateGetEncryptionKeyFailed), |
| 1303 QuitLoopNowAction(false))); | 1280 QuitLoopNowAction(false))); |
| 1304 StartSyncConfiguration(); | 1281 StartSyncConfiguration(); |
| 1305 | 1282 |
| 1306 ModelTypeSet types(THEMES); | 1283 ModelTypeSet types(THEMES); |
| 1307 CallbackCounter ready_counter; | 1284 CallbackCounter ready_counter; |
| 1308 CallbackCounter retry_counter; | 1285 CallbackCounter retry_counter; |
| 1309 ConfigurationParams params( | 1286 ConfigurationParams params( |
| 1310 GetUpdatesCallerInfo::RECONFIGURATION, types, TypesToRoutingInfo(types), | 1287 GetUpdatesCallerInfo::RECONFIGURATION, types, |
| 1311 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), | 1288 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), |
| 1312 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); | 1289 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); |
| 1313 scheduler()->ScheduleConfiguration(params); | 1290 scheduler()->ScheduleConfiguration(params); |
| 1314 RunLoop(); | 1291 RunLoop(); |
| 1315 | 1292 |
| 1316 EXPECT_TRUE(scheduler()->IsBackingOff()); | 1293 EXPECT_TRUE(scheduler()->IsBackingOff()); |
| 1317 } | 1294 } |
| 1318 | 1295 |
| 1319 // Test that no polls or extraneous nudges occur when in backoff. | 1296 // Test that no polls or extraneous nudges occur when in backoff. |
| 1320 TEST_F(SyncSchedulerImplTest, BackoffDropsJobs) { | 1297 TEST_F(SyncSchedulerImplTest, BackoffDropsJobs) { |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1349 Mock::VerifyAndClearExpectations(syncer()); | 1326 Mock::VerifyAndClearExpectations(syncer()); |
| 1350 Mock::VerifyAndClearExpectations(delay()); | 1327 Mock::VerifyAndClearExpectations(delay()); |
| 1351 | 1328 |
| 1352 EXPECT_CALL(*delay(), GetDelay(_)).Times(0); | 1329 EXPECT_CALL(*delay(), GetDelay(_)).Times(0); |
| 1353 | 1330 |
| 1354 StartSyncConfiguration(); | 1331 StartSyncConfiguration(); |
| 1355 | 1332 |
| 1356 CallbackCounter ready_counter; | 1333 CallbackCounter ready_counter; |
| 1357 CallbackCounter retry_counter; | 1334 CallbackCounter retry_counter; |
| 1358 ConfigurationParams params( | 1335 ConfigurationParams params( |
| 1359 GetUpdatesCallerInfo::RECONFIGURATION, types, TypesToRoutingInfo(types), | 1336 GetUpdatesCallerInfo::RECONFIGURATION, types, |
| 1360 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), | 1337 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), |
| 1361 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); | 1338 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); |
| 1362 scheduler()->ScheduleConfiguration(params); | 1339 scheduler()->ScheduleConfiguration(params); |
| 1363 PumpLoop(); | 1340 PumpLoop(); |
| 1364 ASSERT_EQ(0, ready_counter.times_called()); | 1341 ASSERT_EQ(0, ready_counter.times_called()); |
| 1365 ASSERT_EQ(1, retry_counter.times_called()); | 1342 ASSERT_EQ(1, retry_counter.times_called()); |
| 1366 } | 1343 } |
| 1367 | 1344 |
| 1368 // Test that backoff is shaping traffic properly with consecutive errors. | 1345 // Test that backoff is shaping traffic properly with consecutive errors. |
| 1369 TEST_F(SyncSchedulerImplTest, BackoffElevation) { | 1346 TEST_F(SyncSchedulerImplTest, BackoffElevation) { |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1582 Invoke(test_util::SimulateConfigureConnectionFailure), Return(true))); | 1559 Invoke(test_util::SimulateConfigureConnectionFailure), Return(true))); |
| 1583 StartSyncConfiguration(); | 1560 StartSyncConfiguration(); |
| 1584 connection()->SetServerNotReachable(); | 1561 connection()->SetServerNotReachable(); |
| 1585 connection()->UpdateConnectionStatus(); | 1562 connection()->UpdateConnectionStatus(); |
| 1586 | 1563 |
| 1587 ModelTypeSet model_types(THEMES); | 1564 ModelTypeSet model_types(THEMES); |
| 1588 CallbackCounter ready_counter; | 1565 CallbackCounter ready_counter; |
| 1589 CallbackCounter retry_counter; | 1566 CallbackCounter retry_counter; |
| 1590 ConfigurationParams params( | 1567 ConfigurationParams params( |
| 1591 GetUpdatesCallerInfo::RECONFIGURATION, model_types, | 1568 GetUpdatesCallerInfo::RECONFIGURATION, model_types, |
| 1592 TypesToRoutingInfo(model_types), | |
| 1593 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), | 1569 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), |
| 1594 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); | 1570 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); |
| 1595 scheduler()->ScheduleConfiguration(params); | 1571 scheduler()->ScheduleConfiguration(params); |
| 1596 | 1572 |
| 1597 scheduler()->OnConnectionStatusChange(); | 1573 scheduler()->OnConnectionStatusChange(); |
| 1598 scheduler()->OnConnectionStatusChange(); | 1574 scheduler()->OnConnectionStatusChange(); |
| 1599 | 1575 |
| 1600 PumpLoop(); // Run the nudge, that will fail and schedule a quick retry. | 1576 PumpLoop(); // Run the nudge, that will fail and schedule a quick retry. |
| 1601 } | 1577 } |
| 1602 | 1578 |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1778 | 1754 |
| 1779 // The Exponential backoff should be between previous backoff 1.5 and 2.5 | 1755 // The Exponential backoff should be between previous backoff 1.5 and 2.5 |
| 1780 // times. | 1756 // times. |
| 1781 EXPECT_LE(first_blocking_time * 1.5, second_blocking_time); | 1757 EXPECT_LE(first_blocking_time * 1.5, second_blocking_time); |
| 1782 EXPECT_GE(first_blocking_time * 2.5, second_blocking_time); | 1758 EXPECT_GE(first_blocking_time * 2.5, second_blocking_time); |
| 1783 | 1759 |
| 1784 StopSyncScheduler(); | 1760 StopSyncScheduler(); |
| 1785 } | 1761 } |
| 1786 | 1762 |
| 1787 } // namespace syncer | 1763 } // namespace syncer |
| OLD | NEW |