Chromium Code Reviews| 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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 syncer_); | 162 syncer_); |
| 163 scheduler_->SetDefaultNudgeDelay(default_delay()); | 163 scheduler_->SetDefaultNudgeDelay(default_delay()); |
| 164 } | 164 } |
| 165 | 165 |
| 166 SyncSchedulerImpl* scheduler() { return scheduler_.get(); } | 166 SyncSchedulerImpl* scheduler() { return scheduler_.get(); } |
| 167 const ModelSafeRoutingInfo& routing_info() { return routing_info_; } | 167 const ModelSafeRoutingInfo& routing_info() { return routing_info_; } |
| 168 MockSyncer* syncer() { return syncer_; } | 168 MockSyncer* syncer() { return syncer_; } |
| 169 MockDelayProvider* delay() { return delay_; } | 169 MockDelayProvider* delay() { return delay_; } |
| 170 MockConnectionManager* connection() { return connection_.get(); } | 170 MockConnectionManager* connection() { return connection_.get(); } |
| 171 TimeDelta default_delay() { return TimeDelta::FromSeconds(0); } | 171 TimeDelta default_delay() { return TimeDelta::FromSeconds(0); } |
| 172 TimeDelta long_delay() { return TimeDelta::FromSeconds(60); } | |
| 172 TimeDelta timeout() { return TestTimeouts::action_timeout(); } | 173 TimeDelta timeout() { return TestTimeouts::action_timeout(); } |
| 173 | 174 |
| 174 void TearDown() override { | 175 void TearDown() override { |
| 175 PumpLoop(); | 176 PumpLoop(); |
| 176 scheduler_.reset(); | 177 scheduler_.reset(); |
| 177 PumpLoop(); | 178 PumpLoop(); |
| 178 test_user_share_.TearDown(); | 179 test_user_share_.TearDown(); |
| 179 } | 180 } |
| 180 | 181 |
| 181 void AnalyzePollRun(const SyncShareTimes& times, | 182 void AnalyzePollRun(const SyncShareTimes& times, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 219 } | 220 } |
| 220 | 221 |
| 221 void UseMockDelayProvider() { | 222 void UseMockDelayProvider() { |
| 222 delay_ = new MockDelayProvider(); | 223 delay_ = new MockDelayProvider(); |
| 223 scheduler_->delay_provider_.reset(delay_); | 224 scheduler_->delay_provider_.reset(delay_); |
| 224 } | 225 } |
| 225 | 226 |
| 226 SyncCycleContext* context() { return context_.get(); } | 227 SyncCycleContext* context() { return context_.get(); } |
| 227 | 228 |
| 228 ModelTypeSet GetThrottledTypes() { | 229 ModelTypeSet GetThrottledTypes() { |
| 229 return scheduler_->nudge_tracker_.GetThrottledTypes(); | 230 ModelTypeSet throttled_types; |
| 231 ModelTypeSet blocked_types = scheduler_->nudge_tracker_.GetBlockedTypes(); | |
| 232 for (ModelTypeSet::Iterator type_it = blocked_types.First(); type_it.Good(); | |
| 233 type_it.Inc()) { | |
| 234 if (scheduler_->nudge_tracker_.GetTypeBlockingMode(type_it.Get()) == | |
| 235 WaitInterval::THROTTLED) { | |
| 236 throttled_types.Put(type_it.Get()); | |
| 237 } | |
| 238 } | |
| 239 return throttled_types; | |
| 240 } | |
| 241 | |
| 242 ModelTypeSet GetBackedOffTypes() { | |
| 243 ModelTypeSet backed_off_types; | |
| 244 ModelTypeSet blocked_types = scheduler_->nudge_tracker_.GetBlockedTypes(); | |
| 245 for (ModelTypeSet::Iterator type_it = blocked_types.First(); type_it.Good(); | |
| 246 type_it.Inc()) { | |
| 247 if (scheduler_->nudge_tracker_.GetTypeBlockingMode(type_it.Get()) == | |
| 248 WaitInterval::EXPONENTIAL_BACKOFF) { | |
| 249 backed_off_types.Put(type_it.Get()); | |
| 250 } | |
| 251 } | |
| 252 return backed_off_types; | |
| 253 } | |
| 254 | |
| 255 bool IsAnyTypeBlocked() { | |
| 256 return scheduler_->nudge_tracker_.IsAnyTypeBlocked(); | |
| 230 } | 257 } |
| 231 | 258 |
| 232 base::TimeDelta GetRetryTimerDelay() { | 259 base::TimeDelta GetRetryTimerDelay() { |
| 233 EXPECT_TRUE(scheduler_->retry_timer_.IsRunning()); | 260 EXPECT_TRUE(scheduler_->retry_timer_.IsRunning()); |
| 234 return scheduler_->retry_timer_.GetCurrentDelay(); | 261 return scheduler_->retry_timer_.GetCurrentDelay(); |
| 235 } | 262 } |
| 236 | 263 |
| 237 static std::unique_ptr<InvalidationInterface> BuildInvalidation( | 264 static std::unique_ptr<InvalidationInterface> BuildInvalidation( |
| 238 int64_t version, | 265 int64_t version, |
| 239 const std::string& payload) { | 266 const std::string& payload) { |
| 240 return MockInvalidation::Build(version, payload); | 267 return MockInvalidation::Build(version, payload); |
| 241 } | 268 } |
| 242 | 269 |
| 270 base::TimeDelta GetTypeBlockingTime(ModelType type) { | |
| 271 NudgeTracker::TypeTrackerMap::const_iterator tracker_it = | |
| 272 scheduler_->nudge_tracker_.type_trackers_.find(type); | |
| 273 DCHECK(tracker_it != scheduler_->nudge_tracker_.type_trackers_.end()); | |
| 274 return tracker_it->second->GetTimeUntilUnblock(); | |
|
Nicolas Zea
2016/11/14 21:57:15
I think it would be better to query the wait inter
Gang Wu
2016/11/15 01:59:32
Done.
| |
| 275 } | |
| 276 | |
| 277 void SetTypeBlockingMode(ModelType type, WaitInterval::BlockingMode mode) { | |
| 278 NudgeTracker::TypeTrackerMap::const_iterator tracker_it = | |
| 279 scheduler_->nudge_tracker_.type_trackers_.find(type); | |
| 280 DCHECK(tracker_it != scheduler_->nudge_tracker_.type_trackers_.end()); | |
| 281 DCHECK(tracker_it->second->wait_interval_.get()); | |
| 282 tracker_it->second->wait_interval_->mode = mode; | |
| 283 } | |
| 284 | |
| 243 private: | 285 private: |
| 244 syncable::Directory* directory() { | 286 syncable::Directory* directory() { |
| 245 return test_user_share_.user_share()->directory.get(); | 287 return test_user_share_.user_share()->directory.get(); |
| 246 } | 288 } |
| 247 | 289 |
| 248 base::MessageLoop loop_; | 290 base::MessageLoop loop_; |
| 249 TestUserShare test_user_share_; | 291 TestUserShare test_user_share_; |
| 250 CancelationSignal cancelation_signal_; | 292 CancelationSignal cancelation_signal_; |
| 251 std::unique_ptr<MockConnectionManager> connection_; | 293 std::unique_ptr<MockConnectionManager> connection_; |
| 252 std::unique_ptr<ModelTypeRegistry> model_type_registry_; | 294 std::unique_ptr<ModelTypeRegistry> model_type_registry_; |
| (...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 798 EXPECT_EQ(1, retry_counter.times_called()); | 840 EXPECT_EQ(1, retry_counter.times_called()); |
| 799 EXPECT_TRUE(scheduler()->IsCurrentlyThrottled()); | 841 EXPECT_TRUE(scheduler()->IsCurrentlyThrottled()); |
| 800 | 842 |
| 801 RunLoop(); | 843 RunLoop(); |
| 802 EXPECT_FALSE(scheduler()->IsCurrentlyThrottled()); | 844 EXPECT_FALSE(scheduler()->IsCurrentlyThrottled()); |
| 803 | 845 |
| 804 StopSyncScheduler(); | 846 StopSyncScheduler(); |
| 805 } | 847 } |
| 806 | 848 |
| 807 TEST_F(SyncSchedulerImplTest, TypeThrottlingBlocksNudge) { | 849 TEST_F(SyncSchedulerImplTest, TypeThrottlingBlocksNudge) { |
| 808 UseMockDelayProvider(); | |
| 809 EXPECT_CALL(*delay(), GetDelay(_)).WillRepeatedly(Return(default_delay())); | |
| 810 | |
| 811 TimeDelta poll(TimeDelta::FromDays(1)); | 850 TimeDelta poll(TimeDelta::FromDays(1)); |
| 812 TimeDelta throttle1(TimeDelta::FromSeconds(60)); | 851 TimeDelta throttle1(TimeDelta::FromSeconds(60)); |
| 813 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 852 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
| 814 | 853 |
| 815 const ModelTypeSet types(THEMES); | 854 const ModelTypeSet types(THEMES); |
| 816 | 855 |
| 817 ::testing::InSequence seq; | 856 ::testing::InSequence seq; |
| 818 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 857 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 819 .WillOnce( | 858 .WillOnce( |
| 820 DoAll(WithArg<2>(test_util::SimulateTypesThrottled(types, throttle1)), | 859 DoAll(WithArg<2>(test_util::SimulateTypesThrottled(types, throttle1)), |
| 821 Return(false))) | 860 Return(true))) |
| 822 .RetiresOnSaturation(); | 861 .RetiresOnSaturation(); |
| 823 | 862 |
| 824 StartSyncScheduler(base::Time()); | 863 StartSyncScheduler(base::Time()); |
| 825 scheduler()->ScheduleLocalNudge(types, FROM_HERE); | 864 scheduler()->ScheduleLocalNudge(types, FROM_HERE); |
| 826 PumpLoop(); // To get PerformDelayedNudge called. | 865 PumpLoop(); // To get PerformDelayedNudge called. |
| 827 PumpLoop(); // To get TrySyncCycleJob called | 866 PumpLoop(); // To get TrySyncCycleJob called |
| 828 EXPECT_TRUE(GetThrottledTypes().HasAll(types)); | 867 EXPECT_TRUE(GetThrottledTypes().HasAll(types)); |
| 868 EXPECT_FALSE(scheduler()->IsBackingOff()); | |
| 869 EXPECT_FALSE(scheduler()->IsCurrentlyThrottled()); | |
| 829 | 870 |
| 830 // This won't cause a sync cycle because the types are throttled. | 871 // This won't cause a sync cycle because the types are throttled. |
| 831 scheduler()->ScheduleLocalNudge(types, FROM_HERE); | 872 scheduler()->ScheduleLocalNudge(types, FROM_HERE); |
| 832 PumpLoop(); | 873 PumpLoop(); |
| 833 | 874 |
| 834 StopSyncScheduler(); | 875 StopSyncScheduler(); |
| 835 } | 876 } |
| 836 | 877 |
| 878 TEST_F(SyncSchedulerImplTest, TypeBackingOffBlocksNudge) { | |
| 879 UseMockDelayProvider(); | |
| 880 EXPECT_CALL(*delay(), GetDelay(_)).WillRepeatedly(Return(long_delay())); | |
| 881 | |
| 882 TimeDelta poll(TimeDelta::FromDays(1)); | |
| 883 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | |
| 884 | |
| 885 const ModelTypeSet types(THEMES); | |
| 886 | |
| 887 ::testing::InSequence seq; | |
| 888 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | |
| 889 .WillOnce(DoAll(WithArg<2>(test_util::SimulatePartialFailure(types)), | |
| 890 Return(true))) | |
| 891 .RetiresOnSaturation(); | |
| 892 | |
| 893 StartSyncScheduler(base::Time()); | |
| 894 scheduler()->ScheduleLocalNudge(types, FROM_HERE); | |
| 895 PumpLoop(); // To get PerformDelayedNudge called. | |
| 896 PumpLoop(); // To get TrySyncCycleJob called | |
| 897 EXPECT_TRUE(GetBackedOffTypes().HasAll(types)); | |
| 898 EXPECT_FALSE(scheduler()->IsBackingOff()); | |
| 899 EXPECT_FALSE(scheduler()->IsCurrentlyThrottled()); | |
| 900 | |
| 901 // This won't cause a sync cycle because the types are backed off. | |
| 902 scheduler()->ScheduleLocalNudge(types, FROM_HERE); | |
| 903 PumpLoop(); | |
| 904 | |
| 905 StopSyncScheduler(); | |
| 906 } | |
| 907 | |
| 908 TEST_F(SyncSchedulerImplTest, TypeBackingOffWillExpire) { | |
| 909 UseMockDelayProvider(); | |
| 910 EXPECT_CALL(*delay(), GetDelay(_)).WillRepeatedly(Return(default_delay())); | |
| 911 | |
| 912 TimeDelta poll(TimeDelta::FromDays(1)); | |
| 913 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | |
| 914 | |
| 915 const ModelTypeSet types(THEMES); | |
| 916 | |
| 917 ::testing::InSequence seq; | |
| 918 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | |
| 919 .WillOnce(DoAll(WithArg<2>(test_util::SimulatePartialFailure(types)), | |
| 920 Return(true))) | |
| 921 .RetiresOnSaturation(); | |
| 922 | |
| 923 StartSyncScheduler(base::Time()); | |
| 924 scheduler()->ScheduleLocalNudge(types, FROM_HERE); | |
| 925 PumpLoop(); // To get PerformDelayedNudge called. | |
| 926 PumpLoop(); // To get TrySyncCycleJob called | |
| 927 EXPECT_TRUE(GetBackedOffTypes().HasAll(types)); | |
| 928 EXPECT_FALSE(scheduler()->IsBackingOff()); | |
| 929 EXPECT_FALSE(scheduler()->IsCurrentlyThrottled()); | |
| 930 | |
| 931 SyncShareTimes times; | |
| 932 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | |
| 933 .WillRepeatedly(DoAll(Invoke(test_util::SimulateNormalSuccess), | |
| 934 RecordSyncShare(×, true))); | |
| 935 PumpLoop(); // To get PerformDelayedNudge called. | |
| 936 PumpLoop(); // To get TrySyncCycleJob called | |
| 937 EXPECT_FALSE(IsAnyTypeBlocked()); | |
| 938 EXPECT_FALSE(scheduler()->IsBackingOff()); | |
| 939 EXPECT_FALSE(scheduler()->IsCurrentlyThrottled()); | |
| 940 | |
| 941 StopSyncScheduler(); | |
| 942 } | |
| 943 | |
| 944 TEST_F(SyncSchedulerImplTest, TypeBackingOffAndThrottling) { | |
| 945 UseMockDelayProvider(); | |
| 946 EXPECT_CALL(*delay(), GetDelay(_)).WillRepeatedly(Return(long_delay())); | |
| 947 | |
| 948 TimeDelta poll(TimeDelta::FromDays(1)); | |
| 949 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | |
| 950 | |
| 951 const ModelTypeSet types(THEMES); | |
| 952 | |
| 953 ::testing::InSequence seq; | |
| 954 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | |
| 955 .WillOnce(DoAll(WithArg<2>(test_util::SimulatePartialFailure(types)), | |
| 956 Return(true))) | |
| 957 .RetiresOnSaturation(); | |
| 958 | |
| 959 StartSyncScheduler(base::Time()); | |
| 960 scheduler()->ScheduleLocalNudge(types, FROM_HERE); | |
| 961 PumpLoop(); // To get PerformDelayedNudge called. | |
| 962 PumpLoop(); // To get TrySyncCycleJob called | |
| 963 EXPECT_TRUE(GetBackedOffTypes().HasAll(types)); | |
| 964 EXPECT_FALSE(scheduler()->IsBackingOff()); | |
| 965 EXPECT_FALSE(scheduler()->IsCurrentlyThrottled()); | |
| 966 | |
| 967 TimeDelta throttle1(TimeDelta::FromMilliseconds(150)); | |
| 968 | |
| 969 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | |
| 970 .WillOnce(DoAll(WithArg<2>(test_util::SimulateThrottled(throttle1)), | |
| 971 Return(false))) | |
| 972 .RetiresOnSaturation(); | |
| 973 | |
| 974 // Sync still can throttle. | |
| 975 const ModelTypeSet unbacked_off_types(TYPED_URLS); | |
| 976 scheduler()->ScheduleLocalNudge(unbacked_off_types, FROM_HERE); | |
| 977 PumpLoop(); // TO get TypesUnblock called. | |
| 978 PumpLoop(); // To get TrySyncCycleJob called. | |
| 979 | |
| 980 EXPECT_TRUE(GetBackedOffTypes().HasAll(types)); | |
| 981 EXPECT_FALSE(scheduler()->IsBackingOff()); | |
| 982 EXPECT_TRUE(scheduler()->IsCurrentlyThrottled()); | |
| 983 | |
| 984 StopSyncScheduler(); | |
| 985 } | |
| 986 | |
| 987 TEST_F(SyncSchedulerImplTest, TypeThrottlingBackingOffBlocksNudge) { | |
| 988 UseMockDelayProvider(); | |
| 989 EXPECT_CALL(*delay(), GetDelay(_)).WillRepeatedly(Return(long_delay())); | |
| 990 | |
| 991 TimeDelta poll(TimeDelta::FromDays(1)); | |
| 992 TimeDelta throttle(TimeDelta::FromSeconds(60)); | |
| 993 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | |
| 994 | |
| 995 const ModelTypeSet throttled_types(THEMES); | |
| 996 | |
| 997 ::testing::InSequence seq; | |
| 998 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | |
| 999 .WillOnce(DoAll(WithArg<2>(test_util::SimulateTypesThrottled( | |
| 1000 throttled_types, throttle)), | |
| 1001 Return(true))) | |
| 1002 .RetiresOnSaturation(); | |
| 1003 | |
| 1004 StartSyncScheduler(base::Time()); | |
| 1005 scheduler()->ScheduleLocalNudge(throttled_types, FROM_HERE); | |
| 1006 PumpLoop(); // To get PerformDelayedNudge called. | |
| 1007 PumpLoop(); // To get TrySyncCycleJob called | |
| 1008 | |
| 1009 const ModelTypeSet backed_off_types(TYPED_URLS); | |
| 1010 | |
| 1011 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | |
| 1012 .WillOnce( | |
| 1013 DoAll(WithArg<2>(test_util::SimulatePartialFailure(backed_off_types)), | |
| 1014 Return(true))) | |
| 1015 .RetiresOnSaturation(); | |
| 1016 | |
| 1017 scheduler()->ScheduleLocalNudge(backed_off_types, FROM_HERE); | |
| 1018 | |
| 1019 PumpLoop(); // To get PerformDelayedNudge called. | |
| 1020 PumpLoop(); // To get TrySyncCycleJob called | |
| 1021 | |
| 1022 EXPECT_TRUE(GetThrottledTypes().HasAll(throttled_types)); | |
| 1023 EXPECT_TRUE(GetBackedOffTypes().HasAll(backed_off_types)); | |
| 1024 EXPECT_FALSE(scheduler()->IsBackingOff()); | |
| 1025 EXPECT_FALSE(scheduler()->IsCurrentlyThrottled()); | |
| 1026 | |
| 1027 // This won't cause a sync cycle because the types are throttled or backed | |
| 1028 // off. | |
| 1029 scheduler()->ScheduleLocalNudge(Union(throttled_types, backed_off_types), | |
| 1030 FROM_HERE); | |
| 1031 PumpLoop(); | |
| 1032 | |
| 1033 StopSyncScheduler(); | |
| 1034 } | |
| 1035 | |
| 837 TEST_F(SyncSchedulerImplTest, TypeThrottlingDoesBlockOtherSources) { | 1036 TEST_F(SyncSchedulerImplTest, TypeThrottlingDoesBlockOtherSources) { |
| 838 UseMockDelayProvider(); | 1037 UseMockDelayProvider(); |
| 839 EXPECT_CALL(*delay(), GetDelay(_)).WillRepeatedly(Return(default_delay())); | 1038 EXPECT_CALL(*delay(), GetDelay(_)).WillRepeatedly(Return(default_delay())); |
| 840 | 1039 |
| 841 SyncShareTimes times; | 1040 SyncShareTimes times; |
| 842 TimeDelta poll(TimeDelta::FromDays(1)); | 1041 TimeDelta poll(TimeDelta::FromDays(1)); |
| 843 TimeDelta throttle1(TimeDelta::FromSeconds(60)); | 1042 TimeDelta throttle1(TimeDelta::FromSeconds(60)); |
| 844 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 1043 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
| 845 | 1044 |
| 846 const ModelTypeSet throttled_types(THEMES); | 1045 const ModelTypeSet throttled_types(THEMES); |
| 847 const ModelTypeSet unthrottled_types(PREFERENCES); | 1046 const ModelTypeSet unthrottled_types(PREFERENCES); |
| 848 | 1047 |
| 849 ::testing::InSequence seq; | 1048 ::testing::InSequence seq; |
| 850 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 1049 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 851 .WillOnce(DoAll(WithArg<2>(test_util::SimulateTypesThrottled( | 1050 .WillOnce(DoAll(WithArg<2>(test_util::SimulateTypesThrottled( |
| 852 throttled_types, throttle1)), | 1051 throttled_types, throttle1)), |
| 853 Return(false))) | 1052 Return(true))) |
| 854 .RetiresOnSaturation(); | 1053 .RetiresOnSaturation(); |
| 855 | 1054 |
| 856 StartSyncScheduler(base::Time()); | 1055 StartSyncScheduler(base::Time()); |
| 857 scheduler()->ScheduleLocalNudge(throttled_types, FROM_HERE); | 1056 scheduler()->ScheduleLocalNudge(throttled_types, FROM_HERE); |
| 858 PumpLoop(); // To get PerformDelayedNudge called. | 1057 PumpLoop(); // To get PerformDelayedNudge called. |
| 859 PumpLoop(); // To get TrySyncCycleJob called | 1058 PumpLoop(); // To get TrySyncCycleJob called |
| 860 EXPECT_TRUE(GetThrottledTypes().HasAll(throttled_types)); | 1059 EXPECT_TRUE(GetThrottledTypes().HasAll(throttled_types)); |
| 1060 EXPECT_FALSE(scheduler()->IsBackingOff()); | |
| 1061 EXPECT_FALSE(scheduler()->IsCurrentlyThrottled()); | |
| 861 | 1062 |
| 862 // Ignore invalidations for throttled types. | 1063 // Ignore invalidations for throttled types. |
| 863 scheduler()->ScheduleInvalidationNudge(THEMES, BuildInvalidation(10, "test"), | 1064 scheduler()->ScheduleInvalidationNudge(THEMES, BuildInvalidation(10, "test"), |
| 864 FROM_HERE); | 1065 FROM_HERE); |
| 865 PumpLoop(); | 1066 PumpLoop(); |
| 866 | 1067 |
| 867 // Ignore refresh requests for throttled types. | 1068 // Ignore refresh requests for throttled types. |
| 868 scheduler()->ScheduleLocalRefreshRequest(throttled_types, FROM_HERE); | 1069 scheduler()->ScheduleLocalRefreshRequest(throttled_types, FROM_HERE); |
| 869 PumpLoop(); | 1070 PumpLoop(); |
| 870 | 1071 |
| 871 Mock::VerifyAndClearExpectations(syncer()); | 1072 Mock::VerifyAndClearExpectations(syncer()); |
| 872 | 1073 |
| 873 // Local nudges for non-throttled types will trigger a sync. | 1074 // Local nudges for non-throttled types will trigger a sync. |
| 874 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 1075 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 875 .WillRepeatedly(DoAll(Invoke(test_util::SimulateNormalSuccess), | 1076 .WillRepeatedly(DoAll(Invoke(test_util::SimulateNormalSuccess), |
| 876 RecordSyncShare(×, true))); | 1077 RecordSyncShare(×, true))); |
| 877 scheduler()->ScheduleLocalNudge(unthrottled_types, FROM_HERE); | 1078 scheduler()->ScheduleLocalNudge(unthrottled_types, FROM_HERE); |
| 878 RunLoop(); | 1079 RunLoop(); |
| 879 Mock::VerifyAndClearExpectations(syncer()); | 1080 Mock::VerifyAndClearExpectations(syncer()); |
| 880 | 1081 |
| 881 StopSyncScheduler(); | 1082 StopSyncScheduler(); |
| 882 } | 1083 } |
| 883 | 1084 |
| 1085 TEST_F(SyncSchedulerImplTest, TypeBackingOffDoesBlockOtherSources) { | |
| 1086 UseMockDelayProvider(); | |
| 1087 EXPECT_CALL(*delay(), GetDelay(_)).WillRepeatedly(Return(long_delay())); | |
| 1088 | |
| 1089 SyncShareTimes times; | |
| 1090 TimeDelta poll(TimeDelta::FromDays(1)); | |
| 1091 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | |
| 1092 | |
| 1093 const ModelTypeSet backed_off_types(THEMES); | |
| 1094 const ModelTypeSet unbacked_off_types(PREFERENCES); | |
| 1095 | |
| 1096 ::testing::InSequence seq; | |
| 1097 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | |
| 1098 .WillOnce( | |
| 1099 DoAll(WithArg<2>(test_util::SimulatePartialFailure(backed_off_types)), | |
| 1100 Return(true))) | |
| 1101 .RetiresOnSaturation(); | |
| 1102 | |
| 1103 StartSyncScheduler(base::Time()); | |
| 1104 scheduler()->ScheduleLocalNudge(backed_off_types, FROM_HERE); | |
| 1105 PumpLoop(); // To get PerformDelayedNudge called. | |
| 1106 PumpLoop(); // To get TrySyncCycleJob called | |
| 1107 EXPECT_TRUE(GetBackedOffTypes().HasAll(backed_off_types)); | |
| 1108 EXPECT_FALSE(scheduler()->IsBackingOff()); | |
| 1109 EXPECT_FALSE(scheduler()->IsCurrentlyThrottled()); | |
| 1110 | |
| 1111 // Ignore invalidations for backed off types. | |
| 1112 scheduler()->ScheduleInvalidationNudge(THEMES, BuildInvalidation(10, "test"), | |
| 1113 FROM_HERE); | |
| 1114 PumpLoop(); | |
| 1115 | |
| 1116 // Ignore refresh requests for backed off types. | |
| 1117 scheduler()->ScheduleLocalRefreshRequest(backed_off_types, FROM_HERE); | |
| 1118 PumpLoop(); | |
| 1119 | |
| 1120 Mock::VerifyAndClearExpectations(syncer()); | |
| 1121 | |
| 1122 // Local nudges for non-backed off types will trigger a sync. | |
| 1123 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | |
| 1124 .WillRepeatedly(DoAll(Invoke(test_util::SimulateNormalSuccess), | |
| 1125 RecordSyncShare(×, true))); | |
| 1126 scheduler()->ScheduleLocalNudge(unbacked_off_types, FROM_HERE); | |
| 1127 RunLoop(); | |
| 1128 Mock::VerifyAndClearExpectations(syncer()); | |
| 1129 | |
| 1130 StopSyncScheduler(); | |
| 1131 } | |
| 1132 | |
| 884 // Test nudges / polls don't run in config mode and config tasks do. | 1133 // Test nudges / polls don't run in config mode and config tasks do. |
| 885 TEST_F(SyncSchedulerImplTest, ConfigurationMode) { | 1134 TEST_F(SyncSchedulerImplTest, ConfigurationMode) { |
| 886 TimeDelta poll(TimeDelta::FromMilliseconds(15)); | 1135 TimeDelta poll(TimeDelta::FromMilliseconds(15)); |
| 887 SyncShareTimes times; | 1136 SyncShareTimes times; |
| 888 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 1137 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
| 889 | 1138 |
| 890 StartSyncConfiguration(); | 1139 StartSyncConfiguration(); |
| 891 | 1140 |
| 892 const ModelTypeSet nudge_types(TYPED_URLS); | 1141 const ModelTypeSet nudge_types(TYPED_URLS); |
| 893 scheduler()->ScheduleLocalNudge(nudge_types, FROM_HERE); | 1142 scheduler()->ScheduleLocalNudge(nudge_types, FROM_HERE); |
| (...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1432 ASSERT_EQ(0, success_counter.times_called()); | 1681 ASSERT_EQ(0, success_counter.times_called()); |
| 1433 ASSERT_TRUE(scheduler()->IsBackingOff()); | 1682 ASSERT_TRUE(scheduler()->IsBackingOff()); |
| 1434 | 1683 |
| 1435 // Now succeed. | 1684 // Now succeed. |
| 1436 connection()->SetServerReachable(); | 1685 connection()->SetServerReachable(); |
| 1437 PumpLoopFor(2 * delta); | 1686 PumpLoopFor(2 * delta); |
| 1438 ASSERT_EQ(1, success_counter.times_called()); | 1687 ASSERT_EQ(1, success_counter.times_called()); |
| 1439 ASSERT_FALSE(scheduler()->IsBackingOff()); | 1688 ASSERT_FALSE(scheduler()->IsBackingOff()); |
| 1440 } | 1689 } |
| 1441 | 1690 |
| 1691 TEST_F(SyncSchedulerImplTest, PartialFailureWillExponentialBackoff) { | |
| 1692 TimeDelta poll(TimeDelta::FromDays(1)); | |
| 1693 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | |
| 1694 | |
| 1695 const ModelTypeSet types(THEMES); | |
| 1696 | |
| 1697 ::testing::InSequence seq; | |
| 1698 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | |
| 1699 .WillRepeatedly(DoAll( | |
| 1700 WithArg<2>(test_util::SimulatePartialFailure(types)), Return(true))) | |
| 1701 .RetiresOnSaturation(); | |
| 1702 | |
| 1703 StartSyncScheduler(base::Time()); | |
| 1704 scheduler()->ScheduleLocalNudge(types, FROM_HERE); | |
| 1705 PumpLoop(); // To get PerformDelayedNudge called. | |
| 1706 PumpLoop(); // To get TrySyncCycleJob called | |
| 1707 EXPECT_TRUE(GetBackedOffTypes().HasAll(types)); | |
| 1708 EXPECT_FALSE(scheduler()->IsBackingOff()); | |
| 1709 EXPECT_FALSE(scheduler()->IsCurrentlyThrottled()); | |
| 1710 base::TimeDelta first_blocking_time = GetTypeBlockingTime(THEMES); | |
| 1711 | |
| 1712 SetTypeBlockingMode(THEMES, WaitInterval::EXPONENTIAL_BACKOFF_RETRYING); | |
| 1713 // This won't cause a sync cycle because the types are backed off. | |
| 1714 scheduler()->ScheduleLocalNudge(types, FROM_HERE); | |
| 1715 PumpLoop(); | |
| 1716 PumpLoop(); | |
| 1717 base::TimeDelta second_blocking_time = GetTypeBlockingTime(THEMES); | |
| 1718 | |
| 1719 // The Exponential backoff should between previous backoff 1.5 and 2.5 times. | |
|
Nicolas Zea
2016/11/14 21:57:15
"should between" -> "should be between"
Gang Wu
2016/11/15 01:59:32
Done.
| |
| 1720 // But |GetTypeBlockingTime| is to get time delta from base::Time::Now() to | |
| 1721 // next un-backoff, so we enlarge our scope from 1.5-2.5 to 1.4-2.6 to avoid | |
| 1722 // delay between "set backoff" and |GetTypeBlockingTime|. | |
| 1723 EXPECT_LE(first_blocking_time * 1.4, second_blocking_time); | |
|
Nicolas Zea
2016/11/14 21:57:15
If you query the interval time, rather than time u
Gang Wu
2016/11/15 01:59:32
Done.
| |
| 1724 EXPECT_GE(first_blocking_time * 2.6, second_blocking_time); | |
| 1725 | |
| 1726 StopSyncScheduler(); | |
| 1727 } | |
| 1728 | |
| 1442 } // namespace syncer | 1729 } // namespace syncer |
| OLD | NEW |