| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/sync/engine_impl/sync_scheduler_impl.h" | 5 #include "components/sync/engine_impl/sync_scheduler_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 | 76 |
| 77 void PumpLoop() { | 77 void PumpLoop() { |
| 78 // Do it this way instead of RunAllPending to pump loop exactly once | 78 // Do it this way instead of RunAllPending to pump loop exactly once |
| 79 // (necessary in the presence of timers; see comment in | 79 // (necessary in the presence of timers; see comment in |
| 80 // QuitLoopNow). | 80 // QuitLoopNow). |
| 81 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, | 81 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, |
| 82 base::Bind(&QuitLoopNow)); | 82 base::Bind(&QuitLoopNow)); |
| 83 RunLoop(); | 83 RunLoop(); |
| 84 } | 84 } |
| 85 | 85 |
| 86 void PumpLoopFor(base::TimeDelta time) { | 86 void PumpLoopFor(TimeDelta time) { |
| 87 // Allow the loop to run for the specified amount of time. | 87 // Allow the loop to run for the specified amount of time. |
| 88 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 88 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 89 FROM_HERE, base::Bind(&QuitLoopNow), time); | 89 FROM_HERE, base::Bind(&QuitLoopNow), time); |
| 90 RunLoop(); | 90 RunLoop(); |
| 91 } | 91 } |
| 92 | 92 |
| 93 static const size_t kMinNumSamples = 5; | 93 static const size_t kMinNumSamples = 5; |
| 94 | 94 |
| 95 // Test harness for the SyncScheduler. Test the delays and backoff timers used | 95 // Test harness for the SyncScheduler. Test the delays and backoff timers used |
| 96 // in response to various events. | 96 // in response to various events. |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 backed_off_types.Put(type_it.Get()); | 238 backed_off_types.Put(type_it.Get()); |
| 239 } | 239 } |
| 240 } | 240 } |
| 241 return backed_off_types; | 241 return backed_off_types; |
| 242 } | 242 } |
| 243 | 243 |
| 244 bool IsAnyTypeBlocked() { | 244 bool IsAnyTypeBlocked() { |
| 245 return scheduler_->nudge_tracker_.IsAnyTypeBlocked(); | 245 return scheduler_->nudge_tracker_.IsAnyTypeBlocked(); |
| 246 } | 246 } |
| 247 | 247 |
| 248 base::TimeDelta GetRetryTimerDelay() { | 248 TimeDelta GetRetryTimerDelay() { |
| 249 EXPECT_TRUE(scheduler_->retry_timer_.IsRunning()); | 249 EXPECT_TRUE(scheduler_->retry_timer_.IsRunning()); |
| 250 return scheduler_->retry_timer_.GetCurrentDelay(); | 250 return scheduler_->retry_timer_.GetCurrentDelay(); |
| 251 } | 251 } |
| 252 | 252 |
| 253 static std::unique_ptr<InvalidationInterface> BuildInvalidation( | 253 static std::unique_ptr<InvalidationInterface> BuildInvalidation( |
| 254 int64_t version, | 254 int64_t version, |
| 255 const std::string& payload) { | 255 const std::string& payload) { |
| 256 return MockInvalidation::Build(version, payload); | 256 return MockInvalidation::Build(version, payload); |
| 257 } | 257 } |
| 258 | 258 |
| 259 base::TimeDelta GetTypeBlockingTime(ModelType type) { | 259 TimeDelta GetTypeBlockingTime(ModelType type) { |
| 260 NudgeTracker::TypeTrackerMap::const_iterator tracker_it = | 260 NudgeTracker::TypeTrackerMap::const_iterator tracker_it = |
| 261 scheduler_->nudge_tracker_.type_trackers_.find(type); | 261 scheduler_->nudge_tracker_.type_trackers_.find(type); |
| 262 DCHECK(tracker_it != scheduler_->nudge_tracker_.type_trackers_.end()); | 262 DCHECK(tracker_it != scheduler_->nudge_tracker_.type_trackers_.end()); |
| 263 DCHECK(tracker_it->second->wait_interval_.get()); | 263 DCHECK(tracker_it->second->wait_interval_.get()); |
| 264 return tracker_it->second->wait_interval_->length; | 264 return tracker_it->second->wait_interval_->length; |
| 265 } | 265 } |
| 266 | 266 |
| 267 void SetTypeBlockingMode(ModelType type, WaitInterval::BlockingMode mode) { | 267 void SetTypeBlockingMode(ModelType type, WaitInterval::BlockingMode mode) { |
| 268 NudgeTracker::TypeTrackerMap::const_iterator tracker_it = | 268 NudgeTracker::TypeTrackerMap::const_iterator tracker_it = |
| 269 scheduler_->nudge_tracker_.type_trackers_.find(type); | 269 scheduler_->nudge_tracker_.type_trackers_.find(type); |
| 270 DCHECK(tracker_it != scheduler_->nudge_tracker_.type_trackers_.end()); | 270 DCHECK(tracker_it != scheduler_->nudge_tracker_.type_trackers_.end()); |
| 271 DCHECK(tracker_it->second->wait_interval_.get()); | 271 DCHECK(tracker_it->second->wait_interval_.get()); |
| 272 tracker_it->second->wait_interval_->mode = mode; | 272 tracker_it->second->wait_interval_->mode = mode; |
| 273 } | 273 } |
| 274 | 274 |
| 275 void NewSchedulerForLocalBackend() { | 275 void NewSchedulerForLocalBackend() { |
| 276 // The old syncer is destroyed with the scheduler that owns it. | 276 // The old syncer is destroyed with the scheduler that owns it. |
| 277 syncer_ = new testing::StrictMock<MockSyncer>(); | 277 syncer_ = new testing::StrictMock<MockSyncer>(); |
| 278 scheduler_ = base::MakeUnique<SyncSchedulerImpl>( | 278 scheduler_ = base::MakeUnique<SyncSchedulerImpl>( |
| 279 "TestSyncScheduler", BackoffDelayProvider::FromDefaults(), context(), | 279 "TestSyncScheduler", BackoffDelayProvider::FromDefaults(), context(), |
| 280 syncer_, true); | 280 syncer_, true); |
| 281 scheduler_->SetDefaultNudgeDelay(default_delay()); | 281 scheduler_->SetDefaultNudgeDelay(default_delay()); |
| 282 } | 282 } |
| 283 | 283 |
| 284 bool BlockTimerIsRunning() const { | 284 bool BlockTimerIsRunning() const { |
| 285 return scheduler_->pending_wakeup_timer_.IsRunning(); | 285 return scheduler_->pending_wakeup_timer_.IsRunning(); |
| 286 } | 286 } |
| 287 | 287 |
| 288 TimeDelta GetPendingWakeupTimerDelay() { |
| 289 EXPECT_TRUE(scheduler_->pending_wakeup_timer_.IsRunning()); |
| 290 return scheduler_->pending_wakeup_timer_.GetCurrentDelay(); |
| 291 } |
| 292 |
| 288 private: | 293 private: |
| 289 syncable::Directory* directory() { | 294 syncable::Directory* directory() { |
| 290 return test_user_share_.user_share()->directory.get(); | 295 return test_user_share_.user_share()->directory.get(); |
| 291 } | 296 } |
| 292 | 297 |
| 293 base::MessageLoop loop_; | 298 base::MessageLoop loop_; |
| 294 TestUserShare test_user_share_; | 299 TestUserShare test_user_share_; |
| 295 CancelationSignal cancelation_signal_; | 300 CancelationSignal cancelation_signal_; |
| 296 std::unique_ptr<MockConnectionManager> connection_; | 301 std::unique_ptr<MockConnectionManager> connection_; |
| 297 std::unique_ptr<ModelTypeRegistry> model_type_registry_; | 302 std::unique_ptr<ModelTypeRegistry> model_type_registry_; |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 707 EXPECT_CALL(*syncer(), PollSyncShare(_, _)) | 712 EXPECT_CALL(*syncer(), PollSyncShare(_, _)) |
| 708 .Times(AtLeast(kMinNumSamples)) | 713 .Times(AtLeast(kMinNumSamples)) |
| 709 .WillRepeatedly( | 714 .WillRepeatedly( |
| 710 DoAll(Invoke(test_util::SimulatePollSuccess), | 715 DoAll(Invoke(test_util::SimulatePollSuccess), |
| 711 RecordSyncShareMultiple(×, kMinNumSamples, true))); | 716 RecordSyncShareMultiple(×, kMinNumSamples, true))); |
| 712 | 717 |
| 713 scheduler()->OnReceivedLongPollIntervalUpdate(poll_interval); | 718 scheduler()->OnReceivedLongPollIntervalUpdate(poll_interval); |
| 714 | 719 |
| 715 // Set the start time to |poll_interval| in the future. | 720 // Set the start time to |poll_interval| in the future. |
| 716 TimeTicks optimal_start = TimeTicks::Now() + poll_interval; | 721 TimeTicks optimal_start = TimeTicks::Now() + poll_interval; |
| 717 StartSyncScheduler(base::Time::Now() + base::TimeDelta::FromMinutes(10)); | 722 StartSyncScheduler(base::Time::Now() + TimeDelta::FromMinutes(10)); |
| 718 | 723 |
| 719 // Run again to wait for polling. | 724 // Run again to wait for polling. |
| 720 RunLoop(); | 725 RunLoop(); |
| 721 | 726 |
| 722 StopSyncScheduler(); | 727 StopSyncScheduler(); |
| 723 AnalyzePollRun(times, kMinNumSamples, optimal_start, poll_interval); | 728 AnalyzePollRun(times, kMinNumSamples, optimal_start, poll_interval); |
| 724 } | 729 } |
| 725 | 730 |
| 726 // Test that the short poll interval is used. | 731 // Test that the short poll interval is used. |
| 727 TEST_F(SyncSchedulerImplTest, PollNotificationsDisabled) { | 732 TEST_F(SyncSchedulerImplTest, PollNotificationsDisabled) { |
| (...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1441 // Now let the Poll timer do its thing. | 1446 // Now let the Poll timer do its thing. |
| 1442 EXPECT_CALL(*syncer(), PollSyncShare(_, _)) | 1447 EXPECT_CALL(*syncer(), PollSyncShare(_, _)) |
| 1443 .WillRepeatedly( | 1448 .WillRepeatedly( |
| 1444 DoAll(Invoke(test_util::SimulatePollSuccess), | 1449 DoAll(Invoke(test_util::SimulatePollSuccess), |
| 1445 RecordSyncShareMultiple(×, kMinNumSamples, true))); | 1450 RecordSyncShareMultiple(×, kMinNumSamples, true))); |
| 1446 const TimeDelta poll(TimeDelta::FromMilliseconds(10)); | 1451 const TimeDelta poll(TimeDelta::FromMilliseconds(10)); |
| 1447 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 1452 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
| 1448 | 1453 |
| 1449 // The new optimal time is now, since the desired poll should have happened | 1454 // The new optimal time is now, since the desired poll should have happened |
| 1450 // in the past. | 1455 // in the past. |
| 1451 optimal_job_time = base::TimeTicks::Now(); | 1456 optimal_job_time = TimeTicks::Now(); |
| 1452 RunLoop(); | 1457 RunLoop(); |
| 1453 Mock::VerifyAndClearExpectations(syncer()); | 1458 Mock::VerifyAndClearExpectations(syncer()); |
| 1454 ASSERT_EQ(kMinNumSamples, times.size()); | 1459 ASSERT_EQ(kMinNumSamples, times.size()); |
| 1455 for (size_t i = 2; i < times.size(); i++) { | 1460 for (size_t i = 2; i < times.size(); i++) { |
| 1456 SCOPED_TRACE(testing::Message() << "SyncShare # (" << i << ")"); | 1461 SCOPED_TRACE(testing::Message() << "SyncShare # (" << i << ")"); |
| 1457 EXPECT_GE(times[i], optimal_job_time); | 1462 EXPECT_GE(times[i], optimal_job_time); |
| 1458 optimal_job_time = optimal_job_time + poll; | 1463 optimal_job_time = optimal_job_time + poll; |
| 1459 } | 1464 } |
| 1460 | 1465 |
| 1461 StopSyncScheduler(); | 1466 StopSyncScheduler(); |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1620 scheduler()->OnCredentialsUpdated(); | 1625 scheduler()->OnCredentialsUpdated(); |
| 1621 connection()->SetServerStatus(HttpResponse::SERVER_CONNECTION_OK); | 1626 connection()->SetServerStatus(HttpResponse::SERVER_CONNECTION_OK); |
| 1622 RunLoop(); | 1627 RunLoop(); |
| 1623 StopSyncScheduler(); | 1628 StopSyncScheduler(); |
| 1624 } | 1629 } |
| 1625 | 1630 |
| 1626 TEST_F(SyncSchedulerImplTest, SuccessfulRetry) { | 1631 TEST_F(SyncSchedulerImplTest, SuccessfulRetry) { |
| 1627 StartSyncScheduler(base::Time()); | 1632 StartSyncScheduler(base::Time()); |
| 1628 | 1633 |
| 1629 SyncShareTimes times; | 1634 SyncShareTimes times; |
| 1630 base::TimeDelta delay = base::TimeDelta::FromMilliseconds(10); | 1635 TimeDelta delay = TimeDelta::FromMilliseconds(10); |
| 1631 scheduler()->OnReceivedGuRetryDelay(delay); | 1636 scheduler()->OnReceivedGuRetryDelay(delay); |
| 1632 EXPECT_EQ(delay, GetRetryTimerDelay()); | 1637 EXPECT_EQ(delay, GetRetryTimerDelay()); |
| 1633 | 1638 |
| 1634 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 1639 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 1635 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), | 1640 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), |
| 1636 RecordSyncShare(×, true))); | 1641 RecordSyncShare(×, true))); |
| 1637 | 1642 |
| 1638 // Run to wait for retrying. | 1643 // Run to wait for retrying. |
| 1639 RunLoop(); | 1644 RunLoop(); |
| 1640 | 1645 |
| 1641 StopSyncScheduler(); | 1646 StopSyncScheduler(); |
| 1642 } | 1647 } |
| 1643 | 1648 |
| 1644 TEST_F(SyncSchedulerImplTest, FailedRetry) { | 1649 TEST_F(SyncSchedulerImplTest, FailedRetry) { |
| 1645 SyncShareTimes times; | 1650 SyncShareTimes times; |
| 1646 | 1651 |
| 1647 UseMockDelayProvider(); | 1652 UseMockDelayProvider(); |
| 1648 EXPECT_CALL(*delay(), GetDelay(_)) | 1653 EXPECT_CALL(*delay(), GetDelay(_)) |
| 1649 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(10))); | 1654 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(10))); |
| 1650 | 1655 |
| 1651 StartSyncScheduler(base::Time()); | 1656 StartSyncScheduler(base::Time()); |
| 1652 | 1657 |
| 1653 base::TimeDelta delay = base::TimeDelta::FromMilliseconds(10); | 1658 TimeDelta delay = TimeDelta::FromMilliseconds(10); |
| 1654 scheduler()->OnReceivedGuRetryDelay(delay); | 1659 scheduler()->OnReceivedGuRetryDelay(delay); |
| 1655 | 1660 |
| 1656 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 1661 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 1657 .WillOnce(DoAll(Invoke(test_util::SimulateDownloadUpdatesFailed), | 1662 .WillOnce(DoAll(Invoke(test_util::SimulateDownloadUpdatesFailed), |
| 1658 RecordSyncShare(×, false))); | 1663 RecordSyncShare(×, false))); |
| 1659 | 1664 |
| 1660 // Run to wait for retrying. | 1665 // Run to wait for retrying. |
| 1661 RunLoop(); | 1666 RunLoop(); |
| 1662 | 1667 |
| 1663 EXPECT_TRUE(scheduler()->IsBackingOff()); | 1668 EXPECT_TRUE(scheduler()->IsBackingOff()); |
| 1664 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 1669 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 1665 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), | 1670 .WillOnce(DoAll(Invoke(test_util::SimulateNormalSuccess), |
| 1666 RecordSyncShare(×, true))); | 1671 RecordSyncShare(×, true))); |
| 1667 | 1672 |
| 1668 // Run to wait for second retrying. | 1673 // Run to wait for second retrying. |
| 1669 RunLoop(); | 1674 RunLoop(); |
| 1670 | 1675 |
| 1671 StopSyncScheduler(); | 1676 StopSyncScheduler(); |
| 1672 } | 1677 } |
| 1673 | 1678 |
| 1674 ACTION_P2(VerifyRetryTimerDelay, scheduler_test, expected_delay) { | 1679 ACTION_P2(VerifyRetryTimerDelay, scheduler_test, expected_delay) { |
| 1675 EXPECT_EQ(expected_delay, scheduler_test->GetRetryTimerDelay()); | 1680 EXPECT_EQ(expected_delay, scheduler_test->GetRetryTimerDelay()); |
| 1676 } | 1681 } |
| 1677 | 1682 |
| 1678 TEST_F(SyncSchedulerImplTest, ReceiveNewRetryDelay) { | 1683 TEST_F(SyncSchedulerImplTest, ReceiveNewRetryDelay) { |
| 1679 StartSyncScheduler(base::Time()); | 1684 StartSyncScheduler(base::Time()); |
| 1680 | 1685 |
| 1681 SyncShareTimes times; | 1686 SyncShareTimes times; |
| 1682 base::TimeDelta delay1 = base::TimeDelta::FromMilliseconds(100); | 1687 TimeDelta delay1 = TimeDelta::FromMilliseconds(100); |
| 1683 base::TimeDelta delay2 = base::TimeDelta::FromMilliseconds(200); | 1688 TimeDelta delay2 = TimeDelta::FromMilliseconds(200); |
| 1684 | 1689 |
| 1685 scheduler()->ScheduleLocalNudge(ModelTypeSet(THEMES), FROM_HERE); | 1690 scheduler()->ScheduleLocalNudge(ModelTypeSet(THEMES), FROM_HERE); |
| 1686 scheduler()->OnReceivedGuRetryDelay(delay1); | 1691 scheduler()->OnReceivedGuRetryDelay(delay1); |
| 1687 EXPECT_EQ(delay1, GetRetryTimerDelay()); | 1692 EXPECT_EQ(delay1, GetRetryTimerDelay()); |
| 1688 | 1693 |
| 1689 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 1694 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 1690 .WillOnce( | 1695 .WillOnce( |
| 1691 DoAll(WithoutArgs(VerifyRetryTimerDelay(this, delay1)), | 1696 DoAll(WithoutArgs(VerifyRetryTimerDelay(this, delay1)), |
| 1692 WithArg<2>(test_util::SimulateGuRetryDelayCommand(delay2)), | 1697 WithArg<2>(test_util::SimulateGuRetryDelayCommand(delay2)), |
| 1693 RecordSyncShare(×, true))); | 1698 RecordSyncShare(×, true))); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1754 WithArg<2>(test_util::SimulatePartialFailure(types)), Return(true))) | 1759 WithArg<2>(test_util::SimulatePartialFailure(types)), Return(true))) |
| 1755 .RetiresOnSaturation(); | 1760 .RetiresOnSaturation(); |
| 1756 | 1761 |
| 1757 StartSyncScheduler(base::Time()); | 1762 StartSyncScheduler(base::Time()); |
| 1758 scheduler()->ScheduleLocalNudge(types, FROM_HERE); | 1763 scheduler()->ScheduleLocalNudge(types, FROM_HERE); |
| 1759 PumpLoop(); // To get PerformDelayedNudge called. | 1764 PumpLoop(); // To get PerformDelayedNudge called. |
| 1760 PumpLoop(); // To get TrySyncCycleJob called | 1765 PumpLoop(); // To get TrySyncCycleJob called |
| 1761 EXPECT_TRUE(GetBackedOffTypes().HasAll(types)); | 1766 EXPECT_TRUE(GetBackedOffTypes().HasAll(types)); |
| 1762 EXPECT_FALSE(scheduler()->IsBackingOff()); | 1767 EXPECT_FALSE(scheduler()->IsBackingOff()); |
| 1763 EXPECT_FALSE(scheduler()->IsCurrentlyThrottled()); | 1768 EXPECT_FALSE(scheduler()->IsCurrentlyThrottled()); |
| 1764 base::TimeDelta first_blocking_time = GetTypeBlockingTime(THEMES); | 1769 TimeDelta first_blocking_time = GetTypeBlockingTime(THEMES); |
| 1765 | 1770 |
| 1766 SetTypeBlockingMode(THEMES, WaitInterval::EXPONENTIAL_BACKOFF_RETRYING); | 1771 SetTypeBlockingMode(THEMES, WaitInterval::EXPONENTIAL_BACKOFF_RETRYING); |
| 1767 // This won't cause a sync cycle because the types are backed off. | 1772 // This won't cause a sync cycle because the types are backed off. |
| 1768 scheduler()->ScheduleLocalNudge(types, FROM_HERE); | 1773 scheduler()->ScheduleLocalNudge(types, FROM_HERE); |
| 1769 PumpLoop(); | 1774 PumpLoop(); |
| 1770 PumpLoop(); | 1775 PumpLoop(); |
| 1771 base::TimeDelta second_blocking_time = GetTypeBlockingTime(THEMES); | 1776 TimeDelta second_blocking_time = GetTypeBlockingTime(THEMES); |
| 1772 | 1777 |
| 1773 // The Exponential backoff should be between previous backoff 1.5 and 2.5 | 1778 // The Exponential backoff should be between previous backoff 1.5 and 2.5 |
| 1774 // times. | 1779 // times. |
| 1775 EXPECT_LE(first_blocking_time * 1.5, second_blocking_time); | 1780 EXPECT_LE(first_blocking_time * 1.5, second_blocking_time); |
| 1776 EXPECT_GE(first_blocking_time * 2.5, second_blocking_time); | 1781 EXPECT_GE(first_blocking_time * 2.5, second_blocking_time); |
| 1777 | 1782 |
| 1778 StopSyncScheduler(); | 1783 StopSyncScheduler(); |
| 1779 } | 1784 } |
| 1780 | 1785 |
| 1781 // If a datatype is in backoff or throttling, pending_wakeup_timer_ should | 1786 // If a datatype is in backoff or throttling, pending_wakeup_timer_ should |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1893 // Timer is still scheduled for another backoff datatype. | 1898 // Timer is still scheduled for another backoff datatype. |
| 1894 EXPECT_TRUE(GetBackedOffTypes().HasAll(themes_types)); | 1899 EXPECT_TRUE(GetBackedOffTypes().HasAll(themes_types)); |
| 1895 EXPECT_FALSE(GetBackedOffTypes().HasAll(typed_urls_types)); | 1900 EXPECT_FALSE(GetBackedOffTypes().HasAll(typed_urls_types)); |
| 1896 EXPECT_TRUE(BlockTimerIsRunning()); | 1901 EXPECT_TRUE(BlockTimerIsRunning()); |
| 1897 EXPECT_FALSE(scheduler()->IsBackingOff()); | 1902 EXPECT_FALSE(scheduler()->IsBackingOff()); |
| 1898 EXPECT_FALSE(scheduler()->IsCurrentlyThrottled()); | 1903 EXPECT_FALSE(scheduler()->IsCurrentlyThrottled()); |
| 1899 | 1904 |
| 1900 StopSyncScheduler(); | 1905 StopSyncScheduler(); |
| 1901 } | 1906 } |
| 1902 | 1907 |
| 1908 TEST_F(SyncSchedulerImplTest, InterleavedNudgesStillRestart) { |
| 1909 UseMockDelayProvider(); |
| 1910 EXPECT_CALL(*delay(), GetDelay(_)) |
| 1911 .WillOnce(Return(long_delay())) |
| 1912 .RetiresOnSaturation(); |
| 1913 TimeDelta poll(TimeDelta::FromDays(1)); |
| 1914 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
| 1915 |
| 1916 StartSyncScheduler(base::Time()); |
| 1917 scheduler()->ScheduleLocalNudge({THEMES}, FROM_HERE); |
| 1918 PumpLoop(); // To get PerformDelayedNudge called. |
| 1919 EXPECT_FALSE(BlockTimerIsRunning()); |
| 1920 EXPECT_FALSE(scheduler()->IsBackingOff()); |
| 1921 |
| 1922 // This is the tricky piece. We have a gap while the sync job is bouncing to |
| 1923 // get onto the |pending_wakeup_timer_|, should be scheduled with no delay. |
| 1924 scheduler()->ScheduleLocalNudge({TYPED_URLS}, FROM_HERE); |
| 1925 EXPECT_TRUE(BlockTimerIsRunning()); |
| 1926 EXPECT_EQ(TimeDelta(), GetPendingWakeupTimerDelay()); |
| 1927 EXPECT_FALSE(scheduler()->IsBackingOff()); |
| 1928 |
| 1929 // Setup mock as we're about to attempt to sync. |
| 1930 SyncShareTimes times; |
| 1931 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 1932 .WillOnce(DoAll(Invoke(test_util::SimulateCommitFailed), |
| 1933 RecordSyncShare(×, false))); |
| 1934 // Triggers the THEMES TrySyncCycleJobImpl(), which we've setup to fail. Its |
| 1935 // RestartWaiting won't schedule a delayed retry, as the TYPED_URLS nudge has |
| 1936 // a smaller delay. We verify this by making sure the delay is still zero. |
| 1937 PumpLoop(); |
| 1938 EXPECT_TRUE(BlockTimerIsRunning()); |
| 1939 EXPECT_EQ(TimeDelta(), GetPendingWakeupTimerDelay()); |
| 1940 EXPECT_TRUE(scheduler()->IsBackingOff()); |
| 1941 |
| 1942 // Triggers TYPED_URLS PerformDelayedNudge(), which should no-op, because |
| 1943 // we're no long healthy, and normal priorities shouldn't go through, but it |
| 1944 // does need to setup the |pending_wakeup_timer_|. The delay should be ~60 |
| 1945 // seconds, so verifying it's greater than 50 should be safe. |
| 1946 PumpLoop(); |
| 1947 EXPECT_TRUE(BlockTimerIsRunning()); |
| 1948 EXPECT_LT(TimeDelta::FromSeconds(50), GetPendingWakeupTimerDelay()); |
| 1949 EXPECT_TRUE(scheduler()->IsBackingOff()); |
| 1950 } |
| 1951 |
| 1903 } // namespace syncer | 1952 } // namespace syncer |
| OLD | NEW |