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