| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/location.h" | 11 #include "base/location.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 15 #include "base/test/test_timeouts.h" | 15 #include "base/test/test_timeouts.h" |
| 16 #include "base/threading/thread_task_runner_handle.h" | 16 #include "base/threading/thread_task_runner_handle.h" |
| 17 #include "components/sync/base/cancelation_signal.h" | 17 #include "components/sync/base/cancelation_signal.h" |
| 18 #include "components/sync/base/extensions_activity.h" | 18 #include "components/sync/base/extensions_activity.h" |
| 19 #include "components/sync/base/model_type_test_util.h" | 19 #include "components/sync/base/model_type_test_util.h" |
| 20 #include "components/sync/engine_impl/backoff_delay_provider.h" | 20 #include "components/sync/engine_impl/backoff_delay_provider.h" |
| 21 #include "components/sync/engine_impl/cycle/test_util.h" |
| 21 #include "components/sync/engine_impl/sync_scheduler_impl.h" | 22 #include "components/sync/engine_impl/sync_scheduler_impl.h" |
| 22 #include "components/sync/engine_impl/syncer.h" | 23 #include "components/sync/engine_impl/syncer.h" |
| 23 #include "components/sync/sessions_impl/test_util.h" | |
| 24 #include "components/sync/test/callback_counter.h" | 24 #include "components/sync/test/callback_counter.h" |
| 25 #include "components/sync/test/engine/fake_model_worker.h" | 25 #include "components/sync/test/engine/fake_model_worker.h" |
| 26 #include "components/sync/test/engine/mock_connection_manager.h" | 26 #include "components/sync/test/engine/mock_connection_manager.h" |
| 27 #include "components/sync/test/engine/mock_nudge_handler.h" | 27 #include "components/sync/test/engine/mock_nudge_handler.h" |
| 28 #include "components/sync/test/engine/test_directory_setter_upper.h" | 28 #include "components/sync/test/engine/test_directory_setter_upper.h" |
| 29 #include "components/sync/test/mock_invalidation.h" | 29 #include "components/sync/test/mock_invalidation.h" |
| 30 #include "testing/gmock/include/gmock/gmock.h" | 30 #include "testing/gmock/include/gmock/gmock.h" |
| 31 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
| 32 | 32 |
| 33 using base::TimeDelta; | 33 using base::TimeDelta; |
| 34 using base::TimeTicks; | 34 using base::TimeTicks; |
| 35 using testing::_; | 35 using testing::_; |
| 36 using testing::AtLeast; | 36 using testing::AtLeast; |
| 37 using testing::DoAll; | 37 using testing::DoAll; |
| 38 using testing::Invoke; | 38 using testing::Invoke; |
| 39 using testing::Mock; | 39 using testing::Mock; |
| 40 using testing::Return; | 40 using testing::Return; |
| 41 using testing::WithArg; | 41 using testing::WithArg; |
| 42 using testing::WithArgs; | 42 using testing::WithArgs; |
| 43 using testing::WithoutArgs; | 43 using testing::WithoutArgs; |
| 44 | 44 |
| 45 namespace syncer { | 45 namespace syncer { |
| 46 using sessions::SyncSession; | 46 |
| 47 using sessions::SyncSessionContext; | |
| 48 using sync_pb::GetUpdatesCallerInfo; | 47 using sync_pb::GetUpdatesCallerInfo; |
| 49 | 48 |
| 50 class MockSyncer : public Syncer { | 49 class MockSyncer : public Syncer { |
| 51 public: | 50 public: |
| 52 MockSyncer(); | 51 MockSyncer(); |
| 53 MOCK_METHOD3(NormalSyncShare, | 52 MOCK_METHOD3(NormalSyncShare, bool(ModelTypeSet, NudgeTracker*, SyncCycle*)); |
| 54 bool(ModelTypeSet, | |
| 55 sessions::NudgeTracker*, | |
| 56 sessions::SyncSession*)); | |
| 57 MOCK_METHOD3(ConfigureSyncShare, | 53 MOCK_METHOD3(ConfigureSyncShare, |
| 58 bool(ModelTypeSet, | 54 bool(ModelTypeSet, |
| 59 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource, | 55 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource, |
| 60 SyncSession*)); | 56 SyncCycle*)); |
| 61 MOCK_METHOD2(PollSyncShare, bool(ModelTypeSet, sessions::SyncSession*)); | 57 MOCK_METHOD2(PollSyncShare, bool(ModelTypeSet, SyncCycle*)); |
| 62 }; | 58 }; |
| 63 | 59 |
| 64 MockSyncer::MockSyncer() : Syncer(NULL) {} | 60 MockSyncer::MockSyncer() : Syncer(NULL) {} |
| 65 | 61 |
| 66 typedef std::vector<TimeTicks> SyncShareTimes; | 62 typedef std::vector<TimeTicks> SyncShareTimes; |
| 67 | 63 |
| 68 void QuitLoopNow() { | 64 void QuitLoopNow() { |
| 69 // We use QuitNow() instead of Quit() as the latter may get stalled | 65 // We use QuitNow() instead of Quit() as the latter may get stalled |
| 70 // indefinitely in the presence of repeated timers with low delays | 66 // indefinitely in the presence of repeated timers with low delays |
| 71 // and a slow test (e.g., ThrottlingDoesThrottle [which has a poll | 67 // and a slow test (e.g., ThrottlingDoesThrottle [which has a poll |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_DB))); | 138 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_DB))); |
| 143 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_PASSIVE))); | 139 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_PASSIVE))); |
| 144 | 140 |
| 145 connection_.reset( | 141 connection_.reset( |
| 146 new MockConnectionManager(directory(), &cancelation_signal_)); | 142 new MockConnectionManager(directory(), &cancelation_signal_)); |
| 147 connection_->SetServerReachable(); | 143 connection_->SetServerReachable(); |
| 148 | 144 |
| 149 model_type_registry_.reset( | 145 model_type_registry_.reset( |
| 150 new ModelTypeRegistry(workers_, directory(), &mock_nudge_handler_)); | 146 new ModelTypeRegistry(workers_, directory(), &mock_nudge_handler_)); |
| 151 | 147 |
| 152 context_.reset(new SyncSessionContext( | 148 context_.reset(new SyncCycleContext( |
| 153 connection_.get(), directory(), extensions_activity_.get(), | 149 connection_.get(), directory(), extensions_activity_.get(), |
| 154 std::vector<SyncEngineEventListener*>(), NULL, | 150 std::vector<SyncEngineEventListener*>(), NULL, |
| 155 model_type_registry_.get(), | 151 model_type_registry_.get(), |
| 156 true, // enable keystore encryption | 152 true, // enable keystore encryption |
| 157 false, // force enable pre-commit GU avoidance | 153 false, // force enable pre-commit GU avoidance |
| 158 "fake_invalidator_client_id")); | 154 "fake_invalidator_client_id")); |
| 159 context_->SetRoutingInfo(routing_info_); | 155 context_->SetRoutingInfo(routing_info_); |
| 160 context_->set_notifications_enabled(true); | 156 context_->set_notifications_enabled(true); |
| 161 context_->set_account_name("Test"); | 157 context_->set_account_name("Test"); |
| 162 scheduler_.reset(new SyncSchedulerImpl("TestSyncScheduler", | 158 scheduler_.reset(new SyncSchedulerImpl("TestSyncScheduler", |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 RunLoop(); | 214 RunLoop(); |
| 219 | 215 |
| 220 return scheduler()->IsBackingOff(); | 216 return scheduler()->IsBackingOff(); |
| 221 } | 217 } |
| 222 | 218 |
| 223 void UseMockDelayProvider() { | 219 void UseMockDelayProvider() { |
| 224 delay_ = new MockDelayProvider(); | 220 delay_ = new MockDelayProvider(); |
| 225 scheduler_->delay_provider_.reset(delay_); | 221 scheduler_->delay_provider_.reset(delay_); |
| 226 } | 222 } |
| 227 | 223 |
| 228 SyncSessionContext* context() { return context_.get(); } | 224 SyncCycleContext* context() { return context_.get(); } |
| 229 | 225 |
| 230 ModelTypeSet GetThrottledTypes() { | 226 ModelTypeSet GetThrottledTypes() { |
| 231 return scheduler_->nudge_tracker_.GetThrottledTypes(); | 227 return scheduler_->nudge_tracker_.GetThrottledTypes(); |
| 232 } | 228 } |
| 233 | 229 |
| 234 base::TimeDelta GetRetryTimerDelay() { | 230 base::TimeDelta GetRetryTimerDelay() { |
| 235 EXPECT_TRUE(scheduler_->retry_timer_.IsRunning()); | 231 EXPECT_TRUE(scheduler_->retry_timer_.IsRunning()); |
| 236 return scheduler_->retry_timer_.GetCurrentDelay(); | 232 return scheduler_->retry_timer_.GetCurrentDelay(); |
| 237 } | 233 } |
| 238 | 234 |
| 239 static std::unique_ptr<InvalidationInterface> BuildInvalidation( | 235 static std::unique_ptr<InvalidationInterface> BuildInvalidation( |
| 240 int64_t version, | 236 int64_t version, |
| 241 const std::string& payload) { | 237 const std::string& payload) { |
| 242 return MockInvalidation::Build(version, payload); | 238 return MockInvalidation::Build(version, payload); |
| 243 } | 239 } |
| 244 | 240 |
| 245 private: | 241 private: |
| 246 syncable::Directory* directory() { return dir_maker_.directory(); } | 242 syncable::Directory* directory() { return dir_maker_.directory(); } |
| 247 | 243 |
| 248 base::MessageLoop loop_; | 244 base::MessageLoop loop_; |
| 249 TestDirectorySetterUpper dir_maker_; | 245 TestDirectorySetterUpper dir_maker_; |
| 250 CancelationSignal cancelation_signal_; | 246 CancelationSignal cancelation_signal_; |
| 251 std::unique_ptr<MockConnectionManager> connection_; | 247 std::unique_ptr<MockConnectionManager> connection_; |
| 252 std::unique_ptr<ModelTypeRegistry> model_type_registry_; | 248 std::unique_ptr<ModelTypeRegistry> model_type_registry_; |
| 253 std::unique_ptr<SyncSessionContext> context_; | 249 std::unique_ptr<SyncCycleContext> context_; |
| 254 std::unique_ptr<SyncSchedulerImpl> scheduler_; | 250 std::unique_ptr<SyncSchedulerImpl> scheduler_; |
| 255 MockNudgeHandler mock_nudge_handler_; | 251 MockNudgeHandler mock_nudge_handler_; |
| 256 MockSyncer* syncer_; | 252 MockSyncer* syncer_; |
| 257 MockDelayProvider* delay_; | 253 MockDelayProvider* delay_; |
| 258 std::vector<scoped_refptr<ModelSafeWorker>> workers_; | 254 std::vector<scoped_refptr<ModelSafeWorker>> workers_; |
| 259 scoped_refptr<ExtensionsActivity> extensions_activity_; | 255 scoped_refptr<ExtensionsActivity> extensions_activity_; |
| 260 ModelSafeRoutingInfo routing_info_; | 256 ModelSafeRoutingInfo routing_info_; |
| 261 base::WeakPtrFactory<SyncSchedulerTest> weak_ptr_factory_; | 257 base::WeakPtrFactory<SyncSchedulerTest> weak_ptr_factory_; |
| 262 }; | 258 }; |
| 263 | 259 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 QuitLoopNow(); | 292 QuitLoopNow(); |
| 297 return success; | 293 return success; |
| 298 } | 294 } |
| 299 | 295 |
| 300 // Test nudge scheduling. | 296 // Test nudge scheduling. |
| 301 TEST_F(SyncSchedulerTest, Nudge) { | 297 TEST_F(SyncSchedulerTest, Nudge) { |
| 302 SyncShareTimes times; | 298 SyncShareTimes times; |
| 303 ModelTypeSet model_types(THEMES); | 299 ModelTypeSet model_types(THEMES); |
| 304 | 300 |
| 305 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 301 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 306 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 302 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), |
| 307 RecordSyncShare(×, true))) | 303 RecordSyncShare(×, true))) |
| 308 .RetiresOnSaturation(); | 304 .RetiresOnSaturation(); |
| 309 | 305 |
| 310 StartSyncScheduler(base::Time()); | 306 StartSyncScheduler(base::Time()); |
| 311 | 307 |
| 312 scheduler()->ScheduleLocalNudge(model_types, FROM_HERE); | 308 scheduler()->ScheduleLocalNudge(model_types, FROM_HERE); |
| 313 RunLoop(); | 309 RunLoop(); |
| 314 | 310 |
| 315 Mock::VerifyAndClearExpectations(syncer()); | 311 Mock::VerifyAndClearExpectations(syncer()); |
| 316 | 312 |
| 317 // Make sure a second, later, nudge is unaffected by first (no coalescing). | 313 // Make sure a second, later, nudge is unaffected by first (no coalescing). |
| 318 SyncShareTimes times2; | 314 SyncShareTimes times2; |
| 319 model_types.Remove(THEMES); | 315 model_types.Remove(THEMES); |
| 320 model_types.Put(TYPED_URLS); | 316 model_types.Put(TYPED_URLS); |
| 321 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 317 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 322 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 318 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), |
| 323 RecordSyncShare(×2, true))); | 319 RecordSyncShare(×2, true))); |
| 324 scheduler()->ScheduleLocalNudge(model_types, FROM_HERE); | 320 scheduler()->ScheduleLocalNudge(model_types, FROM_HERE); |
| 325 RunLoop(); | 321 RunLoop(); |
| 326 } | 322 } |
| 327 | 323 |
| 328 // Make sure a regular config command is scheduled fine in the absence of any | 324 // Make sure a regular config command is scheduled fine in the absence of any |
| 329 // errors. | 325 // errors. |
| 330 TEST_F(SyncSchedulerTest, Config) { | 326 TEST_F(SyncSchedulerTest, Config) { |
| 331 SyncShareTimes times; | 327 SyncShareTimes times; |
| 332 const ModelTypeSet model_types(THEMES); | 328 const ModelTypeSet model_types(THEMES); |
| 333 | 329 |
| 334 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) | 330 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) |
| 335 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess), | 331 .WillOnce(DoAll(Invoke(test_util::SimulateConfigureSuccess), |
| 336 RecordSyncShare(×, true))); | 332 RecordSyncShare(×, true))); |
| 337 | 333 |
| 338 StartSyncConfiguration(); | 334 StartSyncConfiguration(); |
| 339 | 335 |
| 340 CallbackCounter ready_counter; | 336 CallbackCounter ready_counter; |
| 341 CallbackCounter retry_counter; | 337 CallbackCounter retry_counter; |
| 342 ConfigurationParams params( | 338 ConfigurationParams params( |
| 343 GetUpdatesCallerInfo::RECONFIGURATION, model_types, | 339 GetUpdatesCallerInfo::RECONFIGURATION, model_types, |
| 344 TypesToRoutingInfo(model_types), | 340 TypesToRoutingInfo(model_types), |
| 345 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), | 341 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), |
| 346 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); | 342 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); |
| 347 scheduler()->ScheduleConfiguration(params); | 343 scheduler()->ScheduleConfiguration(params); |
| 348 PumpLoop(); | 344 PumpLoop(); |
| 349 ASSERT_EQ(1, ready_counter.times_called()); | 345 ASSERT_EQ(1, ready_counter.times_called()); |
| 350 ASSERT_EQ(0, retry_counter.times_called()); | 346 ASSERT_EQ(0, retry_counter.times_called()); |
| 351 } | 347 } |
| 352 | 348 |
| 353 // Simulate a failure and make sure the config request is retried. | 349 // Simulate a failure and make sure the config request is retried. |
| 354 TEST_F(SyncSchedulerTest, ConfigWithBackingOff) { | 350 TEST_F(SyncSchedulerTest, ConfigWithBackingOff) { |
| 355 UseMockDelayProvider(); | 351 UseMockDelayProvider(); |
| 356 EXPECT_CALL(*delay(), GetDelay(_)) | 352 EXPECT_CALL(*delay(), GetDelay(_)) |
| 357 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(20))); | 353 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(20))); |
| 358 SyncShareTimes times; | 354 SyncShareTimes times; |
| 359 const ModelTypeSet model_types(THEMES); | 355 const ModelTypeSet model_types(THEMES); |
| 360 | 356 |
| 361 StartSyncConfiguration(); | 357 StartSyncConfiguration(); |
| 362 | 358 |
| 363 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) | 359 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) |
| 364 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureFailed), | 360 .WillOnce(DoAll(Invoke(test_util::SimulateConfigureFailed), |
| 365 RecordSyncShare(×, false))) | 361 RecordSyncShare(×, false))) |
| 366 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureFailed), | 362 .WillOnce(DoAll(Invoke(test_util::SimulateConfigureFailed), |
| 367 RecordSyncShare(×, false))); | 363 RecordSyncShare(×, false))); |
| 368 | 364 |
| 369 CallbackCounter ready_counter; | 365 CallbackCounter ready_counter; |
| 370 CallbackCounter retry_counter; | 366 CallbackCounter retry_counter; |
| 371 ConfigurationParams params( | 367 ConfigurationParams params( |
| 372 GetUpdatesCallerInfo::RECONFIGURATION, model_types, | 368 GetUpdatesCallerInfo::RECONFIGURATION, model_types, |
| 373 TypesToRoutingInfo(model_types), | 369 TypesToRoutingInfo(model_types), |
| 374 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), | 370 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), |
| 375 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); | 371 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); |
| 376 scheduler()->ScheduleConfiguration(params); | 372 scheduler()->ScheduleConfiguration(params); |
| 377 RunLoop(); | 373 RunLoop(); |
| 378 ASSERT_EQ(0, ready_counter.times_called()); | 374 ASSERT_EQ(0, ready_counter.times_called()); |
| 379 ASSERT_EQ(1, retry_counter.times_called()); | 375 ASSERT_EQ(1, retry_counter.times_called()); |
| 380 | 376 |
| 381 // RunLoop() will trigger TryCanaryJob which will retry configuration. | 377 // RunLoop() will trigger TryCanaryJob which will retry configuration. |
| 382 // Since retry_task was already called it shouldn't be called again. | 378 // Since retry_task was already called it shouldn't be called again. |
| 383 RunLoop(); | 379 RunLoop(); |
| 384 ASSERT_EQ(0, ready_counter.times_called()); | 380 ASSERT_EQ(0, ready_counter.times_called()); |
| 385 ASSERT_EQ(1, retry_counter.times_called()); | 381 ASSERT_EQ(1, retry_counter.times_called()); |
| 386 | 382 |
| 387 Mock::VerifyAndClearExpectations(syncer()); | 383 Mock::VerifyAndClearExpectations(syncer()); |
| 388 | 384 |
| 389 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) | 385 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) |
| 390 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess), | 386 .WillOnce(DoAll(Invoke(test_util::SimulateConfigureSuccess), |
| 391 RecordSyncShare(×, true))); | 387 RecordSyncShare(×, true))); |
| 392 RunLoop(); | 388 RunLoop(); |
| 393 | 389 |
| 394 ASSERT_EQ(1, ready_counter.times_called()); | 390 ASSERT_EQ(1, ready_counter.times_called()); |
| 395 } | 391 } |
| 396 | 392 |
| 397 // Simuilate SyncSchedulerImpl::Stop being called in the middle of Configure. | 393 // Simuilate SyncSchedulerImpl::Stop being called in the middle of Configure. |
| 398 // This can happen if server returns NOT_MY_BIRTHDAY. | 394 // This can happen if server returns NOT_MY_BIRTHDAY. |
| 399 TEST_F(SyncSchedulerTest, ConfigWithStop) { | 395 TEST_F(SyncSchedulerTest, ConfigWithStop) { |
| 400 UseMockDelayProvider(); | 396 UseMockDelayProvider(); |
| 401 EXPECT_CALL(*delay(), GetDelay(_)) | 397 EXPECT_CALL(*delay(), GetDelay(_)) |
| 402 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(20))); | 398 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(20))); |
| 403 SyncShareTimes times; | 399 SyncShareTimes times; |
| 404 const ModelTypeSet model_types(THEMES); | 400 const ModelTypeSet model_types(THEMES); |
| 405 | 401 |
| 406 StartSyncConfiguration(); | 402 StartSyncConfiguration(); |
| 407 | 403 |
| 408 // Make ConfigureSyncShare call scheduler->Stop(). It is not supposed to call | 404 // Make ConfigureSyncShare call scheduler->Stop(). It is not supposed to call |
| 409 // retry_task or dereference configuration params. | 405 // retry_task or dereference configuration params. |
| 410 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) | 406 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) |
| 411 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureFailed), | 407 .WillOnce(DoAll(Invoke(test_util::SimulateConfigureFailed), |
| 412 StopScheduler(scheduler()), | 408 StopScheduler(scheduler()), |
| 413 RecordSyncShare(×, false))); | 409 RecordSyncShare(×, false))); |
| 414 | 410 |
| 415 CallbackCounter ready_counter; | 411 CallbackCounter ready_counter; |
| 416 CallbackCounter retry_counter; | 412 CallbackCounter retry_counter; |
| 417 ConfigurationParams params( | 413 ConfigurationParams params( |
| 418 GetUpdatesCallerInfo::RECONFIGURATION, model_types, | 414 GetUpdatesCallerInfo::RECONFIGURATION, model_types, |
| 419 TypesToRoutingInfo(model_types), | 415 TypesToRoutingInfo(model_types), |
| 420 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), | 416 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), |
| 421 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); | 417 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); |
| 422 scheduler()->ScheduleConfiguration(params); | 418 scheduler()->ScheduleConfiguration(params); |
| 423 PumpLoop(); | 419 PumpLoop(); |
| 424 ASSERT_EQ(0, ready_counter.times_called()); | 420 ASSERT_EQ(0, ready_counter.times_called()); |
| 425 ASSERT_EQ(0, retry_counter.times_called()); | 421 ASSERT_EQ(0, retry_counter.times_called()); |
| 426 } | 422 } |
| 427 | 423 |
| 428 // Issue a nudge when the config has failed. Make sure both the config and | 424 // Issue a nudge when the config has failed. Make sure both the config and |
| 429 // nudge are executed. | 425 // nudge are executed. |
| 430 TEST_F(SyncSchedulerTest, NudgeWithConfigWithBackingOff) { | 426 TEST_F(SyncSchedulerTest, NudgeWithConfigWithBackingOff) { |
| 431 const ModelTypeSet model_types(THEMES); | 427 const ModelTypeSet model_types(THEMES); |
| 432 UseMockDelayProvider(); | 428 UseMockDelayProvider(); |
| 433 EXPECT_CALL(*delay(), GetDelay(_)) | 429 EXPECT_CALL(*delay(), GetDelay(_)) |
| 434 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(50))); | 430 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(50))); |
| 435 SyncShareTimes times; | 431 SyncShareTimes times; |
| 436 | 432 |
| 437 StartSyncConfiguration(); | 433 StartSyncConfiguration(); |
| 438 | 434 |
| 439 // Request a configure and make sure it fails. | 435 // Request a configure and make sure it fails. |
| 440 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) | 436 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) |
| 441 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureFailed), | 437 .WillOnce(DoAll(Invoke(test_util::SimulateConfigureFailed), |
| 442 RecordSyncShare(×, false))); | 438 RecordSyncShare(×, false))); |
| 443 CallbackCounter ready_counter; | 439 CallbackCounter ready_counter; |
| 444 CallbackCounter retry_counter; | 440 CallbackCounter retry_counter; |
| 445 ConfigurationParams params( | 441 ConfigurationParams params( |
| 446 GetUpdatesCallerInfo::RECONFIGURATION, model_types, | 442 GetUpdatesCallerInfo::RECONFIGURATION, model_types, |
| 447 TypesToRoutingInfo(model_types), | 443 TypesToRoutingInfo(model_types), |
| 448 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), | 444 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), |
| 449 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); | 445 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); |
| 450 scheduler()->ScheduleConfiguration(params); | 446 scheduler()->ScheduleConfiguration(params); |
| 451 RunLoop(); | 447 RunLoop(); |
| 452 ASSERT_EQ(0, ready_counter.times_called()); | 448 ASSERT_EQ(0, ready_counter.times_called()); |
| 453 ASSERT_EQ(1, retry_counter.times_called()); | 449 ASSERT_EQ(1, retry_counter.times_called()); |
| 454 Mock::VerifyAndClearExpectations(syncer()); | 450 Mock::VerifyAndClearExpectations(syncer()); |
| 455 | 451 |
| 456 // Ask for a nudge while dealing with repeated configure failure. | 452 // Ask for a nudge while dealing with repeated configure failure. |
| 457 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) | 453 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) |
| 458 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureFailed), | 454 .WillOnce(DoAll(Invoke(test_util::SimulateConfigureFailed), |
| 459 RecordSyncShare(×, false))); | 455 RecordSyncShare(×, false))); |
| 460 scheduler()->ScheduleLocalNudge(model_types, FROM_HERE); | 456 scheduler()->ScheduleLocalNudge(model_types, FROM_HERE); |
| 461 RunLoop(); | 457 RunLoop(); |
| 462 // Note that we're not RunLoop()ing for the NUDGE we just scheduled, but | 458 // Note that we're not RunLoop()ing for the NUDGE we just scheduled, but |
| 463 // for the first retry attempt from the config job (after | 459 // for the first retry attempt from the config job (after |
| 464 // waiting ~+/- 50ms). | 460 // waiting ~+/- 50ms). |
| 465 Mock::VerifyAndClearExpectations(syncer()); | 461 Mock::VerifyAndClearExpectations(syncer()); |
| 466 ASSERT_EQ(0, ready_counter.times_called()); | 462 ASSERT_EQ(0, ready_counter.times_called()); |
| 467 | 463 |
| 468 // Let the next configure retry succeed. | 464 // Let the next configure retry succeed. |
| 469 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) | 465 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) |
| 470 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess), | 466 .WillOnce(DoAll(Invoke(test_util::SimulateConfigureSuccess), |
| 471 RecordSyncShare(×, true))); | 467 RecordSyncShare(×, true))); |
| 472 RunLoop(); | 468 RunLoop(); |
| 473 | 469 |
| 474 // Now change the mode so nudge can execute. | 470 // Now change the mode so nudge can execute. |
| 475 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 471 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 476 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 472 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), |
| 477 RecordSyncShare(×, true))); | 473 RecordSyncShare(×, true))); |
| 478 StartSyncScheduler(base::Time()); | 474 StartSyncScheduler(base::Time()); |
| 479 PumpLoop(); | 475 PumpLoop(); |
| 480 } | 476 } |
| 481 | 477 |
| 482 // Test that nudges are coalesced. | 478 // Test that nudges are coalesced. |
| 483 TEST_F(SyncSchedulerTest, NudgeCoalescing) { | 479 TEST_F(SyncSchedulerTest, NudgeCoalescing) { |
| 484 StartSyncScheduler(base::Time()); | 480 StartSyncScheduler(base::Time()); |
| 485 | 481 |
| 486 SyncShareTimes times; | 482 SyncShareTimes times; |
| 487 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 483 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 488 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 484 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), |
| 489 RecordSyncShare(×, true))); | 485 RecordSyncShare(×, true))); |
| 490 const ModelTypeSet types1(THEMES), types2(TYPED_URLS), types3(THEMES); | 486 const ModelTypeSet types1(THEMES), types2(TYPED_URLS), types3(THEMES); |
| 491 TimeTicks optimal_time = TimeTicks::Now() + default_delay(); | 487 TimeTicks optimal_time = TimeTicks::Now() + default_delay(); |
| 492 scheduler()->ScheduleLocalNudge(types1, FROM_HERE); | 488 scheduler()->ScheduleLocalNudge(types1, FROM_HERE); |
| 493 scheduler()->ScheduleLocalNudge(types2, FROM_HERE); | 489 scheduler()->ScheduleLocalNudge(types2, FROM_HERE); |
| 494 RunLoop(); | 490 RunLoop(); |
| 495 | 491 |
| 496 ASSERT_EQ(1U, times.size()); | 492 ASSERT_EQ(1U, times.size()); |
| 497 EXPECT_GE(times[0], optimal_time); | 493 EXPECT_GE(times[0], optimal_time); |
| 498 | 494 |
| 499 Mock::VerifyAndClearExpectations(syncer()); | 495 Mock::VerifyAndClearExpectations(syncer()); |
| 500 | 496 |
| 501 SyncShareTimes times2; | 497 SyncShareTimes times2; |
| 502 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 498 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 503 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 499 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), |
| 504 RecordSyncShare(×2, true))); | 500 RecordSyncShare(×2, true))); |
| 505 scheduler()->ScheduleLocalNudge(types3, FROM_HERE); | 501 scheduler()->ScheduleLocalNudge(types3, FROM_HERE); |
| 506 RunLoop(); | 502 RunLoop(); |
| 507 } | 503 } |
| 508 | 504 |
| 509 // Test that nudges are coalesced. | 505 // Test that nudges are coalesced. |
| 510 TEST_F(SyncSchedulerTest, NudgeCoalescingWithDifferentTimings) { | 506 TEST_F(SyncSchedulerTest, NudgeCoalescingWithDifferentTimings) { |
| 511 StartSyncScheduler(base::Time()); | 507 StartSyncScheduler(base::Time()); |
| 512 | 508 |
| 513 SyncShareTimes times; | 509 SyncShareTimes times; |
| 514 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 510 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 515 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 511 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), |
| 516 RecordSyncShare(×, true))); | 512 RecordSyncShare(×, true))); |
| 517 ModelTypeSet types1(THEMES), types2(TYPED_URLS), types3; | 513 ModelTypeSet types1(THEMES), types2(TYPED_URLS), types3; |
| 518 | 514 |
| 519 // Create a huge time delay. | 515 // Create a huge time delay. |
| 520 TimeDelta delay = TimeDelta::FromDays(1); | 516 TimeDelta delay = TimeDelta::FromDays(1); |
| 521 | 517 |
| 522 std::map<ModelType, TimeDelta> delay_map; | 518 std::map<ModelType, TimeDelta> delay_map; |
| 523 delay_map[types1.First().Get()] = delay; | 519 delay_map[types1.First().Get()] = delay; |
| 524 scheduler()->OnReceivedCustomNudgeDelays(delay_map); | 520 scheduler()->OnReceivedCustomNudgeDelays(delay_map); |
| 525 scheduler()->ScheduleLocalNudge(types1, FROM_HERE); | 521 scheduler()->ScheduleLocalNudge(types1, FROM_HERE); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 536 EXPECT_GE(times[0], min_time); | 532 EXPECT_GE(times[0], min_time); |
| 537 EXPECT_LE(times[0], max_time); | 533 EXPECT_LE(times[0], max_time); |
| 538 } | 534 } |
| 539 | 535 |
| 540 // Test nudge scheduling. | 536 // Test nudge scheduling. |
| 541 TEST_F(SyncSchedulerTest, NudgeWithStates) { | 537 TEST_F(SyncSchedulerTest, NudgeWithStates) { |
| 542 StartSyncScheduler(base::Time()); | 538 StartSyncScheduler(base::Time()); |
| 543 | 539 |
| 544 SyncShareTimes times1; | 540 SyncShareTimes times1; |
| 545 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 541 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 546 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 542 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), |
| 547 RecordSyncShare(×1, true))) | 543 RecordSyncShare(×1, true))) |
| 548 .RetiresOnSaturation(); | 544 .RetiresOnSaturation(); |
| 549 scheduler()->ScheduleInvalidationNudge(THEMES, BuildInvalidation(10, "test"), | 545 scheduler()->ScheduleInvalidationNudge(THEMES, BuildInvalidation(10, "test"), |
| 550 FROM_HERE); | 546 FROM_HERE); |
| 551 RunLoop(); | 547 RunLoop(); |
| 552 | 548 |
| 553 Mock::VerifyAndClearExpectations(syncer()); | 549 Mock::VerifyAndClearExpectations(syncer()); |
| 554 | 550 |
| 555 // Make sure a second, later, nudge is unaffected by first (no coalescing). | 551 // Make sure a second, later, nudge is unaffected by first (no coalescing). |
| 556 SyncShareTimes times2; | 552 SyncShareTimes times2; |
| 557 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 553 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 558 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 554 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), |
| 559 RecordSyncShare(×2, true))); | 555 RecordSyncShare(×2, true))); |
| 560 scheduler()->ScheduleInvalidationNudge( | 556 scheduler()->ScheduleInvalidationNudge( |
| 561 TYPED_URLS, BuildInvalidation(10, "test2"), FROM_HERE); | 557 TYPED_URLS, BuildInvalidation(10, "test2"), FROM_HERE); |
| 562 RunLoop(); | 558 RunLoop(); |
| 563 } | 559 } |
| 564 | 560 |
| 565 // Test that polling works as expected. | 561 // Test that polling works as expected. |
| 566 TEST_F(SyncSchedulerTest, Polling) { | 562 TEST_F(SyncSchedulerTest, Polling) { |
| 567 SyncShareTimes times; | 563 SyncShareTimes times; |
| 568 TimeDelta poll_interval(TimeDelta::FromMilliseconds(30)); | 564 TimeDelta poll_interval(TimeDelta::FromMilliseconds(30)); |
| 569 EXPECT_CALL(*syncer(), PollSyncShare(_, _)) | 565 EXPECT_CALL(*syncer(), PollSyncShare(_, _)) |
| 570 .Times(AtLeast(kMinNumSamples)) | 566 .Times(AtLeast(kMinNumSamples)) |
| 571 .WillRepeatedly( | 567 .WillRepeatedly( |
| 572 DoAll(Invoke(sessions::test_util::SimulatePollSuccess), | 568 DoAll(Invoke(test_util::SimulatePollSuccess), |
| 573 RecordSyncShareMultiple(×, kMinNumSamples, true))); | 569 RecordSyncShareMultiple(×, kMinNumSamples, true))); |
| 574 | 570 |
| 575 scheduler()->OnReceivedLongPollIntervalUpdate(poll_interval); | 571 scheduler()->OnReceivedLongPollIntervalUpdate(poll_interval); |
| 576 | 572 |
| 577 TimeTicks optimal_start = TimeTicks::Now() + poll_interval; | 573 TimeTicks optimal_start = TimeTicks::Now() + poll_interval; |
| 578 StartSyncScheduler(base::Time()); | 574 StartSyncScheduler(base::Time()); |
| 579 | 575 |
| 580 // Run again to wait for polling. | 576 // Run again to wait for polling. |
| 581 RunLoop(); | 577 RunLoop(); |
| 582 | 578 |
| 583 StopSyncScheduler(); | 579 StopSyncScheduler(); |
| 584 AnalyzePollRun(times, kMinNumSamples, optimal_start, poll_interval); | 580 AnalyzePollRun(times, kMinNumSamples, optimal_start, poll_interval); |
| 585 } | 581 } |
| 586 | 582 |
| 587 // Test that we reuse the previous poll time on startup, triggering the first | 583 // Test that we reuse the previous poll time on startup, triggering the first |
| 588 // poll based on when the last one happened. Subsequent polls should have the | 584 // poll based on when the last one happened. Subsequent polls should have the |
| 589 // normal delay. | 585 // normal delay. |
| 590 TEST_F(SyncSchedulerTest, PollingPersistence) { | 586 TEST_F(SyncSchedulerTest, PollingPersistence) { |
| 591 SyncShareTimes times; | 587 SyncShareTimes times; |
| 592 // Use a large poll interval that wouldn't normally get hit on its own for | 588 // Use a large poll interval that wouldn't normally get hit on its own for |
| 593 // some time yet. | 589 // some time yet. |
| 594 TimeDelta poll_interval(TimeDelta::FromMilliseconds(500)); | 590 TimeDelta poll_interval(TimeDelta::FromMilliseconds(500)); |
| 595 EXPECT_CALL(*syncer(), PollSyncShare(_, _)) | 591 EXPECT_CALL(*syncer(), PollSyncShare(_, _)) |
| 596 .Times(AtLeast(kMinNumSamples)) | 592 .Times(AtLeast(kMinNumSamples)) |
| 597 .WillRepeatedly( | 593 .WillRepeatedly( |
| 598 DoAll(Invoke(sessions::test_util::SimulatePollSuccess), | 594 DoAll(Invoke(test_util::SimulatePollSuccess), |
| 599 RecordSyncShareMultiple(×, kMinNumSamples, true))); | 595 RecordSyncShareMultiple(×, kMinNumSamples, true))); |
| 600 | 596 |
| 601 scheduler()->OnReceivedLongPollIntervalUpdate(poll_interval); | 597 scheduler()->OnReceivedLongPollIntervalUpdate(poll_interval); |
| 602 | 598 |
| 603 // Set the start time to now, as the poll was overdue. | 599 // Set the start time to now, as the poll was overdue. |
| 604 TimeTicks optimal_start = TimeTicks::Now(); | 600 TimeTicks optimal_start = TimeTicks::Now(); |
| 605 StartSyncScheduler(base::Time::Now() - poll_interval); | 601 StartSyncScheduler(base::Time::Now() - poll_interval); |
| 606 | 602 |
| 607 // Run again to wait for polling. | 603 // Run again to wait for polling. |
| 608 RunLoop(); | 604 RunLoop(); |
| 609 | 605 |
| 610 StopSyncScheduler(); | 606 StopSyncScheduler(); |
| 611 AnalyzePollRun(times, kMinNumSamples, optimal_start, poll_interval); | 607 AnalyzePollRun(times, kMinNumSamples, optimal_start, poll_interval); |
| 612 } | 608 } |
| 613 | 609 |
| 614 // Test that if the persisted poll is in the future, it's ignored (the case | 610 // Test that if the persisted poll is in the future, it's ignored (the case |
| 615 // where the local time has been modified). | 611 // where the local time has been modified). |
| 616 TEST_F(SyncSchedulerTest, PollingPersistenceBadClock) { | 612 TEST_F(SyncSchedulerTest, PollingPersistenceBadClock) { |
| 617 SyncShareTimes times; | 613 SyncShareTimes times; |
| 618 TimeDelta poll_interval(TimeDelta::FromMilliseconds(30)); | 614 TimeDelta poll_interval(TimeDelta::FromMilliseconds(30)); |
| 619 EXPECT_CALL(*syncer(), PollSyncShare(_, _)) | 615 EXPECT_CALL(*syncer(), PollSyncShare(_, _)) |
| 620 .Times(AtLeast(kMinNumSamples)) | 616 .Times(AtLeast(kMinNumSamples)) |
| 621 .WillRepeatedly( | 617 .WillRepeatedly( |
| 622 DoAll(Invoke(sessions::test_util::SimulatePollSuccess), | 618 DoAll(Invoke(test_util::SimulatePollSuccess), |
| 623 RecordSyncShareMultiple(×, kMinNumSamples, true))); | 619 RecordSyncShareMultiple(×, kMinNumSamples, true))); |
| 624 | 620 |
| 625 scheduler()->OnReceivedLongPollIntervalUpdate(poll_interval); | 621 scheduler()->OnReceivedLongPollIntervalUpdate(poll_interval); |
| 626 | 622 |
| 627 // Set the start time to |poll_interval| in the future. | 623 // Set the start time to |poll_interval| in the future. |
| 628 TimeTicks optimal_start = TimeTicks::Now() + poll_interval; | 624 TimeTicks optimal_start = TimeTicks::Now() + poll_interval; |
| 629 StartSyncScheduler(base::Time::Now() + base::TimeDelta::FromMinutes(10)); | 625 StartSyncScheduler(base::Time::Now() + base::TimeDelta::FromMinutes(10)); |
| 630 | 626 |
| 631 // Run again to wait for polling. | 627 // Run again to wait for polling. |
| 632 RunLoop(); | 628 RunLoop(); |
| 633 | 629 |
| 634 StopSyncScheduler(); | 630 StopSyncScheduler(); |
| 635 AnalyzePollRun(times, kMinNumSamples, optimal_start, poll_interval); | 631 AnalyzePollRun(times, kMinNumSamples, optimal_start, poll_interval); |
| 636 } | 632 } |
| 637 | 633 |
| 638 // Test that the short poll interval is used. | 634 // Test that the short poll interval is used. |
| 639 TEST_F(SyncSchedulerTest, PollNotificationsDisabled) { | 635 TEST_F(SyncSchedulerTest, PollNotificationsDisabled) { |
| 640 SyncShareTimes times; | 636 SyncShareTimes times; |
| 641 TimeDelta poll_interval(TimeDelta::FromMilliseconds(30)); | 637 TimeDelta poll_interval(TimeDelta::FromMilliseconds(30)); |
| 642 EXPECT_CALL(*syncer(), PollSyncShare(_, _)) | 638 EXPECT_CALL(*syncer(), PollSyncShare(_, _)) |
| 643 .Times(AtLeast(kMinNumSamples)) | 639 .Times(AtLeast(kMinNumSamples)) |
| 644 .WillRepeatedly( | 640 .WillRepeatedly( |
| 645 DoAll(Invoke(sessions::test_util::SimulatePollSuccess), | 641 DoAll(Invoke(test_util::SimulatePollSuccess), |
| 646 RecordSyncShareMultiple(×, kMinNumSamples, true))); | 642 RecordSyncShareMultiple(×, kMinNumSamples, true))); |
| 647 | 643 |
| 648 scheduler()->OnReceivedShortPollIntervalUpdate(poll_interval); | 644 scheduler()->OnReceivedShortPollIntervalUpdate(poll_interval); |
| 649 scheduler()->SetNotificationsEnabled(false); | 645 scheduler()->SetNotificationsEnabled(false); |
| 650 | 646 |
| 651 TimeTicks optimal_start = TimeTicks::Now() + poll_interval; | 647 TimeTicks optimal_start = TimeTicks::Now() + poll_interval; |
| 652 StartSyncScheduler(base::Time()); | 648 StartSyncScheduler(base::Time()); |
| 653 | 649 |
| 654 // Run again to wait for polling. | 650 // Run again to wait for polling. |
| 655 RunLoop(); | 651 RunLoop(); |
| 656 | 652 |
| 657 StopSyncScheduler(); | 653 StopSyncScheduler(); |
| 658 AnalyzePollRun(times, kMinNumSamples, optimal_start, poll_interval); | 654 AnalyzePollRun(times, kMinNumSamples, optimal_start, poll_interval); |
| 659 } | 655 } |
| 660 | 656 |
| 661 // Test that polling intervals are updated when needed. | 657 // Test that polling intervals are updated when needed. |
| 662 TEST_F(SyncSchedulerTest, PollIntervalUpdate) { | 658 TEST_F(SyncSchedulerTest, PollIntervalUpdate) { |
| 663 SyncShareTimes times; | 659 SyncShareTimes times; |
| 664 TimeDelta poll1(TimeDelta::FromMilliseconds(120)); | 660 TimeDelta poll1(TimeDelta::FromMilliseconds(120)); |
| 665 TimeDelta poll2(TimeDelta::FromMilliseconds(30)); | 661 TimeDelta poll2(TimeDelta::FromMilliseconds(30)); |
| 666 scheduler()->OnReceivedLongPollIntervalUpdate(poll1); | 662 scheduler()->OnReceivedLongPollIntervalUpdate(poll1); |
| 667 EXPECT_CALL(*syncer(), PollSyncShare(_, _)) | 663 EXPECT_CALL(*syncer(), PollSyncShare(_, _)) |
| 668 .Times(AtLeast(kMinNumSamples)) | 664 .Times(AtLeast(kMinNumSamples)) |
| 669 .WillOnce( | 665 .WillOnce( |
| 670 DoAll(WithArgs<0, 1>( | 666 DoAll(WithArgs<0, 1>(test_util::SimulatePollIntervalUpdate(poll2)), |
| 671 sessions::test_util::SimulatePollIntervalUpdate(poll2)), | |
| 672 Return(true))) | 667 Return(true))) |
| 673 .WillRepeatedly(DoAll( | 668 .WillRepeatedly(DoAll( |
| 674 Invoke(sessions::test_util::SimulatePollSuccess), | 669 Invoke(test_util::SimulatePollSuccess), |
| 675 WithArg<1>(RecordSyncShareMultiple(×, kMinNumSamples, true)))); | 670 WithArg<1>(RecordSyncShareMultiple(×, kMinNumSamples, true)))); |
| 676 | 671 |
| 677 TimeTicks optimal_start = TimeTicks::Now() + poll1 + poll2; | 672 TimeTicks optimal_start = TimeTicks::Now() + poll1 + poll2; |
| 678 StartSyncScheduler(base::Time()); | 673 StartSyncScheduler(base::Time()); |
| 679 | 674 |
| 680 // Run again to wait for polling. | 675 // Run again to wait for polling. |
| 681 RunLoop(); | 676 RunLoop(); |
| 682 | 677 |
| 683 StopSyncScheduler(); | 678 StopSyncScheduler(); |
| 684 AnalyzePollRun(times, kMinNumSamples, optimal_start, poll2); | 679 AnalyzePollRun(times, kMinNumSamples, optimal_start, poll2); |
| 685 } | 680 } |
| 686 | 681 |
| 687 // Test that no syncing occurs when throttled. | 682 // Test that no syncing occurs when throttled. |
| 688 TEST_F(SyncSchedulerTest, ThrottlingDoesThrottle) { | 683 TEST_F(SyncSchedulerTest, ThrottlingDoesThrottle) { |
| 689 const ModelTypeSet types(THEMES); | 684 const ModelTypeSet types(THEMES); |
| 690 TimeDelta poll(TimeDelta::FromMilliseconds(20)); | 685 TimeDelta poll(TimeDelta::FromMilliseconds(20)); |
| 691 TimeDelta throttle(TimeDelta::FromMinutes(10)); | 686 TimeDelta throttle(TimeDelta::FromMinutes(10)); |
| 692 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 687 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
| 693 | 688 |
| 694 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) | 689 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) |
| 695 .WillOnce( | 690 .WillOnce(DoAll(WithArg<2>(test_util::SimulateThrottled(throttle)), |
| 696 DoAll(WithArg<2>(sessions::test_util::SimulateThrottled(throttle)), | 691 Return(false))) |
| 697 Return(false))) | |
| 698 .WillRepeatedly(AddFailureAndQuitLoopNow()); | 692 .WillRepeatedly(AddFailureAndQuitLoopNow()); |
| 699 | 693 |
| 700 StartSyncScheduler(base::Time()); | 694 StartSyncScheduler(base::Time()); |
| 701 | 695 |
| 702 scheduler()->ScheduleLocalNudge(types, FROM_HERE); | 696 scheduler()->ScheduleLocalNudge(types, FROM_HERE); |
| 703 PumpLoop(); | 697 PumpLoop(); |
| 704 | 698 |
| 705 StartSyncConfiguration(); | 699 StartSyncConfiguration(); |
| 706 | 700 |
| 707 CallbackCounter ready_counter; | 701 CallbackCounter ready_counter; |
| 708 CallbackCounter retry_counter; | 702 CallbackCounter retry_counter; |
| 709 ConfigurationParams params( | 703 ConfigurationParams params( |
| 710 GetUpdatesCallerInfo::RECONFIGURATION, types, TypesToRoutingInfo(types), | 704 GetUpdatesCallerInfo::RECONFIGURATION, types, TypesToRoutingInfo(types), |
| 711 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), | 705 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), |
| 712 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); | 706 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); |
| 713 scheduler()->ScheduleConfiguration(params); | 707 scheduler()->ScheduleConfiguration(params); |
| 714 PumpLoop(); | 708 PumpLoop(); |
| 715 ASSERT_EQ(0, ready_counter.times_called()); | 709 ASSERT_EQ(0, ready_counter.times_called()); |
| 716 ASSERT_EQ(1, retry_counter.times_called()); | 710 ASSERT_EQ(1, retry_counter.times_called()); |
| 717 } | 711 } |
| 718 | 712 |
| 719 TEST_F(SyncSchedulerTest, ThrottlingExpiresFromPoll) { | 713 TEST_F(SyncSchedulerTest, ThrottlingExpiresFromPoll) { |
| 720 SyncShareTimes times; | 714 SyncShareTimes times; |
| 721 TimeDelta poll(TimeDelta::FromMilliseconds(15)); | 715 TimeDelta poll(TimeDelta::FromMilliseconds(15)); |
| 722 TimeDelta throttle1(TimeDelta::FromMilliseconds(150)); | 716 TimeDelta throttle1(TimeDelta::FromMilliseconds(150)); |
| 723 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 717 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
| 724 | 718 |
| 725 ::testing::InSequence seq; | 719 ::testing::InSequence seq; |
| 726 EXPECT_CALL(*syncer(), PollSyncShare(_, _)) | 720 EXPECT_CALL(*syncer(), PollSyncShare(_, _)) |
| 727 .WillOnce( | 721 .WillOnce(DoAll(WithArg<1>(test_util::SimulateThrottled(throttle1)), |
| 728 DoAll(WithArg<1>(sessions::test_util::SimulateThrottled(throttle1)), | 722 Return(false))) |
| 729 Return(false))) | |
| 730 .RetiresOnSaturation(); | 723 .RetiresOnSaturation(); |
| 731 EXPECT_CALL(*syncer(), PollSyncShare(_, _)) | 724 EXPECT_CALL(*syncer(), PollSyncShare(_, _)) |
| 732 .WillRepeatedly( | 725 .WillRepeatedly( |
| 733 DoAll(Invoke(sessions::test_util::SimulatePollSuccess), | 726 DoAll(Invoke(test_util::SimulatePollSuccess), |
| 734 RecordSyncShareMultiple(×, kMinNumSamples, true))); | 727 RecordSyncShareMultiple(×, kMinNumSamples, true))); |
| 735 | 728 |
| 736 TimeTicks optimal_start = TimeTicks::Now() + poll + throttle1; | 729 TimeTicks optimal_start = TimeTicks::Now() + poll + throttle1; |
| 737 StartSyncScheduler(base::Time()); | 730 StartSyncScheduler(base::Time()); |
| 738 | 731 |
| 739 // Run again to wait for polling. | 732 // Run again to wait for polling. |
| 740 RunLoop(); | 733 RunLoop(); |
| 741 | 734 |
| 742 StopSyncScheduler(); | 735 StopSyncScheduler(); |
| 743 AnalyzePollRun(times, kMinNumSamples, optimal_start, poll); | 736 AnalyzePollRun(times, kMinNumSamples, optimal_start, poll); |
| 744 } | 737 } |
| 745 | 738 |
| 746 TEST_F(SyncSchedulerTest, ThrottlingExpiresFromNudge) { | 739 TEST_F(SyncSchedulerTest, ThrottlingExpiresFromNudge) { |
| 747 SyncShareTimes times; | 740 SyncShareTimes times; |
| 748 TimeDelta poll(TimeDelta::FromDays(1)); | 741 TimeDelta poll(TimeDelta::FromDays(1)); |
| 749 TimeDelta throttle1(TimeDelta::FromMilliseconds(150)); | 742 TimeDelta throttle1(TimeDelta::FromMilliseconds(150)); |
| 750 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 743 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
| 751 | 744 |
| 752 ::testing::InSequence seq; | 745 ::testing::InSequence seq; |
| 753 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 746 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 754 .WillOnce( | 747 .WillOnce(DoAll(WithArg<2>(test_util::SimulateThrottled(throttle1)), |
| 755 DoAll(WithArg<2>(sessions::test_util::SimulateThrottled(throttle1)), | 748 Return(false))) |
| 756 Return(false))) | |
| 757 .RetiresOnSaturation(); | 749 .RetiresOnSaturation(); |
| 758 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 750 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 759 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 751 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), |
| 760 QuitLoopNowAction(true))); | 752 QuitLoopNowAction(true))); |
| 761 | 753 |
| 762 const ModelTypeSet types(THEMES); | 754 const ModelTypeSet types(THEMES); |
| 763 StartSyncScheduler(base::Time()); | 755 StartSyncScheduler(base::Time()); |
| 764 scheduler()->ScheduleLocalNudge(types, FROM_HERE); | 756 scheduler()->ScheduleLocalNudge(types, FROM_HERE); |
| 765 | 757 |
| 766 PumpLoop(); // To get PerformDelayedNudge called. | 758 PumpLoop(); // To get PerformDelayedNudge called. |
| 767 PumpLoop(); // To get TrySyncSessionJob called | 759 PumpLoop(); // To get TrySyncCycleJob called |
| 768 EXPECT_TRUE(scheduler()->IsCurrentlyThrottled()); | 760 EXPECT_TRUE(scheduler()->IsCurrentlyThrottled()); |
| 769 RunLoop(); | 761 RunLoop(); |
| 770 EXPECT_FALSE(scheduler()->IsCurrentlyThrottled()); | 762 EXPECT_FALSE(scheduler()->IsCurrentlyThrottled()); |
| 771 | 763 |
| 772 StopSyncScheduler(); | 764 StopSyncScheduler(); |
| 773 } | 765 } |
| 774 | 766 |
| 775 TEST_F(SyncSchedulerTest, ThrottlingExpiresFromConfigure) { | 767 TEST_F(SyncSchedulerTest, ThrottlingExpiresFromConfigure) { |
| 776 SyncShareTimes times; | 768 SyncShareTimes times; |
| 777 TimeDelta poll(TimeDelta::FromDays(1)); | 769 TimeDelta poll(TimeDelta::FromDays(1)); |
| 778 TimeDelta throttle1(TimeDelta::FromMilliseconds(150)); | 770 TimeDelta throttle1(TimeDelta::FromMilliseconds(150)); |
| 779 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 771 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
| 780 | 772 |
| 781 ::testing::InSequence seq; | 773 ::testing::InSequence seq; |
| 782 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) | 774 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) |
| 783 .WillOnce( | 775 .WillOnce(DoAll(WithArg<2>(test_util::SimulateThrottled(throttle1)), |
| 784 DoAll(WithArg<2>(sessions::test_util::SimulateThrottled(throttle1)), | 776 Return(false))) |
| 785 Return(false))) | |
| 786 .RetiresOnSaturation(); | 777 .RetiresOnSaturation(); |
| 787 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) | 778 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) |
| 788 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess), | 779 .WillOnce(DoAll(Invoke(test_util::SimulateConfigureSuccess), |
| 789 QuitLoopNowAction(true))); | 780 QuitLoopNowAction(true))); |
| 790 | 781 |
| 791 const ModelTypeSet types(THEMES); | 782 const ModelTypeSet types(THEMES); |
| 792 StartSyncConfiguration(); | 783 StartSyncConfiguration(); |
| 793 | 784 |
| 794 CallbackCounter ready_counter; | 785 CallbackCounter ready_counter; |
| 795 CallbackCounter retry_counter; | 786 CallbackCounter retry_counter; |
| 796 ConfigurationParams params( | 787 ConfigurationParams params( |
| 797 GetUpdatesCallerInfo::RECONFIGURATION, types, TypesToRoutingInfo(types), | 788 GetUpdatesCallerInfo::RECONFIGURATION, types, TypesToRoutingInfo(types), |
| 798 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), | 789 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), |
| (...skipping 15 matching lines...) Expand all Loading... |
| 814 EXPECT_CALL(*delay(), GetDelay(_)).WillRepeatedly(Return(default_delay())); | 805 EXPECT_CALL(*delay(), GetDelay(_)).WillRepeatedly(Return(default_delay())); |
| 815 | 806 |
| 816 TimeDelta poll(TimeDelta::FromDays(1)); | 807 TimeDelta poll(TimeDelta::FromDays(1)); |
| 817 TimeDelta throttle1(TimeDelta::FromSeconds(60)); | 808 TimeDelta throttle1(TimeDelta::FromSeconds(60)); |
| 818 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 809 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
| 819 | 810 |
| 820 const ModelTypeSet types(THEMES); | 811 const ModelTypeSet types(THEMES); |
| 821 | 812 |
| 822 ::testing::InSequence seq; | 813 ::testing::InSequence seq; |
| 823 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 814 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 824 .WillOnce(DoAll(WithArg<2>(sessions::test_util::SimulateTypesThrottled( | 815 .WillOnce( |
| 825 types, throttle1)), | 816 DoAll(WithArg<2>(test_util::SimulateTypesThrottled(types, throttle1)), |
| 826 Return(false))) | 817 Return(false))) |
| 827 .RetiresOnSaturation(); | 818 .RetiresOnSaturation(); |
| 828 | 819 |
| 829 StartSyncScheduler(base::Time()); | 820 StartSyncScheduler(base::Time()); |
| 830 scheduler()->ScheduleLocalNudge(types, FROM_HERE); | 821 scheduler()->ScheduleLocalNudge(types, FROM_HERE); |
| 831 PumpLoop(); // To get PerformDelayedNudge called. | 822 PumpLoop(); // To get PerformDelayedNudge called. |
| 832 PumpLoop(); // To get TrySyncSessionJob called | 823 PumpLoop(); // To get TrySyncCycleJob called |
| 833 EXPECT_TRUE(GetThrottledTypes().HasAll(types)); | 824 EXPECT_TRUE(GetThrottledTypes().HasAll(types)); |
| 834 | 825 |
| 835 // This won't cause a sync cycle because the types are throttled. | 826 // This won't cause a sync cycle because the types are throttled. |
| 836 scheduler()->ScheduleLocalNudge(types, FROM_HERE); | 827 scheduler()->ScheduleLocalNudge(types, FROM_HERE); |
| 837 PumpLoop(); | 828 PumpLoop(); |
| 838 | 829 |
| 839 StopSyncScheduler(); | 830 StopSyncScheduler(); |
| 840 } | 831 } |
| 841 | 832 |
| 842 TEST_F(SyncSchedulerTest, TypeThrottlingDoesBlockOtherSources) { | 833 TEST_F(SyncSchedulerTest, TypeThrottlingDoesBlockOtherSources) { |
| 843 UseMockDelayProvider(); | 834 UseMockDelayProvider(); |
| 844 EXPECT_CALL(*delay(), GetDelay(_)).WillRepeatedly(Return(default_delay())); | 835 EXPECT_CALL(*delay(), GetDelay(_)).WillRepeatedly(Return(default_delay())); |
| 845 | 836 |
| 846 SyncShareTimes times; | 837 SyncShareTimes times; |
| 847 TimeDelta poll(TimeDelta::FromDays(1)); | 838 TimeDelta poll(TimeDelta::FromDays(1)); |
| 848 TimeDelta throttle1(TimeDelta::FromSeconds(60)); | 839 TimeDelta throttle1(TimeDelta::FromSeconds(60)); |
| 849 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 840 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
| 850 | 841 |
| 851 const ModelTypeSet throttled_types(THEMES); | 842 const ModelTypeSet throttled_types(THEMES); |
| 852 const ModelTypeSet unthrottled_types(PREFERENCES); | 843 const ModelTypeSet unthrottled_types(PREFERENCES); |
| 853 | 844 |
| 854 ::testing::InSequence seq; | 845 ::testing::InSequence seq; |
| 855 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 846 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 856 .WillOnce(DoAll(WithArg<2>(sessions::test_util::SimulateTypesThrottled( | 847 .WillOnce(DoAll(WithArg<2>(test_util::SimulateTypesThrottled( |
| 857 throttled_types, throttle1)), | 848 throttled_types, throttle1)), |
| 858 Return(false))) | 849 Return(false))) |
| 859 .RetiresOnSaturation(); | 850 .RetiresOnSaturation(); |
| 860 | 851 |
| 861 StartSyncScheduler(base::Time()); | 852 StartSyncScheduler(base::Time()); |
| 862 scheduler()->ScheduleLocalNudge(throttled_types, FROM_HERE); | 853 scheduler()->ScheduleLocalNudge(throttled_types, FROM_HERE); |
| 863 PumpLoop(); // To get PerformDelayedNudge called. | 854 PumpLoop(); // To get PerformDelayedNudge called. |
| 864 PumpLoop(); // To get TrySyncSessionJob called | 855 PumpLoop(); // To get TrySyncCycleJob called |
| 865 EXPECT_TRUE(GetThrottledTypes().HasAll(throttled_types)); | 856 EXPECT_TRUE(GetThrottledTypes().HasAll(throttled_types)); |
| 866 | 857 |
| 867 // Ignore invalidations for throttled types. | 858 // Ignore invalidations for throttled types. |
| 868 scheduler()->ScheduleInvalidationNudge(THEMES, BuildInvalidation(10, "test"), | 859 scheduler()->ScheduleInvalidationNudge(THEMES, BuildInvalidation(10, "test"), |
| 869 FROM_HERE); | 860 FROM_HERE); |
| 870 PumpLoop(); | 861 PumpLoop(); |
| 871 | 862 |
| 872 // Ignore refresh requests for throttled types. | 863 // Ignore refresh requests for throttled types. |
| 873 scheduler()->ScheduleLocalRefreshRequest(throttled_types, FROM_HERE); | 864 scheduler()->ScheduleLocalRefreshRequest(throttled_types, FROM_HERE); |
| 874 PumpLoop(); | 865 PumpLoop(); |
| 875 | 866 |
| 876 Mock::VerifyAndClearExpectations(syncer()); | 867 Mock::VerifyAndClearExpectations(syncer()); |
| 877 | 868 |
| 878 // Local nudges for non-throttled types will trigger a sync. | 869 // Local nudges for non-throttled types will trigger a sync. |
| 879 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 870 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 880 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 871 .WillRepeatedly(DoAll(Invoke(test_util::SimulateNormalSuccess), |
| 881 RecordSyncShare(×, true))); | 872 RecordSyncShare(×, true))); |
| 882 scheduler()->ScheduleLocalNudge(unthrottled_types, FROM_HERE); | 873 scheduler()->ScheduleLocalNudge(unthrottled_types, FROM_HERE); |
| 883 RunLoop(); | 874 RunLoop(); |
| 884 Mock::VerifyAndClearExpectations(syncer()); | 875 Mock::VerifyAndClearExpectations(syncer()); |
| 885 | 876 |
| 886 StopSyncScheduler(); | 877 StopSyncScheduler(); |
| 887 } | 878 } |
| 888 | 879 |
| 889 // Test nudges / polls don't run in config mode and config tasks do. | 880 // Test nudges / polls don't run in config mode and config tasks do. |
| 890 TEST_F(SyncSchedulerTest, ConfigurationMode) { | 881 TEST_F(SyncSchedulerTest, ConfigurationMode) { |
| 891 TimeDelta poll(TimeDelta::FromMilliseconds(15)); | 882 TimeDelta poll(TimeDelta::FromMilliseconds(15)); |
| 892 SyncShareTimes times; | 883 SyncShareTimes times; |
| 893 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 884 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
| 894 | 885 |
| 895 StartSyncConfiguration(); | 886 StartSyncConfiguration(); |
| 896 | 887 |
| 897 const ModelTypeSet nudge_types(TYPED_URLS); | 888 const ModelTypeSet nudge_types(TYPED_URLS); |
| 898 scheduler()->ScheduleLocalNudge(nudge_types, FROM_HERE); | 889 scheduler()->ScheduleLocalNudge(nudge_types, FROM_HERE); |
| 899 scheduler()->ScheduleLocalNudge(nudge_types, FROM_HERE); | 890 scheduler()->ScheduleLocalNudge(nudge_types, FROM_HERE); |
| 900 | 891 |
| 901 const ModelTypeSet config_types(THEMES); | 892 const ModelTypeSet config_types(THEMES); |
| 902 | 893 |
| 903 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) | 894 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) |
| 904 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess), | 895 .WillOnce(DoAll(Invoke(test_util::SimulateConfigureSuccess), |
| 905 RecordSyncShare(×, true))) | 896 RecordSyncShare(×, true))) |
| 906 .RetiresOnSaturation(); | 897 .RetiresOnSaturation(); |
| 907 CallbackCounter ready_counter; | 898 CallbackCounter ready_counter; |
| 908 CallbackCounter retry_counter; | 899 CallbackCounter retry_counter; |
| 909 ConfigurationParams params( | 900 ConfigurationParams params( |
| 910 GetUpdatesCallerInfo::RECONFIGURATION, config_types, | 901 GetUpdatesCallerInfo::RECONFIGURATION, config_types, |
| 911 TypesToRoutingInfo(config_types), | 902 TypesToRoutingInfo(config_types), |
| 912 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), | 903 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), |
| 913 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); | 904 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); |
| 914 scheduler()->ScheduleConfiguration(params); | 905 scheduler()->ScheduleConfiguration(params); |
| 915 RunLoop(); | 906 RunLoop(); |
| 916 ASSERT_EQ(1, ready_counter.times_called()); | 907 ASSERT_EQ(1, ready_counter.times_called()); |
| 917 ASSERT_EQ(0, retry_counter.times_called()); | 908 ASSERT_EQ(0, retry_counter.times_called()); |
| 918 | 909 |
| 919 Mock::VerifyAndClearExpectations(syncer()); | 910 Mock::VerifyAndClearExpectations(syncer()); |
| 920 | 911 |
| 921 // Switch to NORMAL_MODE to ensure NUDGES were properly saved and run. | 912 // Switch to NORMAL_MODE to ensure NUDGES were properly saved and run. |
| 922 scheduler()->OnReceivedLongPollIntervalUpdate(TimeDelta::FromDays(1)); | 913 scheduler()->OnReceivedLongPollIntervalUpdate(TimeDelta::FromDays(1)); |
| 923 SyncShareTimes times2; | 914 SyncShareTimes times2; |
| 924 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 915 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 925 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 916 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), |
| 926 RecordSyncShare(×2, true))); | 917 RecordSyncShare(×2, true))); |
| 927 | 918 |
| 928 // TODO(tim): Figure out how to remove this dangerous need to reset | 919 // TODO(tim): Figure out how to remove this dangerous need to reset |
| 929 // routing info between mode switches. | 920 // routing info between mode switches. |
| 930 context()->SetRoutingInfo(routing_info()); | 921 context()->SetRoutingInfo(routing_info()); |
| 931 StartSyncScheduler(base::Time()); | 922 StartSyncScheduler(base::Time()); |
| 932 | 923 |
| 933 RunLoop(); | 924 RunLoop(); |
| 934 Mock::VerifyAndClearExpectations(syncer()); | 925 Mock::VerifyAndClearExpectations(syncer()); |
| 935 } | 926 } |
| 936 | 927 |
| 937 class BackoffTriggersSyncSchedulerTest : public SyncSchedulerTest { | 928 class BackoffTriggersSyncSchedulerTest : public SyncSchedulerTest { |
| 938 void SetUp() override { | 929 void SetUp() override { |
| 939 SyncSchedulerTest::SetUp(); | 930 SyncSchedulerTest::SetUp(); |
| 940 UseMockDelayProvider(); | 931 UseMockDelayProvider(); |
| 941 EXPECT_CALL(*delay(), GetDelay(_)) | 932 EXPECT_CALL(*delay(), GetDelay(_)) |
| 942 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(10))); | 933 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(10))); |
| 943 } | 934 } |
| 944 | 935 |
| 945 void TearDown() override { | 936 void TearDown() override { |
| 946 StopSyncScheduler(); | 937 StopSyncScheduler(); |
| 947 SyncSchedulerTest::TearDown(); | 938 SyncSchedulerTest::TearDown(); |
| 948 } | 939 } |
| 949 }; | 940 }; |
| 950 | 941 |
| 951 // Have the syncer fail during commit. Expect that the scheduler enters | 942 // Have the syncer fail during commit. Expect that the scheduler enters |
| 952 // backoff. | 943 // backoff. |
| 953 TEST_F(BackoffTriggersSyncSchedulerTest, FailCommitOnce) { | 944 TEST_F(BackoffTriggersSyncSchedulerTest, FailCommitOnce) { |
| 954 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 945 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 955 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), | 946 .WillOnce(DoAll(Invoke(test_util::SimulateCommitFailed), |
| 956 QuitLoopNowAction(false))); | 947 QuitLoopNowAction(false))); |
| 957 EXPECT_TRUE(RunAndGetBackoff()); | 948 EXPECT_TRUE(RunAndGetBackoff()); |
| 958 } | 949 } |
| 959 | 950 |
| 960 // Have the syncer fail during download updates and succeed on the first | 951 // Have the syncer fail during download updates and succeed on the first |
| 961 // retry. Expect that this clears the backoff state. | 952 // retry. Expect that this clears the backoff state. |
| 962 TEST_F(BackoffTriggersSyncSchedulerTest, FailDownloadOnceThenSucceed) { | 953 TEST_F(BackoffTriggersSyncSchedulerTest, FailDownloadOnceThenSucceed) { |
| 963 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 954 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 964 .WillOnce( | 955 .WillOnce(DoAll(Invoke(test_util::SimulateDownloadUpdatesFailed), |
| 965 DoAll(Invoke(sessions::test_util::SimulateDownloadUpdatesFailed), | 956 Return(false))) |
| 966 Return(false))) | 957 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), |
| 967 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | |
| 968 QuitLoopNowAction(true))); | 958 QuitLoopNowAction(true))); |
| 969 EXPECT_FALSE(RunAndGetBackoff()); | 959 EXPECT_FALSE(RunAndGetBackoff()); |
| 970 } | 960 } |
| 971 | 961 |
| 972 // Have the syncer fail during commit and succeed on the first retry. Expect | 962 // Have the syncer fail during commit and succeed on the first retry. Expect |
| 973 // that this clears the backoff state. | 963 // that this clears the backoff state. |
| 974 TEST_F(BackoffTriggersSyncSchedulerTest, FailCommitOnceThenSucceed) { | 964 TEST_F(BackoffTriggersSyncSchedulerTest, FailCommitOnceThenSucceed) { |
| 975 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 965 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 976 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), | 966 .WillOnce(DoAll(Invoke(test_util::SimulateCommitFailed), Return(false))) |
| 977 Return(false))) | 967 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), |
| 978 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | |
| 979 QuitLoopNowAction(true))); | 968 QuitLoopNowAction(true))); |
| 980 EXPECT_FALSE(RunAndGetBackoff()); | 969 EXPECT_FALSE(RunAndGetBackoff()); |
| 981 } | 970 } |
| 982 | 971 |
| 983 // Have the syncer fail to download updates and fail again on the retry. | 972 // Have the syncer fail to download updates and fail again on the retry. |
| 984 // Expect this will leave the scheduler in backoff. | 973 // Expect this will leave the scheduler in backoff. |
| 985 TEST_F(BackoffTriggersSyncSchedulerTest, FailDownloadTwice) { | 974 TEST_F(BackoffTriggersSyncSchedulerTest, FailDownloadTwice) { |
| 986 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 975 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 987 .WillOnce( | 976 .WillOnce(DoAll(Invoke(test_util::SimulateDownloadUpdatesFailed), |
| 988 DoAll(Invoke(sessions::test_util::SimulateDownloadUpdatesFailed), | 977 Return(false))) |
| 989 Return(false))) | 978 .WillRepeatedly(DoAll(Invoke(test_util::SimulateDownloadUpdatesFailed), |
| 990 .WillRepeatedly( | 979 QuitLoopNowAction(false))); |
| 991 DoAll(Invoke(sessions::test_util::SimulateDownloadUpdatesFailed), | |
| 992 QuitLoopNowAction(false))); | |
| 993 EXPECT_TRUE(RunAndGetBackoff()); | 980 EXPECT_TRUE(RunAndGetBackoff()); |
| 994 } | 981 } |
| 995 | 982 |
| 996 // Have the syncer fail to get the encryption key yet succeed in downloading | 983 // Have the syncer fail to get the encryption key yet succeed in downloading |
| 997 // updates. Expect this will leave the scheduler in backoff. | 984 // updates. Expect this will leave the scheduler in backoff. |
| 998 TEST_F(BackoffTriggersSyncSchedulerTest, FailGetEncryptionKey) { | 985 TEST_F(BackoffTriggersSyncSchedulerTest, FailGetEncryptionKey) { |
| 999 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) | 986 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) |
| 1000 .WillOnce( | 987 .WillOnce(DoAll(Invoke(test_util::SimulateGetEncryptionKeyFailed), |
| 1001 DoAll(Invoke(sessions::test_util::SimulateGetEncryptionKeyFailed), | 988 Return(false))) |
| 1002 Return(false))) | 989 .WillRepeatedly(DoAll(Invoke(test_util::SimulateGetEncryptionKeyFailed), |
| 1003 .WillRepeatedly( | 990 QuitLoopNowAction(false))); |
| 1004 DoAll(Invoke(sessions::test_util::SimulateGetEncryptionKeyFailed), | |
| 1005 QuitLoopNowAction(false))); | |
| 1006 StartSyncConfiguration(); | 991 StartSyncConfiguration(); |
| 1007 | 992 |
| 1008 ModelTypeSet types(THEMES); | 993 ModelTypeSet types(THEMES); |
| 1009 CallbackCounter ready_counter; | 994 CallbackCounter ready_counter; |
| 1010 CallbackCounter retry_counter; | 995 CallbackCounter retry_counter; |
| 1011 ConfigurationParams params( | 996 ConfigurationParams params( |
| 1012 GetUpdatesCallerInfo::RECONFIGURATION, types, TypesToRoutingInfo(types), | 997 GetUpdatesCallerInfo::RECONFIGURATION, types, TypesToRoutingInfo(types), |
| 1013 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), | 998 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), |
| 1014 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); | 999 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); |
| 1015 scheduler()->ScheduleConfiguration(params); | 1000 scheduler()->ScheduleConfiguration(params); |
| 1016 RunLoop(); | 1001 RunLoop(); |
| 1017 | 1002 |
| 1018 EXPECT_TRUE(scheduler()->IsBackingOff()); | 1003 EXPECT_TRUE(scheduler()->IsBackingOff()); |
| 1019 } | 1004 } |
| 1020 | 1005 |
| 1021 // Test that no polls or extraneous nudges occur when in backoff. | 1006 // Test that no polls or extraneous nudges occur when in backoff. |
| 1022 TEST_F(SyncSchedulerTest, BackoffDropsJobs) { | 1007 TEST_F(SyncSchedulerTest, BackoffDropsJobs) { |
| 1023 SyncShareTimes times; | 1008 SyncShareTimes times; |
| 1024 TimeDelta poll(TimeDelta::FromMilliseconds(10)); | 1009 TimeDelta poll(TimeDelta::FromMilliseconds(10)); |
| 1025 const ModelTypeSet types(THEMES); | 1010 const ModelTypeSet types(THEMES); |
| 1026 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 1011 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
| 1027 UseMockDelayProvider(); | 1012 UseMockDelayProvider(); |
| 1028 | 1013 |
| 1029 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 1014 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 1030 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), | 1015 .WillOnce(DoAll(Invoke(test_util::SimulateCommitFailed), |
| 1031 RecordSyncShareMultiple(×, 1U, false))); | 1016 RecordSyncShareMultiple(×, 1U, false))); |
| 1032 EXPECT_CALL(*delay(), GetDelay(_)) | 1017 EXPECT_CALL(*delay(), GetDelay(_)) |
| 1033 .WillRepeatedly(Return(TimeDelta::FromDays(1))); | 1018 .WillRepeatedly(Return(TimeDelta::FromDays(1))); |
| 1034 | 1019 |
| 1035 StartSyncScheduler(base::Time()); | 1020 StartSyncScheduler(base::Time()); |
| 1036 | 1021 |
| 1037 // This nudge should fail and put us into backoff. Thanks to our mock | 1022 // This nudge should fail and put us into backoff. Thanks to our mock |
| 1038 // GetDelay() setup above, this will be a long backoff. | 1023 // GetDelay() setup above, this will be a long backoff. |
| 1039 scheduler()->ScheduleLocalNudge(types, FROM_HERE); | 1024 scheduler()->ScheduleLocalNudge(types, FROM_HERE); |
| 1040 RunLoop(); | 1025 RunLoop(); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1068 } | 1053 } |
| 1069 | 1054 |
| 1070 // Test that backoff is shaping traffic properly with consecutive errors. | 1055 // Test that backoff is shaping traffic properly with consecutive errors. |
| 1071 TEST_F(SyncSchedulerTest, BackoffElevation) { | 1056 TEST_F(SyncSchedulerTest, BackoffElevation) { |
| 1072 SyncShareTimes times; | 1057 SyncShareTimes times; |
| 1073 UseMockDelayProvider(); | 1058 UseMockDelayProvider(); |
| 1074 | 1059 |
| 1075 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 1060 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 1076 .Times(kMinNumSamples) | 1061 .Times(kMinNumSamples) |
| 1077 .WillRepeatedly( | 1062 .WillRepeatedly( |
| 1078 DoAll(Invoke(sessions::test_util::SimulateCommitFailed), | 1063 DoAll(Invoke(test_util::SimulateCommitFailed), |
| 1079 RecordSyncShareMultiple(×, kMinNumSamples, false))); | 1064 RecordSyncShareMultiple(×, kMinNumSamples, false))); |
| 1080 | 1065 |
| 1081 const TimeDelta first = TimeDelta::FromSeconds(kInitialBackoffRetrySeconds); | 1066 const TimeDelta first = TimeDelta::FromSeconds(kInitialBackoffRetrySeconds); |
| 1082 const TimeDelta second = TimeDelta::FromMilliseconds(20); | 1067 const TimeDelta second = TimeDelta::FromMilliseconds(20); |
| 1083 const TimeDelta third = TimeDelta::FromMilliseconds(30); | 1068 const TimeDelta third = TimeDelta::FromMilliseconds(30); |
| 1084 const TimeDelta fourth = TimeDelta::FromMilliseconds(40); | 1069 const TimeDelta fourth = TimeDelta::FromMilliseconds(40); |
| 1085 const TimeDelta fifth = TimeDelta::FromMilliseconds(50); | 1070 const TimeDelta fifth = TimeDelta::FromMilliseconds(50); |
| 1086 const TimeDelta sixth = TimeDelta::FromDays(1); | 1071 const TimeDelta sixth = TimeDelta::FromDays(1); |
| 1087 | 1072 |
| 1088 EXPECT_CALL(*delay(), GetDelay(first)) | 1073 EXPECT_CALL(*delay(), GetDelay(first)) |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1119 | 1104 |
| 1120 const TimeDelta backoff = TimeDelta::FromMilliseconds(10); | 1105 const TimeDelta backoff = TimeDelta::FromMilliseconds(10); |
| 1121 EXPECT_CALL(*delay(), GetDelay(_)).WillOnce(Return(backoff)); | 1106 EXPECT_CALL(*delay(), GetDelay(_)).WillOnce(Return(backoff)); |
| 1122 | 1107 |
| 1123 // Optimal start for the post-backoff poll party. | 1108 // Optimal start for the post-backoff poll party. |
| 1124 TimeTicks optimal_start = TimeTicks::Now(); | 1109 TimeTicks optimal_start = TimeTicks::Now(); |
| 1125 StartSyncScheduler(base::Time()); | 1110 StartSyncScheduler(base::Time()); |
| 1126 | 1111 |
| 1127 // Kick off the test with a failed nudge. | 1112 // Kick off the test with a failed nudge. |
| 1128 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 1113 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 1129 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), | 1114 .WillOnce(DoAll(Invoke(test_util::SimulateCommitFailed), |
| 1130 RecordSyncShare(×, false))); | 1115 RecordSyncShare(×, false))); |
| 1131 scheduler()->ScheduleLocalNudge(ModelTypeSet(THEMES), FROM_HERE); | 1116 scheduler()->ScheduleLocalNudge(ModelTypeSet(THEMES), FROM_HERE); |
| 1132 RunLoop(); | 1117 RunLoop(); |
| 1133 Mock::VerifyAndClearExpectations(syncer()); | 1118 Mock::VerifyAndClearExpectations(syncer()); |
| 1134 TimeTicks optimal_job_time = optimal_start; | 1119 TimeTicks optimal_job_time = optimal_start; |
| 1135 ASSERT_EQ(1U, times.size()); | 1120 ASSERT_EQ(1U, times.size()); |
| 1136 EXPECT_GE(times[0], optimal_job_time); | 1121 EXPECT_GE(times[0], optimal_job_time); |
| 1137 | 1122 |
| 1138 // The retry succeeds. | 1123 // The retry succeeds. |
| 1139 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 1124 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 1140 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 1125 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), |
| 1141 RecordSyncShare(×, true))); | 1126 RecordSyncShare(×, true))); |
| 1142 RunLoop(); | 1127 RunLoop(); |
| 1143 Mock::VerifyAndClearExpectations(syncer()); | 1128 Mock::VerifyAndClearExpectations(syncer()); |
| 1144 optimal_job_time = optimal_job_time + backoff; | 1129 optimal_job_time = optimal_job_time + backoff; |
| 1145 ASSERT_EQ(2U, times.size()); | 1130 ASSERT_EQ(2U, times.size()); |
| 1146 EXPECT_GE(times[1], optimal_job_time); | 1131 EXPECT_GE(times[1], optimal_job_time); |
| 1147 | 1132 |
| 1148 // Now let the Poll timer do its thing. | 1133 // Now let the Poll timer do its thing. |
| 1149 EXPECT_CALL(*syncer(), PollSyncShare(_, _)) | 1134 EXPECT_CALL(*syncer(), PollSyncShare(_, _)) |
| 1150 .WillRepeatedly( | 1135 .WillRepeatedly( |
| 1151 DoAll(Invoke(sessions::test_util::SimulatePollSuccess), | 1136 DoAll(Invoke(test_util::SimulatePollSuccess), |
| 1152 RecordSyncShareMultiple(×, kMinNumSamples, true))); | 1137 RecordSyncShareMultiple(×, kMinNumSamples, true))); |
| 1153 const TimeDelta poll(TimeDelta::FromMilliseconds(10)); | 1138 const TimeDelta poll(TimeDelta::FromMilliseconds(10)); |
| 1154 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 1139 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
| 1155 | 1140 |
| 1156 // The new optimal time is now, since the desired poll should have happened | 1141 // The new optimal time is now, since the desired poll should have happened |
| 1157 // in the past. | 1142 // in the past. |
| 1158 optimal_job_time = base::TimeTicks::Now(); | 1143 optimal_job_time = base::TimeTicks::Now(); |
| 1159 RunLoop(); | 1144 RunLoop(); |
| 1160 Mock::VerifyAndClearExpectations(syncer()); | 1145 Mock::VerifyAndClearExpectations(syncer()); |
| 1161 ASSERT_EQ(kMinNumSamples, times.size()); | 1146 ASSERT_EQ(kMinNumSamples, times.size()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1172 // result in retry with backoff. | 1157 // result in retry with backoff. |
| 1173 TEST_F(SyncSchedulerTest, TransientPollFailure) { | 1158 TEST_F(SyncSchedulerTest, TransientPollFailure) { |
| 1174 SyncShareTimes times; | 1159 SyncShareTimes times; |
| 1175 const TimeDelta poll_interval(TimeDelta::FromMilliseconds(10)); | 1160 const TimeDelta poll_interval(TimeDelta::FromMilliseconds(10)); |
| 1176 scheduler()->OnReceivedLongPollIntervalUpdate(poll_interval); | 1161 scheduler()->OnReceivedLongPollIntervalUpdate(poll_interval); |
| 1177 UseMockDelayProvider(); // Will cause test failure if backoff is initiated. | 1162 UseMockDelayProvider(); // Will cause test failure if backoff is initiated. |
| 1178 EXPECT_CALL(*delay(), GetDelay(_)) | 1163 EXPECT_CALL(*delay(), GetDelay(_)) |
| 1179 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(0))); | 1164 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(0))); |
| 1180 | 1165 |
| 1181 EXPECT_CALL(*syncer(), PollSyncShare(_, _)) | 1166 EXPECT_CALL(*syncer(), PollSyncShare(_, _)) |
| 1182 .WillOnce(DoAll(Invoke(sessions::test_util::SimulatePollFailed), | 1167 .WillOnce(DoAll(Invoke(test_util::SimulatePollFailed), |
| 1183 RecordSyncShare(×, false))) | 1168 RecordSyncShare(×, false))) |
| 1184 .WillOnce(DoAll(Invoke(sessions::test_util::SimulatePollSuccess), | 1169 .WillOnce(DoAll(Invoke(test_util::SimulatePollSuccess), |
| 1185 RecordSyncShare(×, true))); | 1170 RecordSyncShare(×, true))); |
| 1186 | 1171 |
| 1187 StartSyncScheduler(base::Time()); | 1172 StartSyncScheduler(base::Time()); |
| 1188 | 1173 |
| 1189 // Run the unsuccessful poll. The failed poll should not trigger backoff. | 1174 // Run the unsuccessful poll. The failed poll should not trigger backoff. |
| 1190 RunLoop(); | 1175 RunLoop(); |
| 1191 EXPECT_TRUE(scheduler()->IsBackingOff()); | 1176 EXPECT_TRUE(scheduler()->IsBackingOff()); |
| 1192 | 1177 |
| 1193 // Run the successful poll. | 1178 // Run the successful poll. |
| 1194 RunLoop(); | 1179 RunLoop(); |
| 1195 EXPECT_FALSE(scheduler()->IsBackingOff()); | 1180 EXPECT_FALSE(scheduler()->IsBackingOff()); |
| 1196 } | 1181 } |
| 1197 | 1182 |
| 1198 // Test that starting the syncer thread without a valid connection doesn't | 1183 // Test that starting the syncer thread without a valid connection doesn't |
| 1199 // break things when a connection is detected. | 1184 // break things when a connection is detected. |
| 1200 TEST_F(SyncSchedulerTest, StartWhenNotConnected) { | 1185 TEST_F(SyncSchedulerTest, StartWhenNotConnected) { |
| 1201 connection()->SetServerNotReachable(); | 1186 connection()->SetServerNotReachable(); |
| 1202 connection()->UpdateConnectionStatus(); | 1187 connection()->UpdateConnectionStatus(); |
| 1203 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 1188 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 1204 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConnectionFailure), | 1189 .WillOnce( |
| 1205 Return(false))) | 1190 DoAll(Invoke(test_util::SimulateConnectionFailure), Return(false))) |
| 1206 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 1191 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), Return(true))); |
| 1207 Return(true))); | |
| 1208 StartSyncScheduler(base::Time()); | 1192 StartSyncScheduler(base::Time()); |
| 1209 | 1193 |
| 1210 scheduler()->ScheduleLocalNudge(ModelTypeSet(THEMES), FROM_HERE); | 1194 scheduler()->ScheduleLocalNudge(ModelTypeSet(THEMES), FROM_HERE); |
| 1211 // Should save the nudge for until after the server is reachable. | 1195 // Should save the nudge for until after the server is reachable. |
| 1212 base::RunLoop().RunUntilIdle(); | 1196 base::RunLoop().RunUntilIdle(); |
| 1213 | 1197 |
| 1214 scheduler()->OnConnectionStatusChange(); | 1198 scheduler()->OnConnectionStatusChange(); |
| 1215 connection()->SetServerReachable(); | 1199 connection()->SetServerReachable(); |
| 1216 connection()->UpdateConnectionStatus(); | 1200 connection()->UpdateConnectionStatus(); |
| 1217 base::RunLoop().RunUntilIdle(); | 1201 base::RunLoop().RunUntilIdle(); |
| 1218 } | 1202 } |
| 1219 | 1203 |
| 1220 TEST_F(SyncSchedulerTest, ServerConnectionChangeDuringBackoff) { | 1204 TEST_F(SyncSchedulerTest, ServerConnectionChangeDuringBackoff) { |
| 1221 UseMockDelayProvider(); | 1205 UseMockDelayProvider(); |
| 1222 EXPECT_CALL(*delay(), GetDelay(_)) | 1206 EXPECT_CALL(*delay(), GetDelay(_)) |
| 1223 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(0))); | 1207 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(0))); |
| 1224 | 1208 |
| 1225 StartSyncScheduler(base::Time()); | 1209 StartSyncScheduler(base::Time()); |
| 1226 connection()->SetServerNotReachable(); | 1210 connection()->SetServerNotReachable(); |
| 1227 connection()->UpdateConnectionStatus(); | 1211 connection()->UpdateConnectionStatus(); |
| 1228 | 1212 |
| 1229 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 1213 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 1230 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConnectionFailure), | 1214 .WillOnce( |
| 1231 Return(false))) | 1215 DoAll(Invoke(test_util::SimulateConnectionFailure), Return(false))) |
| 1232 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 1216 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), Return(true))); |
| 1233 Return(true))); | |
| 1234 | 1217 |
| 1235 scheduler()->ScheduleLocalNudge(ModelTypeSet(THEMES), FROM_HERE); | 1218 scheduler()->ScheduleLocalNudge(ModelTypeSet(THEMES), FROM_HERE); |
| 1236 PumpLoop(); // To get PerformDelayedNudge called. | 1219 PumpLoop(); // To get PerformDelayedNudge called. |
| 1237 PumpLoop(); // Run the nudge, that will fail and schedule a quick retry. | 1220 PumpLoop(); // Run the nudge, that will fail and schedule a quick retry. |
| 1238 ASSERT_TRUE(scheduler()->IsBackingOff()); | 1221 ASSERT_TRUE(scheduler()->IsBackingOff()); |
| 1239 | 1222 |
| 1240 // Before we run the scheduled canary, trigger a server connection change. | 1223 // Before we run the scheduled canary, trigger a server connection change. |
| 1241 scheduler()->OnConnectionStatusChange(); | 1224 scheduler()->OnConnectionStatusChange(); |
| 1242 connection()->SetServerReachable(); | 1225 connection()->SetServerReachable(); |
| 1243 connection()->UpdateConnectionStatus(); | 1226 connection()->UpdateConnectionStatus(); |
| 1244 base::RunLoop().RunUntilIdle(); | 1227 base::RunLoop().RunUntilIdle(); |
| 1245 } | 1228 } |
| 1246 | 1229 |
| 1247 // This was supposed to test the scenario where we receive a nudge while a | 1230 // This was supposed to test the scenario where we receive a nudge while a |
| 1248 // connection change canary is scheduled, but has not run yet. Since we've made | 1231 // connection change canary is scheduled, but has not run yet. Since we've made |
| 1249 // the connection change canary synchronous, this is no longer possible. | 1232 // the connection change canary synchronous, this is no longer possible. |
| 1250 TEST_F(SyncSchedulerTest, ConnectionChangeCanaryPreemptedByNudge) { | 1233 TEST_F(SyncSchedulerTest, ConnectionChangeCanaryPreemptedByNudge) { |
| 1251 UseMockDelayProvider(); | 1234 UseMockDelayProvider(); |
| 1252 EXPECT_CALL(*delay(), GetDelay(_)) | 1235 EXPECT_CALL(*delay(), GetDelay(_)) |
| 1253 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(0))); | 1236 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(0))); |
| 1254 | 1237 |
| 1255 StartSyncScheduler(base::Time()); | 1238 StartSyncScheduler(base::Time()); |
| 1256 connection()->SetServerNotReachable(); | 1239 connection()->SetServerNotReachable(); |
| 1257 connection()->UpdateConnectionStatus(); | 1240 connection()->UpdateConnectionStatus(); |
| 1258 | 1241 |
| 1259 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 1242 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 1260 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConnectionFailure), | 1243 .WillOnce( |
| 1261 Return(false))) | 1244 DoAll(Invoke(test_util::SimulateConnectionFailure), Return(false))) |
| 1262 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 1245 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), Return(true))) |
| 1263 Return(true))) | 1246 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), |
| 1264 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | |
| 1265 QuitLoopNowAction(true))); | 1247 QuitLoopNowAction(true))); |
| 1266 | 1248 |
| 1267 scheduler()->ScheduleLocalNudge(ModelTypeSet(THEMES), FROM_HERE); | 1249 scheduler()->ScheduleLocalNudge(ModelTypeSet(THEMES), FROM_HERE); |
| 1268 | 1250 |
| 1269 PumpLoop(); // To get PerformDelayedNudge called. | 1251 PumpLoop(); // To get PerformDelayedNudge called. |
| 1270 PumpLoop(); // Run the nudge, that will fail and schedule a quick retry. | 1252 PumpLoop(); // Run the nudge, that will fail and schedule a quick retry. |
| 1271 ASSERT_TRUE(scheduler()->IsBackingOff()); | 1253 ASSERT_TRUE(scheduler()->IsBackingOff()); |
| 1272 | 1254 |
| 1273 // Before we run the scheduled canary, trigger a server connection change. | 1255 // Before we run the scheduled canary, trigger a server connection change. |
| 1274 scheduler()->OnConnectionStatusChange(); | 1256 scheduler()->OnConnectionStatusChange(); |
| 1275 PumpLoop(); | 1257 PumpLoop(); |
| 1276 connection()->SetServerReachable(); | 1258 connection()->SetServerReachable(); |
| 1277 connection()->UpdateConnectionStatus(); | 1259 connection()->UpdateConnectionStatus(); |
| 1278 scheduler()->ScheduleLocalNudge(ModelTypeSet(THEMES), FROM_HERE); | 1260 scheduler()->ScheduleLocalNudge(ModelTypeSet(THEMES), FROM_HERE); |
| 1279 base::RunLoop().RunUntilIdle(); | 1261 base::RunLoop().RunUntilIdle(); |
| 1280 } | 1262 } |
| 1281 | 1263 |
| 1282 // Tests that we don't crash trying to run two canaries at once if we receive | 1264 // Tests that we don't crash trying to run two canaries at once if we receive |
| 1283 // extra connection status change notifications. See crbug.com/190085. | 1265 // extra connection status change notifications. See crbug.com/190085. |
| 1284 TEST_F(SyncSchedulerTest, DoubleCanaryInConfigure) { | 1266 TEST_F(SyncSchedulerTest, DoubleCanaryInConfigure) { |
| 1285 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) | 1267 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) |
| 1286 .WillRepeatedly( | 1268 .WillRepeatedly(DoAll( |
| 1287 DoAll(Invoke(sessions::test_util::SimulateConfigureConnectionFailure), | 1269 Invoke(test_util::SimulateConfigureConnectionFailure), Return(true))); |
| 1288 Return(true))); | |
| 1289 StartSyncConfiguration(); | 1270 StartSyncConfiguration(); |
| 1290 connection()->SetServerNotReachable(); | 1271 connection()->SetServerNotReachable(); |
| 1291 connection()->UpdateConnectionStatus(); | 1272 connection()->UpdateConnectionStatus(); |
| 1292 | 1273 |
| 1293 ModelTypeSet model_types(THEMES); | 1274 ModelTypeSet model_types(THEMES); |
| 1294 CallbackCounter ready_counter; | 1275 CallbackCounter ready_counter; |
| 1295 CallbackCounter retry_counter; | 1276 CallbackCounter retry_counter; |
| 1296 ConfigurationParams params( | 1277 ConfigurationParams params( |
| 1297 GetUpdatesCallerInfo::RECONFIGURATION, model_types, | 1278 GetUpdatesCallerInfo::RECONFIGURATION, model_types, |
| 1298 TypesToRoutingInfo(model_types), | 1279 TypesToRoutingInfo(model_types), |
| 1299 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), | 1280 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), |
| 1300 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); | 1281 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); |
| 1301 scheduler()->ScheduleConfiguration(params); | 1282 scheduler()->ScheduleConfiguration(params); |
| 1302 | 1283 |
| 1303 scheduler()->OnConnectionStatusChange(); | 1284 scheduler()->OnConnectionStatusChange(); |
| 1304 scheduler()->OnConnectionStatusChange(); | 1285 scheduler()->OnConnectionStatusChange(); |
| 1305 | 1286 |
| 1306 PumpLoop(); // Run the nudge, that will fail and schedule a quick retry. | 1287 PumpLoop(); // Run the nudge, that will fail and schedule a quick retry. |
| 1307 } | 1288 } |
| 1308 | 1289 |
| 1309 TEST_F(SyncSchedulerTest, PollFromCanaryAfterAuthError) { | 1290 TEST_F(SyncSchedulerTest, PollFromCanaryAfterAuthError) { |
| 1310 SyncShareTimes times; | 1291 SyncShareTimes times; |
| 1311 TimeDelta poll(TimeDelta::FromMilliseconds(15)); | 1292 TimeDelta poll(TimeDelta::FromMilliseconds(15)); |
| 1312 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 1293 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
| 1313 | 1294 |
| 1314 ::testing::InSequence seq; | 1295 ::testing::InSequence seq; |
| 1315 EXPECT_CALL(*syncer(), PollSyncShare(_, _)) | 1296 EXPECT_CALL(*syncer(), PollSyncShare(_, _)) |
| 1316 .WillRepeatedly( | 1297 .WillRepeatedly( |
| 1317 DoAll(Invoke(sessions::test_util::SimulatePollSuccess), | 1298 DoAll(Invoke(test_util::SimulatePollSuccess), |
| 1318 RecordSyncShareMultiple(×, kMinNumSamples, true))); | 1299 RecordSyncShareMultiple(×, kMinNumSamples, true))); |
| 1319 | 1300 |
| 1320 connection()->SetServerStatus(HttpResponse::SYNC_AUTH_ERROR); | 1301 connection()->SetServerStatus(HttpResponse::SYNC_AUTH_ERROR); |
| 1321 StartSyncScheduler(base::Time()); | 1302 StartSyncScheduler(base::Time()); |
| 1322 | 1303 |
| 1323 // Run to wait for polling. | 1304 // Run to wait for polling. |
| 1324 RunLoop(); | 1305 RunLoop(); |
| 1325 | 1306 |
| 1326 // Normally OnCredentialsUpdated calls TryCanaryJob that doesn't run Poll, | 1307 // Normally OnCredentialsUpdated calls TryCanaryJob that doesn't run Poll, |
| 1327 // but after poll finished with auth error from poll timer it should retry | 1308 // but after poll finished with auth error from poll timer it should retry |
| 1328 // poll once more | 1309 // poll once more |
| 1329 EXPECT_CALL(*syncer(), PollSyncShare(_, _)) | 1310 EXPECT_CALL(*syncer(), PollSyncShare(_, _)) |
| 1330 .WillOnce(DoAll(Invoke(sessions::test_util::SimulatePollSuccess), | 1311 .WillOnce(DoAll(Invoke(test_util::SimulatePollSuccess), |
| 1331 RecordSyncShare(×, true))); | 1312 RecordSyncShare(×, true))); |
| 1332 scheduler()->OnCredentialsUpdated(); | 1313 scheduler()->OnCredentialsUpdated(); |
| 1333 connection()->SetServerStatus(HttpResponse::SERVER_CONNECTION_OK); | 1314 connection()->SetServerStatus(HttpResponse::SERVER_CONNECTION_OK); |
| 1334 RunLoop(); | 1315 RunLoop(); |
| 1335 StopSyncScheduler(); | 1316 StopSyncScheduler(); |
| 1336 } | 1317 } |
| 1337 | 1318 |
| 1338 TEST_F(SyncSchedulerTest, SuccessfulRetry) { | 1319 TEST_F(SyncSchedulerTest, SuccessfulRetry) { |
| 1339 StartSyncScheduler(base::Time()); | 1320 StartSyncScheduler(base::Time()); |
| 1340 | 1321 |
| 1341 SyncShareTimes times; | 1322 SyncShareTimes times; |
| 1342 base::TimeDelta delay = base::TimeDelta::FromMilliseconds(10); | 1323 base::TimeDelta delay = base::TimeDelta::FromMilliseconds(10); |
| 1343 scheduler()->OnReceivedGuRetryDelay(delay); | 1324 scheduler()->OnReceivedGuRetryDelay(delay); |
| 1344 EXPECT_EQ(delay, GetRetryTimerDelay()); | 1325 EXPECT_EQ(delay, GetRetryTimerDelay()); |
| 1345 | 1326 |
| 1346 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 1327 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 1347 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 1328 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), |
| 1348 RecordSyncShare(×, true))); | 1329 RecordSyncShare(×, true))); |
| 1349 | 1330 |
| 1350 // Run to wait for retrying. | 1331 // Run to wait for retrying. |
| 1351 RunLoop(); | 1332 RunLoop(); |
| 1352 | 1333 |
| 1353 StopSyncScheduler(); | 1334 StopSyncScheduler(); |
| 1354 } | 1335 } |
| 1355 | 1336 |
| 1356 TEST_F(SyncSchedulerTest, FailedRetry) { | 1337 TEST_F(SyncSchedulerTest, FailedRetry) { |
| 1357 SyncShareTimes times; | 1338 SyncShareTimes times; |
| 1358 | 1339 |
| 1359 UseMockDelayProvider(); | 1340 UseMockDelayProvider(); |
| 1360 EXPECT_CALL(*delay(), GetDelay(_)) | 1341 EXPECT_CALL(*delay(), GetDelay(_)) |
| 1361 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(10))); | 1342 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(10))); |
| 1362 | 1343 |
| 1363 StartSyncScheduler(base::Time()); | 1344 StartSyncScheduler(base::Time()); |
| 1364 | 1345 |
| 1365 base::TimeDelta delay = base::TimeDelta::FromMilliseconds(10); | 1346 base::TimeDelta delay = base::TimeDelta::FromMilliseconds(10); |
| 1366 scheduler()->OnReceivedGuRetryDelay(delay); | 1347 scheduler()->OnReceivedGuRetryDelay(delay); |
| 1367 | 1348 |
| 1368 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 1349 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 1369 .WillOnce( | 1350 .WillOnce(DoAll(Invoke(test_util::SimulateDownloadUpdatesFailed), |
| 1370 DoAll(Invoke(sessions::test_util::SimulateDownloadUpdatesFailed), | 1351 RecordSyncShare(×, false))); |
| 1371 RecordSyncShare(×, false))); | |
| 1372 | 1352 |
| 1373 // Run to wait for retrying. | 1353 // Run to wait for retrying. |
| 1374 RunLoop(); | 1354 RunLoop(); |
| 1375 | 1355 |
| 1376 EXPECT_TRUE(scheduler()->IsBackingOff()); | 1356 EXPECT_TRUE(scheduler()->IsBackingOff()); |
| 1377 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 1357 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 1378 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 1358 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), |
| 1379 RecordSyncShare(×, true))); | 1359 RecordSyncShare(×, true))); |
| 1380 | 1360 |
| 1381 // Run to wait for second retrying. | 1361 // Run to wait for second retrying. |
| 1382 RunLoop(); | 1362 RunLoop(); |
| 1383 | 1363 |
| 1384 StopSyncScheduler(); | 1364 StopSyncScheduler(); |
| 1385 } | 1365 } |
| 1386 | 1366 |
| 1387 ACTION_P2(VerifyRetryTimerDelay, scheduler_test, expected_delay) { | 1367 ACTION_P2(VerifyRetryTimerDelay, scheduler_test, expected_delay) { |
| 1388 EXPECT_EQ(expected_delay, scheduler_test->GetRetryTimerDelay()); | 1368 EXPECT_EQ(expected_delay, scheduler_test->GetRetryTimerDelay()); |
| 1389 } | 1369 } |
| 1390 | 1370 |
| 1391 TEST_F(SyncSchedulerTest, ReceiveNewRetryDelay) { | 1371 TEST_F(SyncSchedulerTest, ReceiveNewRetryDelay) { |
| 1392 StartSyncScheduler(base::Time()); | 1372 StartSyncScheduler(base::Time()); |
| 1393 | 1373 |
| 1394 SyncShareTimes times; | 1374 SyncShareTimes times; |
| 1395 base::TimeDelta delay1 = base::TimeDelta::FromMilliseconds(100); | 1375 base::TimeDelta delay1 = base::TimeDelta::FromMilliseconds(100); |
| 1396 base::TimeDelta delay2 = base::TimeDelta::FromMilliseconds(200); | 1376 base::TimeDelta delay2 = base::TimeDelta::FromMilliseconds(200); |
| 1397 | 1377 |
| 1398 scheduler()->ScheduleLocalNudge(ModelTypeSet(THEMES), FROM_HERE); | 1378 scheduler()->ScheduleLocalNudge(ModelTypeSet(THEMES), FROM_HERE); |
| 1399 scheduler()->OnReceivedGuRetryDelay(delay1); | 1379 scheduler()->OnReceivedGuRetryDelay(delay1); |
| 1400 EXPECT_EQ(delay1, GetRetryTimerDelay()); | 1380 EXPECT_EQ(delay1, GetRetryTimerDelay()); |
| 1401 | 1381 |
| 1402 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 1382 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 1403 .WillOnce(DoAll( | 1383 .WillOnce( |
| 1404 WithoutArgs(VerifyRetryTimerDelay(this, delay1)), | 1384 DoAll(WithoutArgs(VerifyRetryTimerDelay(this, delay1)), |
| 1405 WithArg<2>(sessions::test_util::SimulateGuRetryDelayCommand(delay2)), | 1385 WithArg<2>(test_util::SimulateGuRetryDelayCommand(delay2)), |
| 1406 RecordSyncShare(×, true))); | 1386 RecordSyncShare(×, true))); |
| 1407 | 1387 |
| 1408 // Run nudge GU. | 1388 // Run nudge GU. |
| 1409 RunLoop(); | 1389 RunLoop(); |
| 1410 EXPECT_EQ(delay2, GetRetryTimerDelay()); | 1390 EXPECT_EQ(delay2, GetRetryTimerDelay()); |
| 1411 | 1391 |
| 1412 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 1392 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 1413 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 1393 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), |
| 1414 RecordSyncShare(×, true))); | 1394 RecordSyncShare(×, true))); |
| 1415 | 1395 |
| 1416 // Run to wait for retrying. | 1396 // Run to wait for retrying. |
| 1417 RunLoop(); | 1397 RunLoop(); |
| 1418 | 1398 |
| 1419 StopSyncScheduler(); | 1399 StopSyncScheduler(); |
| 1420 } | 1400 } |
| 1421 | 1401 |
| 1422 TEST_F(SyncSchedulerTest, ScheduleClearServerData_Succeeds) { | 1402 TEST_F(SyncSchedulerTest, ScheduleClearServerData_Succeeds) { |
| 1423 StartSyncConfiguration(); | 1403 StartSyncConfiguration(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1449 ASSERT_TRUE(scheduler()->IsBackingOff()); | 1429 ASSERT_TRUE(scheduler()->IsBackingOff()); |
| 1450 | 1430 |
| 1451 // Now succeed. | 1431 // Now succeed. |
| 1452 connection()->SetServerReachable(); | 1432 connection()->SetServerReachable(); |
| 1453 PumpLoopFor(2 * delta); | 1433 PumpLoopFor(2 * delta); |
| 1454 ASSERT_EQ(1, success_counter.times_called()); | 1434 ASSERT_EQ(1, success_counter.times_called()); |
| 1455 ASSERT_FALSE(scheduler()->IsBackingOff()); | 1435 ASSERT_FALSE(scheduler()->IsBackingOff()); |
| 1456 } | 1436 } |
| 1457 | 1437 |
| 1458 } // namespace syncer | 1438 } // namespace syncer |
| OLD | NEW |