| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/sync/engine_impl/sync_scheduler_impl.h" |
| 6 |
| 5 #include <stddef.h> | 7 #include <stddef.h> |
| 6 #include <stdint.h> | 8 #include <stdint.h> |
| 7 | 9 |
| 8 #include "base/bind.h" | 10 #include "base/bind.h" |
| 9 #include "base/callback.h" | |
| 10 #include "base/compiler_specific.h" | |
| 11 #include "base/location.h" | 11 #include "base/location.h" |
| 12 #include "base/memory/weak_ptr.h" | |
| 13 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 14 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
| 15 #include "base/test/test_timeouts.h" | 14 #include "base/test/test_timeouts.h" |
| 16 #include "base/threading/thread_task_runner_handle.h" | 15 #include "base/threading/thread_task_runner_handle.h" |
| 17 #include "components/sync/base/cancelation_signal.h" | 16 #include "components/sync/base/cancelation_signal.h" |
| 18 #include "components/sync/base/extensions_activity.h" | 17 #include "components/sync/base/extensions_activity.h" |
| 19 #include "components/sync/base/model_type_test_util.h" | 18 #include "components/sync/base/model_type_test_util.h" |
| 20 #include "components/sync/engine_impl/backoff_delay_provider.h" | 19 #include "components/sync/engine_impl/backoff_delay_provider.h" |
| 21 #include "components/sync/engine_impl/cycle/test_util.h" | 20 #include "components/sync/engine_impl/cycle/test_util.h" |
| 22 #include "components/sync/engine_impl/sync_scheduler_impl.h" | |
| 23 #include "components/sync/engine_impl/syncer.h" | |
| 24 #include "components/sync/test/callback_counter.h" | 21 #include "components/sync/test/callback_counter.h" |
| 25 #include "components/sync/test/engine/fake_model_worker.h" | 22 #include "components/sync/test/engine/fake_model_worker.h" |
| 26 #include "components/sync/test/engine/mock_connection_manager.h" | 23 #include "components/sync/test/engine/mock_connection_manager.h" |
| 27 #include "components/sync/test/engine/mock_nudge_handler.h" | 24 #include "components/sync/test/engine/mock_nudge_handler.h" |
| 28 #include "components/sync/test/engine/test_directory_setter_upper.h" | 25 #include "components/sync/test/engine/test_directory_setter_upper.h" |
| 29 #include "components/sync/test/mock_invalidation.h" | 26 #include "components/sync/test/mock_invalidation.h" |
| 30 #include "testing/gmock/include/gmock/gmock.h" | 27 #include "testing/gmock/include/gmock/gmock.h" |
| 31 #include "testing/gtest/include/gtest/gtest.h" | 28 #include "testing/gtest/include/gtest/gtest.h" |
| 32 | 29 |
| 33 using base::TimeDelta; | 30 using base::TimeDelta; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 | 98 |
| 102 // Test harness for the SyncScheduler. Test the delays and backoff timers used | 99 // Test harness for the SyncScheduler. Test the delays and backoff timers used |
| 103 // in response to various events. | 100 // in response to various events. |
| 104 // | 101 // |
| 105 // These tests execute in real time with real timers. We try to keep the | 102 // These tests execute in real time with real timers. We try to keep the |
| 106 // delays short, but there is a limit to how short we can make them. The | 103 // delays short, but there is a limit to how short we can make them. The |
| 107 // timers on some platforms (ie. Windows) have a timer resolution greater than | 104 // timers on some platforms (ie. Windows) have a timer resolution greater than |
| 108 // 1ms. Using 1ms delays may result in test flakiness. | 105 // 1ms. Using 1ms delays may result in test flakiness. |
| 109 // | 106 // |
| 110 // See crbug.com/402212 for more info. | 107 // See crbug.com/402212 for more info. |
| 111 class SyncSchedulerTest : public testing::Test { | 108 class SyncSchedulerImplTest : public testing::Test { |
| 112 public: | 109 public: |
| 113 SyncSchedulerTest() : syncer_(NULL), delay_(NULL), weak_ptr_factory_(this) {} | 110 SyncSchedulerImplTest() |
| 111 : syncer_(NULL), delay_(NULL), weak_ptr_factory_(this) {} |
| 114 | 112 |
| 115 class MockDelayProvider : public BackoffDelayProvider { | 113 class MockDelayProvider : public BackoffDelayProvider { |
| 116 public: | 114 public: |
| 117 MockDelayProvider() | 115 MockDelayProvider() |
| 118 : BackoffDelayProvider( | 116 : BackoffDelayProvider( |
| 119 TimeDelta::FromSeconds(kInitialBackoffRetrySeconds), | 117 TimeDelta::FromSeconds(kInitialBackoffRetrySeconds), |
| 120 TimeDelta::FromSeconds(kInitialBackoffImmediateRetrySeconds)) {} | 118 TimeDelta::FromSeconds(kInitialBackoffImmediateRetrySeconds)) {} |
| 121 | 119 |
| 122 MOCK_METHOD1(GetDelay, TimeDelta(const TimeDelta&)); | 120 MOCK_METHOD1(GetDelay, TimeDelta(const TimeDelta&)); |
| 123 }; | 121 }; |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 scheduler()->Start(SyncScheduler::CONFIGURATION_MODE, base::Time()); | 192 scheduler()->Start(SyncScheduler::CONFIGURATION_MODE, base::Time()); |
| 195 } | 193 } |
| 196 | 194 |
| 197 void StartSyncScheduler(base::Time last_poll_time) { | 195 void StartSyncScheduler(base::Time last_poll_time) { |
| 198 scheduler()->Start(SyncScheduler::NORMAL_MODE, last_poll_time); | 196 scheduler()->Start(SyncScheduler::NORMAL_MODE, last_poll_time); |
| 199 } | 197 } |
| 200 | 198 |
| 201 // This stops the scheduler synchronously. | 199 // This stops the scheduler synchronously. |
| 202 void StopSyncScheduler() { | 200 void StopSyncScheduler() { |
| 203 base::ThreadTaskRunnerHandle::Get()->PostTask( | 201 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 204 FROM_HERE, base::Bind(&SyncSchedulerTest::DoQuitLoopNow, | 202 FROM_HERE, base::Bind(&SyncSchedulerImplTest::DoQuitLoopNow, |
| 205 weak_ptr_factory_.GetWeakPtr())); | 203 weak_ptr_factory_.GetWeakPtr())); |
| 206 RunLoop(); | 204 RunLoop(); |
| 207 } | 205 } |
| 208 | 206 |
| 209 bool RunAndGetBackoff() { | 207 bool RunAndGetBackoff() { |
| 210 ModelTypeSet nudge_types(THEMES); | 208 ModelTypeSet nudge_types(THEMES); |
| 211 StartSyncScheduler(base::Time()); | 209 StartSyncScheduler(base::Time()); |
| 212 | 210 |
| 213 scheduler()->ScheduleLocalNudge(nudge_types, FROM_HERE); | 211 scheduler()->ScheduleLocalNudge(nudge_types, FROM_HERE); |
| 214 RunLoop(); | 212 RunLoop(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 std::unique_ptr<MockConnectionManager> connection_; | 245 std::unique_ptr<MockConnectionManager> connection_; |
| 248 std::unique_ptr<ModelTypeRegistry> model_type_registry_; | 246 std::unique_ptr<ModelTypeRegistry> model_type_registry_; |
| 249 std::unique_ptr<SyncCycleContext> context_; | 247 std::unique_ptr<SyncCycleContext> context_; |
| 250 std::unique_ptr<SyncSchedulerImpl> scheduler_; | 248 std::unique_ptr<SyncSchedulerImpl> scheduler_; |
| 251 MockNudgeHandler mock_nudge_handler_; | 249 MockNudgeHandler mock_nudge_handler_; |
| 252 MockSyncer* syncer_; | 250 MockSyncer* syncer_; |
| 253 MockDelayProvider* delay_; | 251 MockDelayProvider* delay_; |
| 254 std::vector<scoped_refptr<ModelSafeWorker>> workers_; | 252 std::vector<scoped_refptr<ModelSafeWorker>> workers_; |
| 255 scoped_refptr<ExtensionsActivity> extensions_activity_; | 253 scoped_refptr<ExtensionsActivity> extensions_activity_; |
| 256 ModelSafeRoutingInfo routing_info_; | 254 ModelSafeRoutingInfo routing_info_; |
| 257 base::WeakPtrFactory<SyncSchedulerTest> weak_ptr_factory_; | 255 base::WeakPtrFactory<SyncSchedulerImplTest> weak_ptr_factory_; |
| 258 }; | 256 }; |
| 259 | 257 |
| 260 void RecordSyncShareImpl(SyncShareTimes* times) { | 258 void RecordSyncShareImpl(SyncShareTimes* times) { |
| 261 times->push_back(TimeTicks::Now()); | 259 times->push_back(TimeTicks::Now()); |
| 262 } | 260 } |
| 263 | 261 |
| 264 ACTION_P2(RecordSyncShare, times, success) { | 262 ACTION_P2(RecordSyncShare, times, success) { |
| 265 RecordSyncShareImpl(times); | 263 RecordSyncShareImpl(times); |
| 266 if (base::MessageLoop::current()->is_running()) | 264 if (base::MessageLoop::current()->is_running()) |
| 267 QuitLoopNow(); | 265 QuitLoopNow(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 287 QuitLoopNow(); | 285 QuitLoopNow(); |
| 288 return true; | 286 return true; |
| 289 } | 287 } |
| 290 | 288 |
| 291 ACTION_P(QuitLoopNowAction, success) { | 289 ACTION_P(QuitLoopNowAction, success) { |
| 292 QuitLoopNow(); | 290 QuitLoopNow(); |
| 293 return success; | 291 return success; |
| 294 } | 292 } |
| 295 | 293 |
| 296 // Test nudge scheduling. | 294 // Test nudge scheduling. |
| 297 TEST_F(SyncSchedulerTest, Nudge) { | 295 TEST_F(SyncSchedulerImplTest, Nudge) { |
| 298 SyncShareTimes times; | 296 SyncShareTimes times; |
| 299 ModelTypeSet model_types(THEMES); | 297 ModelTypeSet model_types(THEMES); |
| 300 | 298 |
| 301 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 299 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 302 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), | 300 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), |
| 303 RecordSyncShare(×, true))) | 301 RecordSyncShare(×, true))) |
| 304 .RetiresOnSaturation(); | 302 .RetiresOnSaturation(); |
| 305 | 303 |
| 306 StartSyncScheduler(base::Time()); | 304 StartSyncScheduler(base::Time()); |
| 307 | 305 |
| 308 scheduler()->ScheduleLocalNudge(model_types, FROM_HERE); | 306 scheduler()->ScheduleLocalNudge(model_types, FROM_HERE); |
| 309 RunLoop(); | 307 RunLoop(); |
| 310 | 308 |
| 311 Mock::VerifyAndClearExpectations(syncer()); | 309 Mock::VerifyAndClearExpectations(syncer()); |
| 312 | 310 |
| 313 // Make sure a second, later, nudge is unaffected by first (no coalescing). | 311 // Make sure a second, later, nudge is unaffected by first (no coalescing). |
| 314 SyncShareTimes times2; | 312 SyncShareTimes times2; |
| 315 model_types.Remove(THEMES); | 313 model_types.Remove(THEMES); |
| 316 model_types.Put(TYPED_URLS); | 314 model_types.Put(TYPED_URLS); |
| 317 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 315 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 318 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), | 316 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), |
| 319 RecordSyncShare(×2, true))); | 317 RecordSyncShare(×2, true))); |
| 320 scheduler()->ScheduleLocalNudge(model_types, FROM_HERE); | 318 scheduler()->ScheduleLocalNudge(model_types, FROM_HERE); |
| 321 RunLoop(); | 319 RunLoop(); |
| 322 } | 320 } |
| 323 | 321 |
| 324 // Make sure a regular config command is scheduled fine in the absence of any | 322 // Make sure a regular config command is scheduled fine in the absence of any |
| 325 // errors. | 323 // errors. |
| 326 TEST_F(SyncSchedulerTest, Config) { | 324 TEST_F(SyncSchedulerImplTest, Config) { |
| 327 SyncShareTimes times; | 325 SyncShareTimes times; |
| 328 const ModelTypeSet model_types(THEMES); | 326 const ModelTypeSet model_types(THEMES); |
| 329 | 327 |
| 330 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) | 328 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) |
| 331 .WillOnce(DoAll(Invoke(test_util::SimulateConfigureSuccess), | 329 .WillOnce(DoAll(Invoke(test_util::SimulateConfigureSuccess), |
| 332 RecordSyncShare(×, true))); | 330 RecordSyncShare(×, true))); |
| 333 | 331 |
| 334 StartSyncConfiguration(); | 332 StartSyncConfiguration(); |
| 335 | 333 |
| 336 CallbackCounter ready_counter; | 334 CallbackCounter ready_counter; |
| 337 CallbackCounter retry_counter; | 335 CallbackCounter retry_counter; |
| 338 ConfigurationParams params( | 336 ConfigurationParams params( |
| 339 GetUpdatesCallerInfo::RECONFIGURATION, model_types, | 337 GetUpdatesCallerInfo::RECONFIGURATION, model_types, |
| 340 TypesToRoutingInfo(model_types), | 338 TypesToRoutingInfo(model_types), |
| 341 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), | 339 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), |
| 342 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); | 340 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); |
| 343 scheduler()->ScheduleConfiguration(params); | 341 scheduler()->ScheduleConfiguration(params); |
| 344 PumpLoop(); | 342 PumpLoop(); |
| 345 ASSERT_EQ(1, ready_counter.times_called()); | 343 ASSERT_EQ(1, ready_counter.times_called()); |
| 346 ASSERT_EQ(0, retry_counter.times_called()); | 344 ASSERT_EQ(0, retry_counter.times_called()); |
| 347 } | 345 } |
| 348 | 346 |
| 349 // Simulate a failure and make sure the config request is retried. | 347 // Simulate a failure and make sure the config request is retried. |
| 350 TEST_F(SyncSchedulerTest, ConfigWithBackingOff) { | 348 TEST_F(SyncSchedulerImplTest, ConfigWithBackingOff) { |
| 351 UseMockDelayProvider(); | 349 UseMockDelayProvider(); |
| 352 EXPECT_CALL(*delay(), GetDelay(_)) | 350 EXPECT_CALL(*delay(), GetDelay(_)) |
| 353 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(20))); | 351 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(20))); |
| 354 SyncShareTimes times; | 352 SyncShareTimes times; |
| 355 const ModelTypeSet model_types(THEMES); | 353 const ModelTypeSet model_types(THEMES); |
| 356 | 354 |
| 357 StartSyncConfiguration(); | 355 StartSyncConfiguration(); |
| 358 | 356 |
| 359 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) | 357 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) |
| 360 .WillOnce(DoAll(Invoke(test_util::SimulateConfigureFailed), | 358 .WillOnce(DoAll(Invoke(test_util::SimulateConfigureFailed), |
| (...skipping 24 matching lines...) Expand all Loading... |
| 385 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) | 383 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) |
| 386 .WillOnce(DoAll(Invoke(test_util::SimulateConfigureSuccess), | 384 .WillOnce(DoAll(Invoke(test_util::SimulateConfigureSuccess), |
| 387 RecordSyncShare(×, true))); | 385 RecordSyncShare(×, true))); |
| 388 RunLoop(); | 386 RunLoop(); |
| 389 | 387 |
| 390 ASSERT_EQ(1, ready_counter.times_called()); | 388 ASSERT_EQ(1, ready_counter.times_called()); |
| 391 } | 389 } |
| 392 | 390 |
| 393 // Simuilate SyncSchedulerImpl::Stop being called in the middle of Configure. | 391 // Simuilate SyncSchedulerImpl::Stop being called in the middle of Configure. |
| 394 // This can happen if server returns NOT_MY_BIRTHDAY. | 392 // This can happen if server returns NOT_MY_BIRTHDAY. |
| 395 TEST_F(SyncSchedulerTest, ConfigWithStop) { | 393 TEST_F(SyncSchedulerImplTest, ConfigWithStop) { |
| 396 UseMockDelayProvider(); | 394 UseMockDelayProvider(); |
| 397 EXPECT_CALL(*delay(), GetDelay(_)) | 395 EXPECT_CALL(*delay(), GetDelay(_)) |
| 398 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(20))); | 396 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(20))); |
| 399 SyncShareTimes times; | 397 SyncShareTimes times; |
| 400 const ModelTypeSet model_types(THEMES); | 398 const ModelTypeSet model_types(THEMES); |
| 401 | 399 |
| 402 StartSyncConfiguration(); | 400 StartSyncConfiguration(); |
| 403 | 401 |
| 404 // Make ConfigureSyncShare call scheduler->Stop(). It is not supposed to call | 402 // Make ConfigureSyncShare call scheduler->Stop(). It is not supposed to call |
| 405 // retry_task or dereference configuration params. | 403 // retry_task or dereference configuration params. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 416 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), | 414 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), |
| 417 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); | 415 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); |
| 418 scheduler()->ScheduleConfiguration(params); | 416 scheduler()->ScheduleConfiguration(params); |
| 419 PumpLoop(); | 417 PumpLoop(); |
| 420 ASSERT_EQ(0, ready_counter.times_called()); | 418 ASSERT_EQ(0, ready_counter.times_called()); |
| 421 ASSERT_EQ(0, retry_counter.times_called()); | 419 ASSERT_EQ(0, retry_counter.times_called()); |
| 422 } | 420 } |
| 423 | 421 |
| 424 // Issue a nudge when the config has failed. Make sure both the config and | 422 // Issue a nudge when the config has failed. Make sure both the config and |
| 425 // nudge are executed. | 423 // nudge are executed. |
| 426 TEST_F(SyncSchedulerTest, NudgeWithConfigWithBackingOff) { | 424 TEST_F(SyncSchedulerImplTest, NudgeWithConfigWithBackingOff) { |
| 427 const ModelTypeSet model_types(THEMES); | 425 const ModelTypeSet model_types(THEMES); |
| 428 UseMockDelayProvider(); | 426 UseMockDelayProvider(); |
| 429 EXPECT_CALL(*delay(), GetDelay(_)) | 427 EXPECT_CALL(*delay(), GetDelay(_)) |
| 430 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(50))); | 428 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(50))); |
| 431 SyncShareTimes times; | 429 SyncShareTimes times; |
| 432 | 430 |
| 433 StartSyncConfiguration(); | 431 StartSyncConfiguration(); |
| 434 | 432 |
| 435 // Request a configure and make sure it fails. | 433 // Request a configure and make sure it fails. |
| 436 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) | 434 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 | 467 |
| 470 // Now change the mode so nudge can execute. | 468 // Now change the mode so nudge can execute. |
| 471 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 469 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 472 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), | 470 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), |
| 473 RecordSyncShare(×, true))); | 471 RecordSyncShare(×, true))); |
| 474 StartSyncScheduler(base::Time()); | 472 StartSyncScheduler(base::Time()); |
| 475 PumpLoop(); | 473 PumpLoop(); |
| 476 } | 474 } |
| 477 | 475 |
| 478 // Test that nudges are coalesced. | 476 // Test that nudges are coalesced. |
| 479 TEST_F(SyncSchedulerTest, NudgeCoalescing) { | 477 TEST_F(SyncSchedulerImplTest, NudgeCoalescing) { |
| 480 StartSyncScheduler(base::Time()); | 478 StartSyncScheduler(base::Time()); |
| 481 | 479 |
| 482 SyncShareTimes times; | 480 SyncShareTimes times; |
| 483 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 481 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 484 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), | 482 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), |
| 485 RecordSyncShare(×, true))); | 483 RecordSyncShare(×, true))); |
| 486 const ModelTypeSet types1(THEMES), types2(TYPED_URLS), types3(THEMES); | 484 const ModelTypeSet types1(THEMES), types2(TYPED_URLS), types3(THEMES); |
| 487 TimeTicks optimal_time = TimeTicks::Now() + default_delay(); | 485 TimeTicks optimal_time = TimeTicks::Now() + default_delay(); |
| 488 scheduler()->ScheduleLocalNudge(types1, FROM_HERE); | 486 scheduler()->ScheduleLocalNudge(types1, FROM_HERE); |
| 489 scheduler()->ScheduleLocalNudge(types2, FROM_HERE); | 487 scheduler()->ScheduleLocalNudge(types2, FROM_HERE); |
| 490 RunLoop(); | 488 RunLoop(); |
| 491 | 489 |
| 492 ASSERT_EQ(1U, times.size()); | 490 ASSERT_EQ(1U, times.size()); |
| 493 EXPECT_GE(times[0], optimal_time); | 491 EXPECT_GE(times[0], optimal_time); |
| 494 | 492 |
| 495 Mock::VerifyAndClearExpectations(syncer()); | 493 Mock::VerifyAndClearExpectations(syncer()); |
| 496 | 494 |
| 497 SyncShareTimes times2; | 495 SyncShareTimes times2; |
| 498 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 496 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 499 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), | 497 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), |
| 500 RecordSyncShare(×2, true))); | 498 RecordSyncShare(×2, true))); |
| 501 scheduler()->ScheduleLocalNudge(types3, FROM_HERE); | 499 scheduler()->ScheduleLocalNudge(types3, FROM_HERE); |
| 502 RunLoop(); | 500 RunLoop(); |
| 503 } | 501 } |
| 504 | 502 |
| 505 // Test that nudges are coalesced. | 503 // Test that nudges are coalesced. |
| 506 TEST_F(SyncSchedulerTest, NudgeCoalescingWithDifferentTimings) { | 504 TEST_F(SyncSchedulerImplTest, NudgeCoalescingWithDifferentTimings) { |
| 507 StartSyncScheduler(base::Time()); | 505 StartSyncScheduler(base::Time()); |
| 508 | 506 |
| 509 SyncShareTimes times; | 507 SyncShareTimes times; |
| 510 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 508 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 511 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), | 509 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), |
| 512 RecordSyncShare(×, true))); | 510 RecordSyncShare(×, true))); |
| 513 ModelTypeSet types1(THEMES), types2(TYPED_URLS), types3; | 511 ModelTypeSet types1(THEMES), types2(TYPED_URLS), types3; |
| 514 | 512 |
| 515 // Create a huge time delay. | 513 // Create a huge time delay. |
| 516 TimeDelta delay = TimeDelta::FromDays(1); | 514 TimeDelta delay = TimeDelta::FromDays(1); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 527 RunLoop(); | 525 RunLoop(); |
| 528 Mock::VerifyAndClearExpectations(syncer()); | 526 Mock::VerifyAndClearExpectations(syncer()); |
| 529 | 527 |
| 530 // Make sure the sync happened at the right time. | 528 // Make sure the sync happened at the right time. |
| 531 ASSERT_EQ(1U, times.size()); | 529 ASSERT_EQ(1U, times.size()); |
| 532 EXPECT_GE(times[0], min_time); | 530 EXPECT_GE(times[0], min_time); |
| 533 EXPECT_LE(times[0], max_time); | 531 EXPECT_LE(times[0], max_time); |
| 534 } | 532 } |
| 535 | 533 |
| 536 // Test nudge scheduling. | 534 // Test nudge scheduling. |
| 537 TEST_F(SyncSchedulerTest, NudgeWithStates) { | 535 TEST_F(SyncSchedulerImplTest, NudgeWithStates) { |
| 538 StartSyncScheduler(base::Time()); | 536 StartSyncScheduler(base::Time()); |
| 539 | 537 |
| 540 SyncShareTimes times1; | 538 SyncShareTimes times1; |
| 541 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 539 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 542 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), | 540 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), |
| 543 RecordSyncShare(×1, true))) | 541 RecordSyncShare(×1, true))) |
| 544 .RetiresOnSaturation(); | 542 .RetiresOnSaturation(); |
| 545 scheduler()->ScheduleInvalidationNudge(THEMES, BuildInvalidation(10, "test"), | 543 scheduler()->ScheduleInvalidationNudge(THEMES, BuildInvalidation(10, "test"), |
| 546 FROM_HERE); | 544 FROM_HERE); |
| 547 RunLoop(); | 545 RunLoop(); |
| 548 | 546 |
| 549 Mock::VerifyAndClearExpectations(syncer()); | 547 Mock::VerifyAndClearExpectations(syncer()); |
| 550 | 548 |
| 551 // Make sure a second, later, nudge is unaffected by first (no coalescing). | 549 // Make sure a second, later, nudge is unaffected by first (no coalescing). |
| 552 SyncShareTimes times2; | 550 SyncShareTimes times2; |
| 553 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 551 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 554 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), | 552 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), |
| 555 RecordSyncShare(×2, true))); | 553 RecordSyncShare(×2, true))); |
| 556 scheduler()->ScheduleInvalidationNudge( | 554 scheduler()->ScheduleInvalidationNudge( |
| 557 TYPED_URLS, BuildInvalidation(10, "test2"), FROM_HERE); | 555 TYPED_URLS, BuildInvalidation(10, "test2"), FROM_HERE); |
| 558 RunLoop(); | 556 RunLoop(); |
| 559 } | 557 } |
| 560 | 558 |
| 561 // Test that polling works as expected. | 559 // Test that polling works as expected. |
| 562 TEST_F(SyncSchedulerTest, Polling) { | 560 TEST_F(SyncSchedulerImplTest, Polling) { |
| 563 SyncShareTimes times; | 561 SyncShareTimes times; |
| 564 TimeDelta poll_interval(TimeDelta::FromMilliseconds(30)); | 562 TimeDelta poll_interval(TimeDelta::FromMilliseconds(30)); |
| 565 EXPECT_CALL(*syncer(), PollSyncShare(_, _)) | 563 EXPECT_CALL(*syncer(), PollSyncShare(_, _)) |
| 566 .Times(AtLeast(kMinNumSamples)) | 564 .Times(AtLeast(kMinNumSamples)) |
| 567 .WillRepeatedly( | 565 .WillRepeatedly( |
| 568 DoAll(Invoke(test_util::SimulatePollSuccess), | 566 DoAll(Invoke(test_util::SimulatePollSuccess), |
| 569 RecordSyncShareMultiple(×, kMinNumSamples, true))); | 567 RecordSyncShareMultiple(×, kMinNumSamples, true))); |
| 570 | 568 |
| 571 scheduler()->OnReceivedLongPollIntervalUpdate(poll_interval); | 569 scheduler()->OnReceivedLongPollIntervalUpdate(poll_interval); |
| 572 | 570 |
| 573 TimeTicks optimal_start = TimeTicks::Now() + poll_interval; | 571 TimeTicks optimal_start = TimeTicks::Now() + poll_interval; |
| 574 StartSyncScheduler(base::Time()); | 572 StartSyncScheduler(base::Time()); |
| 575 | 573 |
| 576 // Run again to wait for polling. | 574 // Run again to wait for polling. |
| 577 RunLoop(); | 575 RunLoop(); |
| 578 | 576 |
| 579 StopSyncScheduler(); | 577 StopSyncScheduler(); |
| 580 AnalyzePollRun(times, kMinNumSamples, optimal_start, poll_interval); | 578 AnalyzePollRun(times, kMinNumSamples, optimal_start, poll_interval); |
| 581 } | 579 } |
| 582 | 580 |
| 583 // Test that we reuse the previous poll time on startup, triggering the first | 581 // Test that we reuse the previous poll time on startup, triggering the first |
| 584 // poll based on when the last one happened. Subsequent polls should have the | 582 // poll based on when the last one happened. Subsequent polls should have the |
| 585 // normal delay. | 583 // normal delay. |
| 586 TEST_F(SyncSchedulerTest, PollingPersistence) { | 584 TEST_F(SyncSchedulerImplTest, PollingPersistence) { |
| 587 SyncShareTimes times; | 585 SyncShareTimes times; |
| 588 // Use a large poll interval that wouldn't normally get hit on its own for | 586 // Use a large poll interval that wouldn't normally get hit on its own for |
| 589 // some time yet. | 587 // some time yet. |
| 590 TimeDelta poll_interval(TimeDelta::FromMilliseconds(500)); | 588 TimeDelta poll_interval(TimeDelta::FromMilliseconds(500)); |
| 591 EXPECT_CALL(*syncer(), PollSyncShare(_, _)) | 589 EXPECT_CALL(*syncer(), PollSyncShare(_, _)) |
| 592 .Times(AtLeast(kMinNumSamples)) | 590 .Times(AtLeast(kMinNumSamples)) |
| 593 .WillRepeatedly( | 591 .WillRepeatedly( |
| 594 DoAll(Invoke(test_util::SimulatePollSuccess), | 592 DoAll(Invoke(test_util::SimulatePollSuccess), |
| 595 RecordSyncShareMultiple(×, kMinNumSamples, true))); | 593 RecordSyncShareMultiple(×, kMinNumSamples, true))); |
| 596 | 594 |
| 597 scheduler()->OnReceivedLongPollIntervalUpdate(poll_interval); | 595 scheduler()->OnReceivedLongPollIntervalUpdate(poll_interval); |
| 598 | 596 |
| 599 // Set the start time to now, as the poll was overdue. | 597 // Set the start time to now, as the poll was overdue. |
| 600 TimeTicks optimal_start = TimeTicks::Now(); | 598 TimeTicks optimal_start = TimeTicks::Now(); |
| 601 StartSyncScheduler(base::Time::Now() - poll_interval); | 599 StartSyncScheduler(base::Time::Now() - poll_interval); |
| 602 | 600 |
| 603 // Run again to wait for polling. | 601 // Run again to wait for polling. |
| 604 RunLoop(); | 602 RunLoop(); |
| 605 | 603 |
| 606 StopSyncScheduler(); | 604 StopSyncScheduler(); |
| 607 AnalyzePollRun(times, kMinNumSamples, optimal_start, poll_interval); | 605 AnalyzePollRun(times, kMinNumSamples, optimal_start, poll_interval); |
| 608 } | 606 } |
| 609 | 607 |
| 610 // Test that if the persisted poll is in the future, it's ignored (the case | 608 // Test that if the persisted poll is in the future, it's ignored (the case |
| 611 // where the local time has been modified). | 609 // where the local time has been modified). |
| 612 TEST_F(SyncSchedulerTest, PollingPersistenceBadClock) { | 610 TEST_F(SyncSchedulerImplTest, PollingPersistenceBadClock) { |
| 613 SyncShareTimes times; | 611 SyncShareTimes times; |
| 614 TimeDelta poll_interval(TimeDelta::FromMilliseconds(30)); | 612 TimeDelta poll_interval(TimeDelta::FromMilliseconds(30)); |
| 615 EXPECT_CALL(*syncer(), PollSyncShare(_, _)) | 613 EXPECT_CALL(*syncer(), PollSyncShare(_, _)) |
| 616 .Times(AtLeast(kMinNumSamples)) | 614 .Times(AtLeast(kMinNumSamples)) |
| 617 .WillRepeatedly( | 615 .WillRepeatedly( |
| 618 DoAll(Invoke(test_util::SimulatePollSuccess), | 616 DoAll(Invoke(test_util::SimulatePollSuccess), |
| 619 RecordSyncShareMultiple(×, kMinNumSamples, true))); | 617 RecordSyncShareMultiple(×, kMinNumSamples, true))); |
| 620 | 618 |
| 621 scheduler()->OnReceivedLongPollIntervalUpdate(poll_interval); | 619 scheduler()->OnReceivedLongPollIntervalUpdate(poll_interval); |
| 622 | 620 |
| 623 // Set the start time to |poll_interval| in the future. | 621 // Set the start time to |poll_interval| in the future. |
| 624 TimeTicks optimal_start = TimeTicks::Now() + poll_interval; | 622 TimeTicks optimal_start = TimeTicks::Now() + poll_interval; |
| 625 StartSyncScheduler(base::Time::Now() + base::TimeDelta::FromMinutes(10)); | 623 StartSyncScheduler(base::Time::Now() + base::TimeDelta::FromMinutes(10)); |
| 626 | 624 |
| 627 // Run again to wait for polling. | 625 // Run again to wait for polling. |
| 628 RunLoop(); | 626 RunLoop(); |
| 629 | 627 |
| 630 StopSyncScheduler(); | 628 StopSyncScheduler(); |
| 631 AnalyzePollRun(times, kMinNumSamples, optimal_start, poll_interval); | 629 AnalyzePollRun(times, kMinNumSamples, optimal_start, poll_interval); |
| 632 } | 630 } |
| 633 | 631 |
| 634 // Test that the short poll interval is used. | 632 // Test that the short poll interval is used. |
| 635 TEST_F(SyncSchedulerTest, PollNotificationsDisabled) { | 633 TEST_F(SyncSchedulerImplTest, PollNotificationsDisabled) { |
| 636 SyncShareTimes times; | 634 SyncShareTimes times; |
| 637 TimeDelta poll_interval(TimeDelta::FromMilliseconds(30)); | 635 TimeDelta poll_interval(TimeDelta::FromMilliseconds(30)); |
| 638 EXPECT_CALL(*syncer(), PollSyncShare(_, _)) | 636 EXPECT_CALL(*syncer(), PollSyncShare(_, _)) |
| 639 .Times(AtLeast(kMinNumSamples)) | 637 .Times(AtLeast(kMinNumSamples)) |
| 640 .WillRepeatedly( | 638 .WillRepeatedly( |
| 641 DoAll(Invoke(test_util::SimulatePollSuccess), | 639 DoAll(Invoke(test_util::SimulatePollSuccess), |
| 642 RecordSyncShareMultiple(×, kMinNumSamples, true))); | 640 RecordSyncShareMultiple(×, kMinNumSamples, true))); |
| 643 | 641 |
| 644 scheduler()->OnReceivedShortPollIntervalUpdate(poll_interval); | 642 scheduler()->OnReceivedShortPollIntervalUpdate(poll_interval); |
| 645 scheduler()->SetNotificationsEnabled(false); | 643 scheduler()->SetNotificationsEnabled(false); |
| 646 | 644 |
| 647 TimeTicks optimal_start = TimeTicks::Now() + poll_interval; | 645 TimeTicks optimal_start = TimeTicks::Now() + poll_interval; |
| 648 StartSyncScheduler(base::Time()); | 646 StartSyncScheduler(base::Time()); |
| 649 | 647 |
| 650 // Run again to wait for polling. | 648 // Run again to wait for polling. |
| 651 RunLoop(); | 649 RunLoop(); |
| 652 | 650 |
| 653 StopSyncScheduler(); | 651 StopSyncScheduler(); |
| 654 AnalyzePollRun(times, kMinNumSamples, optimal_start, poll_interval); | 652 AnalyzePollRun(times, kMinNumSamples, optimal_start, poll_interval); |
| 655 } | 653 } |
| 656 | 654 |
| 657 // Test that polling intervals are updated when needed. | 655 // Test that polling intervals are updated when needed. |
| 658 TEST_F(SyncSchedulerTest, PollIntervalUpdate) { | 656 TEST_F(SyncSchedulerImplTest, PollIntervalUpdate) { |
| 659 SyncShareTimes times; | 657 SyncShareTimes times; |
| 660 TimeDelta poll1(TimeDelta::FromMilliseconds(120)); | 658 TimeDelta poll1(TimeDelta::FromMilliseconds(120)); |
| 661 TimeDelta poll2(TimeDelta::FromMilliseconds(30)); | 659 TimeDelta poll2(TimeDelta::FromMilliseconds(30)); |
| 662 scheduler()->OnReceivedLongPollIntervalUpdate(poll1); | 660 scheduler()->OnReceivedLongPollIntervalUpdate(poll1); |
| 663 EXPECT_CALL(*syncer(), PollSyncShare(_, _)) | 661 EXPECT_CALL(*syncer(), PollSyncShare(_, _)) |
| 664 .Times(AtLeast(kMinNumSamples)) | 662 .Times(AtLeast(kMinNumSamples)) |
| 665 .WillOnce( | 663 .WillOnce( |
| 666 DoAll(WithArgs<0, 1>(test_util::SimulatePollIntervalUpdate(poll2)), | 664 DoAll(WithArgs<0, 1>(test_util::SimulatePollIntervalUpdate(poll2)), |
| 667 Return(true))) | 665 Return(true))) |
| 668 .WillRepeatedly(DoAll( | 666 .WillRepeatedly(DoAll( |
| 669 Invoke(test_util::SimulatePollSuccess), | 667 Invoke(test_util::SimulatePollSuccess), |
| 670 WithArg<1>(RecordSyncShareMultiple(×, kMinNumSamples, true)))); | 668 WithArg<1>(RecordSyncShareMultiple(×, kMinNumSamples, true)))); |
| 671 | 669 |
| 672 TimeTicks optimal_start = TimeTicks::Now() + poll1 + poll2; | 670 TimeTicks optimal_start = TimeTicks::Now() + poll1 + poll2; |
| 673 StartSyncScheduler(base::Time()); | 671 StartSyncScheduler(base::Time()); |
| 674 | 672 |
| 675 // Run again to wait for polling. | 673 // Run again to wait for polling. |
| 676 RunLoop(); | 674 RunLoop(); |
| 677 | 675 |
| 678 StopSyncScheduler(); | 676 StopSyncScheduler(); |
| 679 AnalyzePollRun(times, kMinNumSamples, optimal_start, poll2); | 677 AnalyzePollRun(times, kMinNumSamples, optimal_start, poll2); |
| 680 } | 678 } |
| 681 | 679 |
| 682 // Test that no syncing occurs when throttled. | 680 // Test that no syncing occurs when throttled. |
| 683 TEST_F(SyncSchedulerTest, ThrottlingDoesThrottle) { | 681 TEST_F(SyncSchedulerImplTest, ThrottlingDoesThrottle) { |
| 684 const ModelTypeSet types(THEMES); | 682 const ModelTypeSet types(THEMES); |
| 685 TimeDelta poll(TimeDelta::FromMilliseconds(20)); | 683 TimeDelta poll(TimeDelta::FromMilliseconds(20)); |
| 686 TimeDelta throttle(TimeDelta::FromMinutes(10)); | 684 TimeDelta throttle(TimeDelta::FromMinutes(10)); |
| 687 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 685 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
| 688 | 686 |
| 689 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) | 687 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) |
| 690 .WillOnce(DoAll(WithArg<2>(test_util::SimulateThrottled(throttle)), | 688 .WillOnce(DoAll(WithArg<2>(test_util::SimulateThrottled(throttle)), |
| 691 Return(false))) | 689 Return(false))) |
| 692 .WillRepeatedly(AddFailureAndQuitLoopNow()); | 690 .WillRepeatedly(AddFailureAndQuitLoopNow()); |
| 693 | 691 |
| 694 StartSyncScheduler(base::Time()); | 692 StartSyncScheduler(base::Time()); |
| 695 | 693 |
| 696 scheduler()->ScheduleLocalNudge(types, FROM_HERE); | 694 scheduler()->ScheduleLocalNudge(types, FROM_HERE); |
| 697 PumpLoop(); | 695 PumpLoop(); |
| 698 | 696 |
| 699 StartSyncConfiguration(); | 697 StartSyncConfiguration(); |
| 700 | 698 |
| 701 CallbackCounter ready_counter; | 699 CallbackCounter ready_counter; |
| 702 CallbackCounter retry_counter; | 700 CallbackCounter retry_counter; |
| 703 ConfigurationParams params( | 701 ConfigurationParams params( |
| 704 GetUpdatesCallerInfo::RECONFIGURATION, types, TypesToRoutingInfo(types), | 702 GetUpdatesCallerInfo::RECONFIGURATION, types, TypesToRoutingInfo(types), |
| 705 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), | 703 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), |
| 706 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); | 704 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); |
| 707 scheduler()->ScheduleConfiguration(params); | 705 scheduler()->ScheduleConfiguration(params); |
| 708 PumpLoop(); | 706 PumpLoop(); |
| 709 ASSERT_EQ(0, ready_counter.times_called()); | 707 ASSERT_EQ(0, ready_counter.times_called()); |
| 710 ASSERT_EQ(1, retry_counter.times_called()); | 708 ASSERT_EQ(1, retry_counter.times_called()); |
| 711 } | 709 } |
| 712 | 710 |
| 713 TEST_F(SyncSchedulerTest, ThrottlingExpiresFromPoll) { | 711 TEST_F(SyncSchedulerImplTest, ThrottlingExpiresFromPoll) { |
| 714 SyncShareTimes times; | 712 SyncShareTimes times; |
| 715 TimeDelta poll(TimeDelta::FromMilliseconds(15)); | 713 TimeDelta poll(TimeDelta::FromMilliseconds(15)); |
| 716 TimeDelta throttle1(TimeDelta::FromMilliseconds(150)); | 714 TimeDelta throttle1(TimeDelta::FromMilliseconds(150)); |
| 717 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 715 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
| 718 | 716 |
| 719 ::testing::InSequence seq; | 717 ::testing::InSequence seq; |
| 720 EXPECT_CALL(*syncer(), PollSyncShare(_, _)) | 718 EXPECT_CALL(*syncer(), PollSyncShare(_, _)) |
| 721 .WillOnce(DoAll(WithArg<1>(test_util::SimulateThrottled(throttle1)), | 719 .WillOnce(DoAll(WithArg<1>(test_util::SimulateThrottled(throttle1)), |
| 722 Return(false))) | 720 Return(false))) |
| 723 .RetiresOnSaturation(); | 721 .RetiresOnSaturation(); |
| 724 EXPECT_CALL(*syncer(), PollSyncShare(_, _)) | 722 EXPECT_CALL(*syncer(), PollSyncShare(_, _)) |
| 725 .WillRepeatedly( | 723 .WillRepeatedly( |
| 726 DoAll(Invoke(test_util::SimulatePollSuccess), | 724 DoAll(Invoke(test_util::SimulatePollSuccess), |
| 727 RecordSyncShareMultiple(×, kMinNumSamples, true))); | 725 RecordSyncShareMultiple(×, kMinNumSamples, true))); |
| 728 | 726 |
| 729 TimeTicks optimal_start = TimeTicks::Now() + poll + throttle1; | 727 TimeTicks optimal_start = TimeTicks::Now() + poll + throttle1; |
| 730 StartSyncScheduler(base::Time()); | 728 StartSyncScheduler(base::Time()); |
| 731 | 729 |
| 732 // Run again to wait for polling. | 730 // Run again to wait for polling. |
| 733 RunLoop(); | 731 RunLoop(); |
| 734 | 732 |
| 735 StopSyncScheduler(); | 733 StopSyncScheduler(); |
| 736 AnalyzePollRun(times, kMinNumSamples, optimal_start, poll); | 734 AnalyzePollRun(times, kMinNumSamples, optimal_start, poll); |
| 737 } | 735 } |
| 738 | 736 |
| 739 TEST_F(SyncSchedulerTest, ThrottlingExpiresFromNudge) { | 737 TEST_F(SyncSchedulerImplTest, ThrottlingExpiresFromNudge) { |
| 740 SyncShareTimes times; | 738 SyncShareTimes times; |
| 741 TimeDelta poll(TimeDelta::FromDays(1)); | 739 TimeDelta poll(TimeDelta::FromDays(1)); |
| 742 TimeDelta throttle1(TimeDelta::FromMilliseconds(150)); | 740 TimeDelta throttle1(TimeDelta::FromMilliseconds(150)); |
| 743 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 741 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
| 744 | 742 |
| 745 ::testing::InSequence seq; | 743 ::testing::InSequence seq; |
| 746 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 744 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 747 .WillOnce(DoAll(WithArg<2>(test_util::SimulateThrottled(throttle1)), | 745 .WillOnce(DoAll(WithArg<2>(test_util::SimulateThrottled(throttle1)), |
| 748 Return(false))) | 746 Return(false))) |
| 749 .RetiresOnSaturation(); | 747 .RetiresOnSaturation(); |
| 750 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 748 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 751 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), | 749 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), |
| 752 QuitLoopNowAction(true))); | 750 QuitLoopNowAction(true))); |
| 753 | 751 |
| 754 const ModelTypeSet types(THEMES); | 752 const ModelTypeSet types(THEMES); |
| 755 StartSyncScheduler(base::Time()); | 753 StartSyncScheduler(base::Time()); |
| 756 scheduler()->ScheduleLocalNudge(types, FROM_HERE); | 754 scheduler()->ScheduleLocalNudge(types, FROM_HERE); |
| 757 | 755 |
| 758 PumpLoop(); // To get PerformDelayedNudge called. | 756 PumpLoop(); // To get PerformDelayedNudge called. |
| 759 PumpLoop(); // To get TrySyncCycleJob called | 757 PumpLoop(); // To get TrySyncCycleJob called |
| 760 EXPECT_TRUE(scheduler()->IsCurrentlyThrottled()); | 758 EXPECT_TRUE(scheduler()->IsCurrentlyThrottled()); |
| 761 RunLoop(); | 759 RunLoop(); |
| 762 EXPECT_FALSE(scheduler()->IsCurrentlyThrottled()); | 760 EXPECT_FALSE(scheduler()->IsCurrentlyThrottled()); |
| 763 | 761 |
| 764 StopSyncScheduler(); | 762 StopSyncScheduler(); |
| 765 } | 763 } |
| 766 | 764 |
| 767 TEST_F(SyncSchedulerTest, ThrottlingExpiresFromConfigure) { | 765 TEST_F(SyncSchedulerImplTest, ThrottlingExpiresFromConfigure) { |
| 768 SyncShareTimes times; | 766 SyncShareTimes times; |
| 769 TimeDelta poll(TimeDelta::FromDays(1)); | 767 TimeDelta poll(TimeDelta::FromDays(1)); |
| 770 TimeDelta throttle1(TimeDelta::FromMilliseconds(150)); | 768 TimeDelta throttle1(TimeDelta::FromMilliseconds(150)); |
| 771 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 769 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
| 772 | 770 |
| 773 ::testing::InSequence seq; | 771 ::testing::InSequence seq; |
| 774 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) | 772 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) |
| 775 .WillOnce(DoAll(WithArg<2>(test_util::SimulateThrottled(throttle1)), | 773 .WillOnce(DoAll(WithArg<2>(test_util::SimulateThrottled(throttle1)), |
| 776 Return(false))) | 774 Return(false))) |
| 777 .RetiresOnSaturation(); | 775 .RetiresOnSaturation(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 793 EXPECT_EQ(0, ready_counter.times_called()); | 791 EXPECT_EQ(0, ready_counter.times_called()); |
| 794 EXPECT_EQ(1, retry_counter.times_called()); | 792 EXPECT_EQ(1, retry_counter.times_called()); |
| 795 EXPECT_TRUE(scheduler()->IsCurrentlyThrottled()); | 793 EXPECT_TRUE(scheduler()->IsCurrentlyThrottled()); |
| 796 | 794 |
| 797 RunLoop(); | 795 RunLoop(); |
| 798 EXPECT_FALSE(scheduler()->IsCurrentlyThrottled()); | 796 EXPECT_FALSE(scheduler()->IsCurrentlyThrottled()); |
| 799 | 797 |
| 800 StopSyncScheduler(); | 798 StopSyncScheduler(); |
| 801 } | 799 } |
| 802 | 800 |
| 803 TEST_F(SyncSchedulerTest, TypeThrottlingBlocksNudge) { | 801 TEST_F(SyncSchedulerImplTest, TypeThrottlingBlocksNudge) { |
| 804 UseMockDelayProvider(); | 802 UseMockDelayProvider(); |
| 805 EXPECT_CALL(*delay(), GetDelay(_)).WillRepeatedly(Return(default_delay())); | 803 EXPECT_CALL(*delay(), GetDelay(_)).WillRepeatedly(Return(default_delay())); |
| 806 | 804 |
| 807 TimeDelta poll(TimeDelta::FromDays(1)); | 805 TimeDelta poll(TimeDelta::FromDays(1)); |
| 808 TimeDelta throttle1(TimeDelta::FromSeconds(60)); | 806 TimeDelta throttle1(TimeDelta::FromSeconds(60)); |
| 809 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 807 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
| 810 | 808 |
| 811 const ModelTypeSet types(THEMES); | 809 const ModelTypeSet types(THEMES); |
| 812 | 810 |
| 813 ::testing::InSequence seq; | 811 ::testing::InSequence seq; |
| 814 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 812 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 815 .WillOnce( | 813 .WillOnce( |
| 816 DoAll(WithArg<2>(test_util::SimulateTypesThrottled(types, throttle1)), | 814 DoAll(WithArg<2>(test_util::SimulateTypesThrottled(types, throttle1)), |
| 817 Return(false))) | 815 Return(false))) |
| 818 .RetiresOnSaturation(); | 816 .RetiresOnSaturation(); |
| 819 | 817 |
| 820 StartSyncScheduler(base::Time()); | 818 StartSyncScheduler(base::Time()); |
| 821 scheduler()->ScheduleLocalNudge(types, FROM_HERE); | 819 scheduler()->ScheduleLocalNudge(types, FROM_HERE); |
| 822 PumpLoop(); // To get PerformDelayedNudge called. | 820 PumpLoop(); // To get PerformDelayedNudge called. |
| 823 PumpLoop(); // To get TrySyncCycleJob called | 821 PumpLoop(); // To get TrySyncCycleJob called |
| 824 EXPECT_TRUE(GetThrottledTypes().HasAll(types)); | 822 EXPECT_TRUE(GetThrottledTypes().HasAll(types)); |
| 825 | 823 |
| 826 // This won't cause a sync cycle because the types are throttled. | 824 // This won't cause a sync cycle because the types are throttled. |
| 827 scheduler()->ScheduleLocalNudge(types, FROM_HERE); | 825 scheduler()->ScheduleLocalNudge(types, FROM_HERE); |
| 828 PumpLoop(); | 826 PumpLoop(); |
| 829 | 827 |
| 830 StopSyncScheduler(); | 828 StopSyncScheduler(); |
| 831 } | 829 } |
| 832 | 830 |
| 833 TEST_F(SyncSchedulerTest, TypeThrottlingDoesBlockOtherSources) { | 831 TEST_F(SyncSchedulerImplTest, TypeThrottlingDoesBlockOtherSources) { |
| 834 UseMockDelayProvider(); | 832 UseMockDelayProvider(); |
| 835 EXPECT_CALL(*delay(), GetDelay(_)).WillRepeatedly(Return(default_delay())); | 833 EXPECT_CALL(*delay(), GetDelay(_)).WillRepeatedly(Return(default_delay())); |
| 836 | 834 |
| 837 SyncShareTimes times; | 835 SyncShareTimes times; |
| 838 TimeDelta poll(TimeDelta::FromDays(1)); | 836 TimeDelta poll(TimeDelta::FromDays(1)); |
| 839 TimeDelta throttle1(TimeDelta::FromSeconds(60)); | 837 TimeDelta throttle1(TimeDelta::FromSeconds(60)); |
| 840 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 838 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
| 841 | 839 |
| 842 const ModelTypeSet throttled_types(THEMES); | 840 const ModelTypeSet throttled_types(THEMES); |
| 843 const ModelTypeSet unthrottled_types(PREFERENCES); | 841 const ModelTypeSet unthrottled_types(PREFERENCES); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 871 .WillRepeatedly(DoAll(Invoke(test_util::SimulateNormalSuccess), | 869 .WillRepeatedly(DoAll(Invoke(test_util::SimulateNormalSuccess), |
| 872 RecordSyncShare(×, true))); | 870 RecordSyncShare(×, true))); |
| 873 scheduler()->ScheduleLocalNudge(unthrottled_types, FROM_HERE); | 871 scheduler()->ScheduleLocalNudge(unthrottled_types, FROM_HERE); |
| 874 RunLoop(); | 872 RunLoop(); |
| 875 Mock::VerifyAndClearExpectations(syncer()); | 873 Mock::VerifyAndClearExpectations(syncer()); |
| 876 | 874 |
| 877 StopSyncScheduler(); | 875 StopSyncScheduler(); |
| 878 } | 876 } |
| 879 | 877 |
| 880 // Test nudges / polls don't run in config mode and config tasks do. | 878 // Test nudges / polls don't run in config mode and config tasks do. |
| 881 TEST_F(SyncSchedulerTest, ConfigurationMode) { | 879 TEST_F(SyncSchedulerImplTest, ConfigurationMode) { |
| 882 TimeDelta poll(TimeDelta::FromMilliseconds(15)); | 880 TimeDelta poll(TimeDelta::FromMilliseconds(15)); |
| 883 SyncShareTimes times; | 881 SyncShareTimes times; |
| 884 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 882 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
| 885 | 883 |
| 886 StartSyncConfiguration(); | 884 StartSyncConfiguration(); |
| 887 | 885 |
| 888 const ModelTypeSet nudge_types(TYPED_URLS); | 886 const ModelTypeSet nudge_types(TYPED_URLS); |
| 889 scheduler()->ScheduleLocalNudge(nudge_types, FROM_HERE); | 887 scheduler()->ScheduleLocalNudge(nudge_types, FROM_HERE); |
| 890 scheduler()->ScheduleLocalNudge(nudge_types, FROM_HERE); | 888 scheduler()->ScheduleLocalNudge(nudge_types, FROM_HERE); |
| 891 | 889 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 918 | 916 |
| 919 // TODO(tim): Figure out how to remove this dangerous need to reset | 917 // TODO(tim): Figure out how to remove this dangerous need to reset |
| 920 // routing info between mode switches. | 918 // routing info between mode switches. |
| 921 context()->SetRoutingInfo(routing_info()); | 919 context()->SetRoutingInfo(routing_info()); |
| 922 StartSyncScheduler(base::Time()); | 920 StartSyncScheduler(base::Time()); |
| 923 | 921 |
| 924 RunLoop(); | 922 RunLoop(); |
| 925 Mock::VerifyAndClearExpectations(syncer()); | 923 Mock::VerifyAndClearExpectations(syncer()); |
| 926 } | 924 } |
| 927 | 925 |
| 928 class BackoffTriggersSyncSchedulerTest : public SyncSchedulerTest { | 926 class BackoffTriggersSyncSchedulerImplTest : public SyncSchedulerImplTest { |
| 929 void SetUp() override { | 927 void SetUp() override { |
| 930 SyncSchedulerTest::SetUp(); | 928 SyncSchedulerImplTest::SetUp(); |
| 931 UseMockDelayProvider(); | 929 UseMockDelayProvider(); |
| 932 EXPECT_CALL(*delay(), GetDelay(_)) | 930 EXPECT_CALL(*delay(), GetDelay(_)) |
| 933 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(10))); | 931 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(10))); |
| 934 } | 932 } |
| 935 | 933 |
| 936 void TearDown() override { | 934 void TearDown() override { |
| 937 StopSyncScheduler(); | 935 StopSyncScheduler(); |
| 938 SyncSchedulerTest::TearDown(); | 936 SyncSchedulerImplTest::TearDown(); |
| 939 } | 937 } |
| 940 }; | 938 }; |
| 941 | 939 |
| 942 // Have the syncer fail during commit. Expect that the scheduler enters | 940 // Have the syncer fail during commit. Expect that the scheduler enters |
| 943 // backoff. | 941 // backoff. |
| 944 TEST_F(BackoffTriggersSyncSchedulerTest, FailCommitOnce) { | 942 TEST_F(BackoffTriggersSyncSchedulerImplTest, FailCommitOnce) { |
| 945 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 943 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 946 .WillOnce(DoAll(Invoke(test_util::SimulateCommitFailed), | 944 .WillOnce(DoAll(Invoke(test_util::SimulateCommitFailed), |
| 947 QuitLoopNowAction(false))); | 945 QuitLoopNowAction(false))); |
| 948 EXPECT_TRUE(RunAndGetBackoff()); | 946 EXPECT_TRUE(RunAndGetBackoff()); |
| 949 } | 947 } |
| 950 | 948 |
| 951 // Have the syncer fail during download updates and succeed on the first | 949 // Have the syncer fail during download updates and succeed on the first |
| 952 // retry. Expect that this clears the backoff state. | 950 // retry. Expect that this clears the backoff state. |
| 953 TEST_F(BackoffTriggersSyncSchedulerTest, FailDownloadOnceThenSucceed) { | 951 TEST_F(BackoffTriggersSyncSchedulerImplTest, FailDownloadOnceThenSucceed) { |
| 954 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 952 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 955 .WillOnce(DoAll(Invoke(test_util::SimulateDownloadUpdatesFailed), | 953 .WillOnce(DoAll(Invoke(test_util::SimulateDownloadUpdatesFailed), |
| 956 Return(false))) | 954 Return(false))) |
| 957 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), | 955 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), |
| 958 QuitLoopNowAction(true))); | 956 QuitLoopNowAction(true))); |
| 959 EXPECT_FALSE(RunAndGetBackoff()); | 957 EXPECT_FALSE(RunAndGetBackoff()); |
| 960 } | 958 } |
| 961 | 959 |
| 962 // Have the syncer fail during commit and succeed on the first retry. Expect | 960 // Have the syncer fail during commit and succeed on the first retry. Expect |
| 963 // that this clears the backoff state. | 961 // that this clears the backoff state. |
| 964 TEST_F(BackoffTriggersSyncSchedulerTest, FailCommitOnceThenSucceed) { | 962 TEST_F(BackoffTriggersSyncSchedulerImplTest, FailCommitOnceThenSucceed) { |
| 965 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 963 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 966 .WillOnce(DoAll(Invoke(test_util::SimulateCommitFailed), Return(false))) | 964 .WillOnce(DoAll(Invoke(test_util::SimulateCommitFailed), Return(false))) |
| 967 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), | 965 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), |
| 968 QuitLoopNowAction(true))); | 966 QuitLoopNowAction(true))); |
| 969 EXPECT_FALSE(RunAndGetBackoff()); | 967 EXPECT_FALSE(RunAndGetBackoff()); |
| 970 } | 968 } |
| 971 | 969 |
| 972 // Have the syncer fail to download updates and fail again on the retry. | 970 // Have the syncer fail to download updates and fail again on the retry. |
| 973 // Expect this will leave the scheduler in backoff. | 971 // Expect this will leave the scheduler in backoff. |
| 974 TEST_F(BackoffTriggersSyncSchedulerTest, FailDownloadTwice) { | 972 TEST_F(BackoffTriggersSyncSchedulerImplTest, FailDownloadTwice) { |
| 975 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 973 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 976 .WillOnce(DoAll(Invoke(test_util::SimulateDownloadUpdatesFailed), | 974 .WillOnce(DoAll(Invoke(test_util::SimulateDownloadUpdatesFailed), |
| 977 Return(false))) | 975 Return(false))) |
| 978 .WillRepeatedly(DoAll(Invoke(test_util::SimulateDownloadUpdatesFailed), | 976 .WillRepeatedly(DoAll(Invoke(test_util::SimulateDownloadUpdatesFailed), |
| 979 QuitLoopNowAction(false))); | 977 QuitLoopNowAction(false))); |
| 980 EXPECT_TRUE(RunAndGetBackoff()); | 978 EXPECT_TRUE(RunAndGetBackoff()); |
| 981 } | 979 } |
| 982 | 980 |
| 983 // Have the syncer fail to get the encryption key yet succeed in downloading | 981 // Have the syncer fail to get the encryption key yet succeed in downloading |
| 984 // updates. Expect this will leave the scheduler in backoff. | 982 // updates. Expect this will leave the scheduler in backoff. |
| 985 TEST_F(BackoffTriggersSyncSchedulerTest, FailGetEncryptionKey) { | 983 TEST_F(BackoffTriggersSyncSchedulerImplTest, FailGetEncryptionKey) { |
| 986 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) | 984 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) |
| 987 .WillOnce(DoAll(Invoke(test_util::SimulateGetEncryptionKeyFailed), | 985 .WillOnce(DoAll(Invoke(test_util::SimulateGetEncryptionKeyFailed), |
| 988 Return(false))) | 986 Return(false))) |
| 989 .WillRepeatedly(DoAll(Invoke(test_util::SimulateGetEncryptionKeyFailed), | 987 .WillRepeatedly(DoAll(Invoke(test_util::SimulateGetEncryptionKeyFailed), |
| 990 QuitLoopNowAction(false))); | 988 QuitLoopNowAction(false))); |
| 991 StartSyncConfiguration(); | 989 StartSyncConfiguration(); |
| 992 | 990 |
| 993 ModelTypeSet types(THEMES); | 991 ModelTypeSet types(THEMES); |
| 994 CallbackCounter ready_counter; | 992 CallbackCounter ready_counter; |
| 995 CallbackCounter retry_counter; | 993 CallbackCounter retry_counter; |
| 996 ConfigurationParams params( | 994 ConfigurationParams params( |
| 997 GetUpdatesCallerInfo::RECONFIGURATION, types, TypesToRoutingInfo(types), | 995 GetUpdatesCallerInfo::RECONFIGURATION, types, TypesToRoutingInfo(types), |
| 998 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), | 996 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), |
| 999 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); | 997 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); |
| 1000 scheduler()->ScheduleConfiguration(params); | 998 scheduler()->ScheduleConfiguration(params); |
| 1001 RunLoop(); | 999 RunLoop(); |
| 1002 | 1000 |
| 1003 EXPECT_TRUE(scheduler()->IsBackingOff()); | 1001 EXPECT_TRUE(scheduler()->IsBackingOff()); |
| 1004 } | 1002 } |
| 1005 | 1003 |
| 1006 // Test that no polls or extraneous nudges occur when in backoff. | 1004 // Test that no polls or extraneous nudges occur when in backoff. |
| 1007 TEST_F(SyncSchedulerTest, BackoffDropsJobs) { | 1005 TEST_F(SyncSchedulerImplTest, BackoffDropsJobs) { |
| 1008 SyncShareTimes times; | 1006 SyncShareTimes times; |
| 1009 TimeDelta poll(TimeDelta::FromMilliseconds(10)); | 1007 TimeDelta poll(TimeDelta::FromMilliseconds(10)); |
| 1010 const ModelTypeSet types(THEMES); | 1008 const ModelTypeSet types(THEMES); |
| 1011 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 1009 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
| 1012 UseMockDelayProvider(); | 1010 UseMockDelayProvider(); |
| 1013 | 1011 |
| 1014 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 1012 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 1015 .WillOnce(DoAll(Invoke(test_util::SimulateCommitFailed), | 1013 .WillOnce(DoAll(Invoke(test_util::SimulateCommitFailed), |
| 1016 RecordSyncShareMultiple(×, 1U, false))); | 1014 RecordSyncShareMultiple(×, 1U, false))); |
| 1017 EXPECT_CALL(*delay(), GetDelay(_)) | 1015 EXPECT_CALL(*delay(), GetDelay(_)) |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1046 GetUpdatesCallerInfo::RECONFIGURATION, types, TypesToRoutingInfo(types), | 1044 GetUpdatesCallerInfo::RECONFIGURATION, types, TypesToRoutingInfo(types), |
| 1047 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), | 1045 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), |
| 1048 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); | 1046 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); |
| 1049 scheduler()->ScheduleConfiguration(params); | 1047 scheduler()->ScheduleConfiguration(params); |
| 1050 PumpLoop(); | 1048 PumpLoop(); |
| 1051 ASSERT_EQ(0, ready_counter.times_called()); | 1049 ASSERT_EQ(0, ready_counter.times_called()); |
| 1052 ASSERT_EQ(1, retry_counter.times_called()); | 1050 ASSERT_EQ(1, retry_counter.times_called()); |
| 1053 } | 1051 } |
| 1054 | 1052 |
| 1055 // Test that backoff is shaping traffic properly with consecutive errors. | 1053 // Test that backoff is shaping traffic properly with consecutive errors. |
| 1056 TEST_F(SyncSchedulerTest, BackoffElevation) { | 1054 TEST_F(SyncSchedulerImplTest, BackoffElevation) { |
| 1057 SyncShareTimes times; | 1055 SyncShareTimes times; |
| 1058 UseMockDelayProvider(); | 1056 UseMockDelayProvider(); |
| 1059 | 1057 |
| 1060 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 1058 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 1061 .Times(kMinNumSamples) | 1059 .Times(kMinNumSamples) |
| 1062 .WillRepeatedly( | 1060 .WillRepeatedly( |
| 1063 DoAll(Invoke(test_util::SimulateCommitFailed), | 1061 DoAll(Invoke(test_util::SimulateCommitFailed), |
| 1064 RecordSyncShareMultiple(×, kMinNumSamples, false))); | 1062 RecordSyncShareMultiple(×, kMinNumSamples, false))); |
| 1065 | 1063 |
| 1066 const TimeDelta first = TimeDelta::FromSeconds(kInitialBackoffRetrySeconds); | 1064 const TimeDelta first = TimeDelta::FromSeconds(kInitialBackoffRetrySeconds); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1091 RunLoop(); | 1089 RunLoop(); |
| 1092 | 1090 |
| 1093 ASSERT_EQ(kMinNumSamples, times.size()); | 1091 ASSERT_EQ(kMinNumSamples, times.size()); |
| 1094 EXPECT_GE(times[1] - times[0], second); | 1092 EXPECT_GE(times[1] - times[0], second); |
| 1095 EXPECT_GE(times[2] - times[1], third); | 1093 EXPECT_GE(times[2] - times[1], third); |
| 1096 EXPECT_GE(times[3] - times[2], fourth); | 1094 EXPECT_GE(times[3] - times[2], fourth); |
| 1097 EXPECT_GE(times[4] - times[3], fifth); | 1095 EXPECT_GE(times[4] - times[3], fifth); |
| 1098 } | 1096 } |
| 1099 | 1097 |
| 1100 // Test that things go back to normal once a retry makes forward progress. | 1098 // Test that things go back to normal once a retry makes forward progress. |
| 1101 TEST_F(SyncSchedulerTest, BackoffRelief) { | 1099 TEST_F(SyncSchedulerImplTest, BackoffRelief) { |
| 1102 SyncShareTimes times; | 1100 SyncShareTimes times; |
| 1103 UseMockDelayProvider(); | 1101 UseMockDelayProvider(); |
| 1104 | 1102 |
| 1105 const TimeDelta backoff = TimeDelta::FromMilliseconds(10); | 1103 const TimeDelta backoff = TimeDelta::FromMilliseconds(10); |
| 1106 EXPECT_CALL(*delay(), GetDelay(_)).WillOnce(Return(backoff)); | 1104 EXPECT_CALL(*delay(), GetDelay(_)).WillOnce(Return(backoff)); |
| 1107 | 1105 |
| 1108 // Optimal start for the post-backoff poll party. | 1106 // Optimal start for the post-backoff poll party. |
| 1109 TimeTicks optimal_start = TimeTicks::Now(); | 1107 TimeTicks optimal_start = TimeTicks::Now(); |
| 1110 StartSyncScheduler(base::Time()); | 1108 StartSyncScheduler(base::Time()); |
| 1111 | 1109 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1148 SCOPED_TRACE(testing::Message() << "SyncShare # (" << i << ")"); | 1146 SCOPED_TRACE(testing::Message() << "SyncShare # (" << i << ")"); |
| 1149 EXPECT_GE(times[i], optimal_job_time); | 1147 EXPECT_GE(times[i], optimal_job_time); |
| 1150 optimal_job_time = optimal_job_time + poll; | 1148 optimal_job_time = optimal_job_time + poll; |
| 1151 } | 1149 } |
| 1152 | 1150 |
| 1153 StopSyncScheduler(); | 1151 StopSyncScheduler(); |
| 1154 } | 1152 } |
| 1155 | 1153 |
| 1156 // Test that poll failures are treated like any other failure. They should | 1154 // Test that poll failures are treated like any other failure. They should |
| 1157 // result in retry with backoff. | 1155 // result in retry with backoff. |
| 1158 TEST_F(SyncSchedulerTest, TransientPollFailure) { | 1156 TEST_F(SyncSchedulerImplTest, TransientPollFailure) { |
| 1159 SyncShareTimes times; | 1157 SyncShareTimes times; |
| 1160 const TimeDelta poll_interval(TimeDelta::FromMilliseconds(10)); | 1158 const TimeDelta poll_interval(TimeDelta::FromMilliseconds(10)); |
| 1161 scheduler()->OnReceivedLongPollIntervalUpdate(poll_interval); | 1159 scheduler()->OnReceivedLongPollIntervalUpdate(poll_interval); |
| 1162 UseMockDelayProvider(); // Will cause test failure if backoff is initiated. | 1160 UseMockDelayProvider(); // Will cause test failure if backoff is initiated. |
| 1163 EXPECT_CALL(*delay(), GetDelay(_)) | 1161 EXPECT_CALL(*delay(), GetDelay(_)) |
| 1164 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(0))); | 1162 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(0))); |
| 1165 | 1163 |
| 1166 EXPECT_CALL(*syncer(), PollSyncShare(_, _)) | 1164 EXPECT_CALL(*syncer(), PollSyncShare(_, _)) |
| 1167 .WillOnce(DoAll(Invoke(test_util::SimulatePollFailed), | 1165 .WillOnce(DoAll(Invoke(test_util::SimulatePollFailed), |
| 1168 RecordSyncShare(×, false))) | 1166 RecordSyncShare(×, false))) |
| 1169 .WillOnce(DoAll(Invoke(test_util::SimulatePollSuccess), | 1167 .WillOnce(DoAll(Invoke(test_util::SimulatePollSuccess), |
| 1170 RecordSyncShare(×, true))); | 1168 RecordSyncShare(×, true))); |
| 1171 | 1169 |
| 1172 StartSyncScheduler(base::Time()); | 1170 StartSyncScheduler(base::Time()); |
| 1173 | 1171 |
| 1174 // Run the unsuccessful poll. The failed poll should not trigger backoff. | 1172 // Run the unsuccessful poll. The failed poll should not trigger backoff. |
| 1175 RunLoop(); | 1173 RunLoop(); |
| 1176 EXPECT_TRUE(scheduler()->IsBackingOff()); | 1174 EXPECT_TRUE(scheduler()->IsBackingOff()); |
| 1177 | 1175 |
| 1178 // Run the successful poll. | 1176 // Run the successful poll. |
| 1179 RunLoop(); | 1177 RunLoop(); |
| 1180 EXPECT_FALSE(scheduler()->IsBackingOff()); | 1178 EXPECT_FALSE(scheduler()->IsBackingOff()); |
| 1181 } | 1179 } |
| 1182 | 1180 |
| 1183 // Test that starting the syncer thread without a valid connection doesn't | 1181 // Test that starting the syncer thread without a valid connection doesn't |
| 1184 // break things when a connection is detected. | 1182 // break things when a connection is detected. |
| 1185 TEST_F(SyncSchedulerTest, StartWhenNotConnected) { | 1183 TEST_F(SyncSchedulerImplTest, StartWhenNotConnected) { |
| 1186 connection()->SetServerNotReachable(); | 1184 connection()->SetServerNotReachable(); |
| 1187 connection()->UpdateConnectionStatus(); | 1185 connection()->UpdateConnectionStatus(); |
| 1188 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 1186 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 1189 .WillOnce( | 1187 .WillOnce( |
| 1190 DoAll(Invoke(test_util::SimulateConnectionFailure), Return(false))) | 1188 DoAll(Invoke(test_util::SimulateConnectionFailure), Return(false))) |
| 1191 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), Return(true))); | 1189 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), Return(true))); |
| 1192 StartSyncScheduler(base::Time()); | 1190 StartSyncScheduler(base::Time()); |
| 1193 | 1191 |
| 1194 scheduler()->ScheduleLocalNudge(ModelTypeSet(THEMES), FROM_HERE); | 1192 scheduler()->ScheduleLocalNudge(ModelTypeSet(THEMES), FROM_HERE); |
| 1195 // Should save the nudge for until after the server is reachable. | 1193 // Should save the nudge for until after the server is reachable. |
| 1196 base::RunLoop().RunUntilIdle(); | 1194 base::RunLoop().RunUntilIdle(); |
| 1197 | 1195 |
| 1198 scheduler()->OnConnectionStatusChange(); | 1196 scheduler()->OnConnectionStatusChange(); |
| 1199 connection()->SetServerReachable(); | 1197 connection()->SetServerReachable(); |
| 1200 connection()->UpdateConnectionStatus(); | 1198 connection()->UpdateConnectionStatus(); |
| 1201 base::RunLoop().RunUntilIdle(); | 1199 base::RunLoop().RunUntilIdle(); |
| 1202 } | 1200 } |
| 1203 | 1201 |
| 1204 TEST_F(SyncSchedulerTest, ServerConnectionChangeDuringBackoff) { | 1202 TEST_F(SyncSchedulerImplTest, ServerConnectionChangeDuringBackoff) { |
| 1205 UseMockDelayProvider(); | 1203 UseMockDelayProvider(); |
| 1206 EXPECT_CALL(*delay(), GetDelay(_)) | 1204 EXPECT_CALL(*delay(), GetDelay(_)) |
| 1207 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(0))); | 1205 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(0))); |
| 1208 | 1206 |
| 1209 StartSyncScheduler(base::Time()); | 1207 StartSyncScheduler(base::Time()); |
| 1210 connection()->SetServerNotReachable(); | 1208 connection()->SetServerNotReachable(); |
| 1211 connection()->UpdateConnectionStatus(); | 1209 connection()->UpdateConnectionStatus(); |
| 1212 | 1210 |
| 1213 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 1211 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 1214 .WillOnce( | 1212 .WillOnce( |
| 1215 DoAll(Invoke(test_util::SimulateConnectionFailure), Return(false))) | 1213 DoAll(Invoke(test_util::SimulateConnectionFailure), Return(false))) |
| 1216 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), Return(true))); | 1214 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), Return(true))); |
| 1217 | 1215 |
| 1218 scheduler()->ScheduleLocalNudge(ModelTypeSet(THEMES), FROM_HERE); | 1216 scheduler()->ScheduleLocalNudge(ModelTypeSet(THEMES), FROM_HERE); |
| 1219 PumpLoop(); // To get PerformDelayedNudge called. | 1217 PumpLoop(); // To get PerformDelayedNudge called. |
| 1220 PumpLoop(); // Run the nudge, that will fail and schedule a quick retry. | 1218 PumpLoop(); // Run the nudge, that will fail and schedule a quick retry. |
| 1221 ASSERT_TRUE(scheduler()->IsBackingOff()); | 1219 ASSERT_TRUE(scheduler()->IsBackingOff()); |
| 1222 | 1220 |
| 1223 // Before we run the scheduled canary, trigger a server connection change. | 1221 // Before we run the scheduled canary, trigger a server connection change. |
| 1224 scheduler()->OnConnectionStatusChange(); | 1222 scheduler()->OnConnectionStatusChange(); |
| 1225 connection()->SetServerReachable(); | 1223 connection()->SetServerReachable(); |
| 1226 connection()->UpdateConnectionStatus(); | 1224 connection()->UpdateConnectionStatus(); |
| 1227 base::RunLoop().RunUntilIdle(); | 1225 base::RunLoop().RunUntilIdle(); |
| 1228 } | 1226 } |
| 1229 | 1227 |
| 1230 // This was supposed to test the scenario where we receive a nudge while a | 1228 // This was supposed to test the scenario where we receive a nudge while a |
| 1231 // connection change canary is scheduled, but has not run yet. Since we've made | 1229 // connection change canary is scheduled, but has not run yet. Since we've made |
| 1232 // the connection change canary synchronous, this is no longer possible. | 1230 // the connection change canary synchronous, this is no longer possible. |
| 1233 TEST_F(SyncSchedulerTest, ConnectionChangeCanaryPreemptedByNudge) { | 1231 TEST_F(SyncSchedulerImplTest, ConnectionChangeCanaryPreemptedByNudge) { |
| 1234 UseMockDelayProvider(); | 1232 UseMockDelayProvider(); |
| 1235 EXPECT_CALL(*delay(), GetDelay(_)) | 1233 EXPECT_CALL(*delay(), GetDelay(_)) |
| 1236 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(0))); | 1234 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(0))); |
| 1237 | 1235 |
| 1238 StartSyncScheduler(base::Time()); | 1236 StartSyncScheduler(base::Time()); |
| 1239 connection()->SetServerNotReachable(); | 1237 connection()->SetServerNotReachable(); |
| 1240 connection()->UpdateConnectionStatus(); | 1238 connection()->UpdateConnectionStatus(); |
| 1241 | 1239 |
| 1242 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 1240 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 1243 .WillOnce( | 1241 .WillOnce( |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1256 scheduler()->OnConnectionStatusChange(); | 1254 scheduler()->OnConnectionStatusChange(); |
| 1257 PumpLoop(); | 1255 PumpLoop(); |
| 1258 connection()->SetServerReachable(); | 1256 connection()->SetServerReachable(); |
| 1259 connection()->UpdateConnectionStatus(); | 1257 connection()->UpdateConnectionStatus(); |
| 1260 scheduler()->ScheduleLocalNudge(ModelTypeSet(THEMES), FROM_HERE); | 1258 scheduler()->ScheduleLocalNudge(ModelTypeSet(THEMES), FROM_HERE); |
| 1261 base::RunLoop().RunUntilIdle(); | 1259 base::RunLoop().RunUntilIdle(); |
| 1262 } | 1260 } |
| 1263 | 1261 |
| 1264 // Tests that we don't crash trying to run two canaries at once if we receive | 1262 // Tests that we don't crash trying to run two canaries at once if we receive |
| 1265 // extra connection status change notifications. See crbug.com/190085. | 1263 // extra connection status change notifications. See crbug.com/190085. |
| 1266 TEST_F(SyncSchedulerTest, DoubleCanaryInConfigure) { | 1264 TEST_F(SyncSchedulerImplTest, DoubleCanaryInConfigure) { |
| 1267 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) | 1265 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) |
| 1268 .WillRepeatedly(DoAll( | 1266 .WillRepeatedly(DoAll( |
| 1269 Invoke(test_util::SimulateConfigureConnectionFailure), Return(true))); | 1267 Invoke(test_util::SimulateConfigureConnectionFailure), Return(true))); |
| 1270 StartSyncConfiguration(); | 1268 StartSyncConfiguration(); |
| 1271 connection()->SetServerNotReachable(); | 1269 connection()->SetServerNotReachable(); |
| 1272 connection()->UpdateConnectionStatus(); | 1270 connection()->UpdateConnectionStatus(); |
| 1273 | 1271 |
| 1274 ModelTypeSet model_types(THEMES); | 1272 ModelTypeSet model_types(THEMES); |
| 1275 CallbackCounter ready_counter; | 1273 CallbackCounter ready_counter; |
| 1276 CallbackCounter retry_counter; | 1274 CallbackCounter retry_counter; |
| 1277 ConfigurationParams params( | 1275 ConfigurationParams params( |
| 1278 GetUpdatesCallerInfo::RECONFIGURATION, model_types, | 1276 GetUpdatesCallerInfo::RECONFIGURATION, model_types, |
| 1279 TypesToRoutingInfo(model_types), | 1277 TypesToRoutingInfo(model_types), |
| 1280 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), | 1278 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), |
| 1281 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); | 1279 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); |
| 1282 scheduler()->ScheduleConfiguration(params); | 1280 scheduler()->ScheduleConfiguration(params); |
| 1283 | 1281 |
| 1284 scheduler()->OnConnectionStatusChange(); | 1282 scheduler()->OnConnectionStatusChange(); |
| 1285 scheduler()->OnConnectionStatusChange(); | 1283 scheduler()->OnConnectionStatusChange(); |
| 1286 | 1284 |
| 1287 PumpLoop(); // Run the nudge, that will fail and schedule a quick retry. | 1285 PumpLoop(); // Run the nudge, that will fail and schedule a quick retry. |
| 1288 } | 1286 } |
| 1289 | 1287 |
| 1290 TEST_F(SyncSchedulerTest, PollFromCanaryAfterAuthError) { | 1288 TEST_F(SyncSchedulerImplTest, PollFromCanaryAfterAuthError) { |
| 1291 SyncShareTimes times; | 1289 SyncShareTimes times; |
| 1292 TimeDelta poll(TimeDelta::FromMilliseconds(15)); | 1290 TimeDelta poll(TimeDelta::FromMilliseconds(15)); |
| 1293 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 1291 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
| 1294 | 1292 |
| 1295 ::testing::InSequence seq; | 1293 ::testing::InSequence seq; |
| 1296 EXPECT_CALL(*syncer(), PollSyncShare(_, _)) | 1294 EXPECT_CALL(*syncer(), PollSyncShare(_, _)) |
| 1297 .WillRepeatedly( | 1295 .WillRepeatedly( |
| 1298 DoAll(Invoke(test_util::SimulatePollSuccess), | 1296 DoAll(Invoke(test_util::SimulatePollSuccess), |
| 1299 RecordSyncShareMultiple(×, kMinNumSamples, true))); | 1297 RecordSyncShareMultiple(×, kMinNumSamples, true))); |
| 1300 | 1298 |
| 1301 connection()->SetServerStatus(HttpResponse::SYNC_AUTH_ERROR); | 1299 connection()->SetServerStatus(HttpResponse::SYNC_AUTH_ERROR); |
| 1302 StartSyncScheduler(base::Time()); | 1300 StartSyncScheduler(base::Time()); |
| 1303 | 1301 |
| 1304 // Run to wait for polling. | 1302 // Run to wait for polling. |
| 1305 RunLoop(); | 1303 RunLoop(); |
| 1306 | 1304 |
| 1307 // Normally OnCredentialsUpdated calls TryCanaryJob that doesn't run Poll, | 1305 // Normally OnCredentialsUpdated calls TryCanaryJob that doesn't run Poll, |
| 1308 // but after poll finished with auth error from poll timer it should retry | 1306 // but after poll finished with auth error from poll timer it should retry |
| 1309 // poll once more | 1307 // poll once more |
| 1310 EXPECT_CALL(*syncer(), PollSyncShare(_, _)) | 1308 EXPECT_CALL(*syncer(), PollSyncShare(_, _)) |
| 1311 .WillOnce(DoAll(Invoke(test_util::SimulatePollSuccess), | 1309 .WillOnce(DoAll(Invoke(test_util::SimulatePollSuccess), |
| 1312 RecordSyncShare(×, true))); | 1310 RecordSyncShare(×, true))); |
| 1313 scheduler()->OnCredentialsUpdated(); | 1311 scheduler()->OnCredentialsUpdated(); |
| 1314 connection()->SetServerStatus(HttpResponse::SERVER_CONNECTION_OK); | 1312 connection()->SetServerStatus(HttpResponse::SERVER_CONNECTION_OK); |
| 1315 RunLoop(); | 1313 RunLoop(); |
| 1316 StopSyncScheduler(); | 1314 StopSyncScheduler(); |
| 1317 } | 1315 } |
| 1318 | 1316 |
| 1319 TEST_F(SyncSchedulerTest, SuccessfulRetry) { | 1317 TEST_F(SyncSchedulerImplTest, SuccessfulRetry) { |
| 1320 StartSyncScheduler(base::Time()); | 1318 StartSyncScheduler(base::Time()); |
| 1321 | 1319 |
| 1322 SyncShareTimes times; | 1320 SyncShareTimes times; |
| 1323 base::TimeDelta delay = base::TimeDelta::FromMilliseconds(10); | 1321 base::TimeDelta delay = base::TimeDelta::FromMilliseconds(10); |
| 1324 scheduler()->OnReceivedGuRetryDelay(delay); | 1322 scheduler()->OnReceivedGuRetryDelay(delay); |
| 1325 EXPECT_EQ(delay, GetRetryTimerDelay()); | 1323 EXPECT_EQ(delay, GetRetryTimerDelay()); |
| 1326 | 1324 |
| 1327 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 1325 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 1328 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), | 1326 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), |
| 1329 RecordSyncShare(×, true))); | 1327 RecordSyncShare(×, true))); |
| 1330 | 1328 |
| 1331 // Run to wait for retrying. | 1329 // Run to wait for retrying. |
| 1332 RunLoop(); | 1330 RunLoop(); |
| 1333 | 1331 |
| 1334 StopSyncScheduler(); | 1332 StopSyncScheduler(); |
| 1335 } | 1333 } |
| 1336 | 1334 |
| 1337 TEST_F(SyncSchedulerTest, FailedRetry) { | 1335 TEST_F(SyncSchedulerImplTest, FailedRetry) { |
| 1338 SyncShareTimes times; | 1336 SyncShareTimes times; |
| 1339 | 1337 |
| 1340 UseMockDelayProvider(); | 1338 UseMockDelayProvider(); |
| 1341 EXPECT_CALL(*delay(), GetDelay(_)) | 1339 EXPECT_CALL(*delay(), GetDelay(_)) |
| 1342 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(10))); | 1340 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(10))); |
| 1343 | 1341 |
| 1344 StartSyncScheduler(base::Time()); | 1342 StartSyncScheduler(base::Time()); |
| 1345 | 1343 |
| 1346 base::TimeDelta delay = base::TimeDelta::FromMilliseconds(10); | 1344 base::TimeDelta delay = base::TimeDelta::FromMilliseconds(10); |
| 1347 scheduler()->OnReceivedGuRetryDelay(delay); | 1345 scheduler()->OnReceivedGuRetryDelay(delay); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1361 // Run to wait for second retrying. | 1359 // Run to wait for second retrying. |
| 1362 RunLoop(); | 1360 RunLoop(); |
| 1363 | 1361 |
| 1364 StopSyncScheduler(); | 1362 StopSyncScheduler(); |
| 1365 } | 1363 } |
| 1366 | 1364 |
| 1367 ACTION_P2(VerifyRetryTimerDelay, scheduler_test, expected_delay) { | 1365 ACTION_P2(VerifyRetryTimerDelay, scheduler_test, expected_delay) { |
| 1368 EXPECT_EQ(expected_delay, scheduler_test->GetRetryTimerDelay()); | 1366 EXPECT_EQ(expected_delay, scheduler_test->GetRetryTimerDelay()); |
| 1369 } | 1367 } |
| 1370 | 1368 |
| 1371 TEST_F(SyncSchedulerTest, ReceiveNewRetryDelay) { | 1369 TEST_F(SyncSchedulerImplTest, ReceiveNewRetryDelay) { |
| 1372 StartSyncScheduler(base::Time()); | 1370 StartSyncScheduler(base::Time()); |
| 1373 | 1371 |
| 1374 SyncShareTimes times; | 1372 SyncShareTimes times; |
| 1375 base::TimeDelta delay1 = base::TimeDelta::FromMilliseconds(100); | 1373 base::TimeDelta delay1 = base::TimeDelta::FromMilliseconds(100); |
| 1376 base::TimeDelta delay2 = base::TimeDelta::FromMilliseconds(200); | 1374 base::TimeDelta delay2 = base::TimeDelta::FromMilliseconds(200); |
| 1377 | 1375 |
| 1378 scheduler()->ScheduleLocalNudge(ModelTypeSet(THEMES), FROM_HERE); | 1376 scheduler()->ScheduleLocalNudge(ModelTypeSet(THEMES), FROM_HERE); |
| 1379 scheduler()->OnReceivedGuRetryDelay(delay1); | 1377 scheduler()->OnReceivedGuRetryDelay(delay1); |
| 1380 EXPECT_EQ(delay1, GetRetryTimerDelay()); | 1378 EXPECT_EQ(delay1, GetRetryTimerDelay()); |
| 1381 | 1379 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1392 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 1390 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 1393 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), | 1391 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), |
| 1394 RecordSyncShare(×, true))); | 1392 RecordSyncShare(×, true))); |
| 1395 | 1393 |
| 1396 // Run to wait for retrying. | 1394 // Run to wait for retrying. |
| 1397 RunLoop(); | 1395 RunLoop(); |
| 1398 | 1396 |
| 1399 StopSyncScheduler(); | 1397 StopSyncScheduler(); |
| 1400 } | 1398 } |
| 1401 | 1399 |
| 1402 TEST_F(SyncSchedulerTest, ScheduleClearServerData_Succeeds) { | 1400 TEST_F(SyncSchedulerImplTest, ScheduleClearServerData_Succeeds) { |
| 1403 StartSyncConfiguration(); | 1401 StartSyncConfiguration(); |
| 1404 scheduler()->Start(SyncScheduler::CLEAR_SERVER_DATA_MODE, base::Time()); | 1402 scheduler()->Start(SyncScheduler::CLEAR_SERVER_DATA_MODE, base::Time()); |
| 1405 CallbackCounter success_counter; | 1403 CallbackCounter success_counter; |
| 1406 ClearParams params(base::Bind(&CallbackCounter::Callback, | 1404 ClearParams params(base::Bind(&CallbackCounter::Callback, |
| 1407 base::Unretained(&success_counter))); | 1405 base::Unretained(&success_counter))); |
| 1408 scheduler()->ScheduleClearServerData(params); | 1406 scheduler()->ScheduleClearServerData(params); |
| 1409 PumpLoop(); | 1407 PumpLoop(); |
| 1410 ASSERT_EQ(1, success_counter.times_called()); | 1408 ASSERT_EQ(1, success_counter.times_called()); |
| 1411 } | 1409 } |
| 1412 | 1410 |
| 1413 TEST_F(SyncSchedulerTest, ScheduleClearServerData_FailsRetriesSucceeds) { | 1411 TEST_F(SyncSchedulerImplTest, ScheduleClearServerData_FailsRetriesSucceeds) { |
| 1414 UseMockDelayProvider(); | 1412 UseMockDelayProvider(); |
| 1415 TimeDelta delta(TimeDelta::FromMilliseconds(20)); | 1413 TimeDelta delta(TimeDelta::FromMilliseconds(20)); |
| 1416 EXPECT_CALL(*delay(), GetDelay(_)).WillRepeatedly(Return(delta)); | 1414 EXPECT_CALL(*delay(), GetDelay(_)).WillRepeatedly(Return(delta)); |
| 1417 | 1415 |
| 1418 StartSyncConfiguration(); | 1416 StartSyncConfiguration(); |
| 1419 scheduler()->Start(SyncScheduler::CLEAR_SERVER_DATA_MODE, base::Time()); | 1417 scheduler()->Start(SyncScheduler::CLEAR_SERVER_DATA_MODE, base::Time()); |
| 1420 CallbackCounter success_counter; | 1418 CallbackCounter success_counter; |
| 1421 ClearParams params(base::Bind(&CallbackCounter::Callback, | 1419 ClearParams params(base::Bind(&CallbackCounter::Callback, |
| 1422 base::Unretained(&success_counter))); | 1420 base::Unretained(&success_counter))); |
| 1423 | 1421 |
| 1424 // Next request will fail. | 1422 // Next request will fail. |
| 1425 connection()->SetServerNotReachable(); | 1423 connection()->SetServerNotReachable(); |
| 1426 scheduler()->ScheduleClearServerData(params); | 1424 scheduler()->ScheduleClearServerData(params); |
| 1427 PumpLoop(); | 1425 PumpLoop(); |
| 1428 ASSERT_EQ(0, success_counter.times_called()); | 1426 ASSERT_EQ(0, success_counter.times_called()); |
| 1429 ASSERT_TRUE(scheduler()->IsBackingOff()); | 1427 ASSERT_TRUE(scheduler()->IsBackingOff()); |
| 1430 | 1428 |
| 1431 // Now succeed. | 1429 // Now succeed. |
| 1432 connection()->SetServerReachable(); | 1430 connection()->SetServerReachable(); |
| 1433 PumpLoopFor(2 * delta); | 1431 PumpLoopFor(2 * delta); |
| 1434 ASSERT_EQ(1, success_counter.times_called()); | 1432 ASSERT_EQ(1, success_counter.times_called()); |
| 1435 ASSERT_FALSE(scheduler()->IsBackingOff()); | 1433 ASSERT_FALSE(scheduler()->IsBackingOff()); |
| 1436 } | 1434 } |
| 1437 | 1435 |
| 1438 } // namespace syncer | 1436 } // namespace syncer |
| OLD | NEW |