| 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 DCHECK(tracker_it->second->wait_interval_.get()); |
| 275 return tracker_it->second->wait_interval_->length; |
| 276 } |
| 277 |
| 278 void SetTypeBlockingMode(ModelType type, WaitInterval::BlockingMode mode) { |
| 279 NudgeTracker::TypeTrackerMap::const_iterator tracker_it = |
| 280 scheduler_->nudge_tracker_.type_trackers_.find(type); |
| 281 DCHECK(tracker_it != scheduler_->nudge_tracker_.type_trackers_.end()); |
| 282 DCHECK(tracker_it->second->wait_interval_.get()); |
| 283 tracker_it->second->wait_interval_->mode = mode; |
| 284 } |
| 285 |
| 243 private: | 286 private: |
| 244 syncable::Directory* directory() { | 287 syncable::Directory* directory() { |
| 245 return test_user_share_.user_share()->directory.get(); | 288 return test_user_share_.user_share()->directory.get(); |
| 246 } | 289 } |
| 247 | 290 |
| 248 base::MessageLoop loop_; | 291 base::MessageLoop loop_; |
| 249 TestUserShare test_user_share_; | 292 TestUserShare test_user_share_; |
| 250 CancelationSignal cancelation_signal_; | 293 CancelationSignal cancelation_signal_; |
| 251 std::unique_ptr<MockConnectionManager> connection_; | 294 std::unique_ptr<MockConnectionManager> connection_; |
| 252 std::unique_ptr<ModelTypeRegistry> model_type_registry_; | 295 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()); | 841 EXPECT_EQ(1, retry_counter.times_called()); |
| 799 EXPECT_TRUE(scheduler()->IsCurrentlyThrottled()); | 842 EXPECT_TRUE(scheduler()->IsCurrentlyThrottled()); |
| 800 | 843 |
| 801 RunLoop(); | 844 RunLoop(); |
| 802 EXPECT_FALSE(scheduler()->IsCurrentlyThrottled()); | 845 EXPECT_FALSE(scheduler()->IsCurrentlyThrottled()); |
| 803 | 846 |
| 804 StopSyncScheduler(); | 847 StopSyncScheduler(); |
| 805 } | 848 } |
| 806 | 849 |
| 807 TEST_F(SyncSchedulerImplTest, TypeThrottlingBlocksNudge) { | 850 TEST_F(SyncSchedulerImplTest, TypeThrottlingBlocksNudge) { |
| 808 UseMockDelayProvider(); | |
| 809 EXPECT_CALL(*delay(), GetDelay(_)).WillRepeatedly(Return(default_delay())); | |
| 810 | |
| 811 TimeDelta poll(TimeDelta::FromDays(1)); | 851 TimeDelta poll(TimeDelta::FromDays(1)); |
| 812 TimeDelta throttle1(TimeDelta::FromSeconds(60)); | 852 TimeDelta throttle1(TimeDelta::FromSeconds(60)); |
| 813 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 853 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
| 814 | 854 |
| 815 const ModelTypeSet types(THEMES); | 855 const ModelTypeSet types(THEMES); |
| 816 | 856 |
| 817 ::testing::InSequence seq; | 857 ::testing::InSequence seq; |
| 818 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 858 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 819 .WillOnce( | 859 .WillOnce( |
| 820 DoAll(WithArg<2>(test_util::SimulateTypesThrottled(types, throttle1)), | 860 DoAll(WithArg<2>(test_util::SimulateTypesThrottled(types, throttle1)), |
| 821 Return(false))) | 861 Return(true))) |
| 822 .RetiresOnSaturation(); | 862 .RetiresOnSaturation(); |
| 823 | 863 |
| 824 StartSyncScheduler(base::Time()); | 864 StartSyncScheduler(base::Time()); |
| 825 scheduler()->ScheduleLocalNudge(types, FROM_HERE); | 865 scheduler()->ScheduleLocalNudge(types, FROM_HERE); |
| 826 PumpLoop(); // To get PerformDelayedNudge called. | 866 PumpLoop(); // To get PerformDelayedNudge called. |
| 827 PumpLoop(); // To get TrySyncCycleJob called | 867 PumpLoop(); // To get TrySyncCycleJob called |
| 828 EXPECT_TRUE(GetThrottledTypes().HasAll(types)); | 868 EXPECT_TRUE(GetThrottledTypes().HasAll(types)); |
| 869 EXPECT_FALSE(scheduler()->IsBackingOff()); |
| 870 EXPECT_FALSE(scheduler()->IsCurrentlyThrottled()); |
| 829 | 871 |
| 830 // This won't cause a sync cycle because the types are throttled. | 872 // This won't cause a sync cycle because the types are throttled. |
| 831 scheduler()->ScheduleLocalNudge(types, FROM_HERE); | 873 scheduler()->ScheduleLocalNudge(types, FROM_HERE); |
| 832 PumpLoop(); | 874 PumpLoop(); |
| 833 | 875 |
| 834 StopSyncScheduler(); | 876 StopSyncScheduler(); |
| 835 } | 877 } |
| 836 | 878 |
| 879 TEST_F(SyncSchedulerImplTest, TypeBackingOffBlocksNudge) { |
| 880 UseMockDelayProvider(); |
| 881 EXPECT_CALL(*delay(), GetDelay(_)).WillRepeatedly(Return(long_delay())); |
| 882 |
| 883 TimeDelta poll(TimeDelta::FromDays(1)); |
| 884 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
| 885 |
| 886 const ModelTypeSet types(THEMES); |
| 887 |
| 888 ::testing::InSequence seq; |
| 889 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 890 .WillOnce(DoAll(WithArg<2>(test_util::SimulatePartialFailure(types)), |
| 891 Return(true))) |
| 892 .RetiresOnSaturation(); |
| 893 |
| 894 StartSyncScheduler(base::Time()); |
| 895 scheduler()->ScheduleLocalNudge(types, FROM_HERE); |
| 896 PumpLoop(); // To get PerformDelayedNudge called. |
| 897 PumpLoop(); // To get TrySyncCycleJob called |
| 898 EXPECT_TRUE(GetBackedOffTypes().HasAll(types)); |
| 899 EXPECT_FALSE(scheduler()->IsBackingOff()); |
| 900 EXPECT_FALSE(scheduler()->IsCurrentlyThrottled()); |
| 901 |
| 902 // This won't cause a sync cycle because the types are backed off. |
| 903 scheduler()->ScheduleLocalNudge(types, FROM_HERE); |
| 904 PumpLoop(); |
| 905 |
| 906 StopSyncScheduler(); |
| 907 } |
| 908 |
| 909 TEST_F(SyncSchedulerImplTest, TypeBackingOffWillExpire) { |
| 910 UseMockDelayProvider(); |
| 911 EXPECT_CALL(*delay(), GetDelay(_)).WillRepeatedly(Return(default_delay())); |
| 912 |
| 913 TimeDelta poll(TimeDelta::FromDays(1)); |
| 914 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
| 915 |
| 916 const ModelTypeSet types(THEMES); |
| 917 |
| 918 ::testing::InSequence seq; |
| 919 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 920 .WillOnce(DoAll(WithArg<2>(test_util::SimulatePartialFailure(types)), |
| 921 Return(true))) |
| 922 .RetiresOnSaturation(); |
| 923 |
| 924 StartSyncScheduler(base::Time()); |
| 925 scheduler()->ScheduleLocalNudge(types, FROM_HERE); |
| 926 PumpLoop(); // To get PerformDelayedNudge called. |
| 927 PumpLoop(); // To get TrySyncCycleJob called |
| 928 EXPECT_TRUE(GetBackedOffTypes().HasAll(types)); |
| 929 EXPECT_FALSE(scheduler()->IsBackingOff()); |
| 930 EXPECT_FALSE(scheduler()->IsCurrentlyThrottled()); |
| 931 |
| 932 SyncShareTimes times; |
| 933 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 934 .WillRepeatedly(DoAll(Invoke(test_util::SimulateNormalSuccess), |
| 935 RecordSyncShare(×, true))); |
| 936 PumpLoop(); // To get PerformDelayedNudge called. |
| 937 PumpLoop(); // To get TrySyncCycleJob called |
| 938 EXPECT_FALSE(IsAnyTypeBlocked()); |
| 939 EXPECT_FALSE(scheduler()->IsBackingOff()); |
| 940 EXPECT_FALSE(scheduler()->IsCurrentlyThrottled()); |
| 941 |
| 942 StopSyncScheduler(); |
| 943 } |
| 944 |
| 945 TEST_F(SyncSchedulerImplTest, TypeBackingOffAndThrottling) { |
| 946 UseMockDelayProvider(); |
| 947 EXPECT_CALL(*delay(), GetDelay(_)).WillRepeatedly(Return(long_delay())); |
| 948 |
| 949 TimeDelta poll(TimeDelta::FromDays(1)); |
| 950 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
| 951 |
| 952 const ModelTypeSet types(THEMES); |
| 953 |
| 954 ::testing::InSequence seq; |
| 955 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 956 .WillOnce(DoAll(WithArg<2>(test_util::SimulatePartialFailure(types)), |
| 957 Return(true))) |
| 958 .RetiresOnSaturation(); |
| 959 |
| 960 StartSyncScheduler(base::Time()); |
| 961 scheduler()->ScheduleLocalNudge(types, FROM_HERE); |
| 962 PumpLoop(); // To get PerformDelayedNudge called. |
| 963 PumpLoop(); // To get TrySyncCycleJob called |
| 964 EXPECT_TRUE(GetBackedOffTypes().HasAll(types)); |
| 965 EXPECT_FALSE(scheduler()->IsBackingOff()); |
| 966 EXPECT_FALSE(scheduler()->IsCurrentlyThrottled()); |
| 967 |
| 968 TimeDelta throttle1(TimeDelta::FromMilliseconds(150)); |
| 969 |
| 970 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 971 .WillOnce(DoAll(WithArg<2>(test_util::SimulateThrottled(throttle1)), |
| 972 Return(false))) |
| 973 .RetiresOnSaturation(); |
| 974 |
| 975 // Sync still can throttle. |
| 976 const ModelTypeSet unbacked_off_types(TYPED_URLS); |
| 977 scheduler()->ScheduleLocalNudge(unbacked_off_types, FROM_HERE); |
| 978 PumpLoop(); // TO get TypesUnblock called. |
| 979 PumpLoop(); // To get TrySyncCycleJob called. |
| 980 |
| 981 EXPECT_TRUE(GetBackedOffTypes().HasAll(types)); |
| 982 EXPECT_FALSE(scheduler()->IsBackingOff()); |
| 983 EXPECT_TRUE(scheduler()->IsCurrentlyThrottled()); |
| 984 |
| 985 StopSyncScheduler(); |
| 986 } |
| 987 |
| 988 TEST_F(SyncSchedulerImplTest, TypeThrottlingBackingOffBlocksNudge) { |
| 989 UseMockDelayProvider(); |
| 990 EXPECT_CALL(*delay(), GetDelay(_)).WillRepeatedly(Return(long_delay())); |
| 991 |
| 992 TimeDelta poll(TimeDelta::FromDays(1)); |
| 993 TimeDelta throttle(TimeDelta::FromSeconds(60)); |
| 994 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
| 995 |
| 996 const ModelTypeSet throttled_types(THEMES); |
| 997 |
| 998 ::testing::InSequence seq; |
| 999 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 1000 .WillOnce(DoAll(WithArg<2>(test_util::SimulateTypesThrottled( |
| 1001 throttled_types, throttle)), |
| 1002 Return(true))) |
| 1003 .RetiresOnSaturation(); |
| 1004 |
| 1005 StartSyncScheduler(base::Time()); |
| 1006 scheduler()->ScheduleLocalNudge(throttled_types, FROM_HERE); |
| 1007 PumpLoop(); // To get PerformDelayedNudge called. |
| 1008 PumpLoop(); // To get TrySyncCycleJob called |
| 1009 |
| 1010 const ModelTypeSet backed_off_types(TYPED_URLS); |
| 1011 |
| 1012 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 1013 .WillOnce( |
| 1014 DoAll(WithArg<2>(test_util::SimulatePartialFailure(backed_off_types)), |
| 1015 Return(true))) |
| 1016 .RetiresOnSaturation(); |
| 1017 |
| 1018 scheduler()->ScheduleLocalNudge(backed_off_types, FROM_HERE); |
| 1019 |
| 1020 PumpLoop(); // To get PerformDelayedNudge called. |
| 1021 PumpLoop(); // To get TrySyncCycleJob called |
| 1022 |
| 1023 EXPECT_TRUE(GetThrottledTypes().HasAll(throttled_types)); |
| 1024 EXPECT_TRUE(GetBackedOffTypes().HasAll(backed_off_types)); |
| 1025 EXPECT_FALSE(scheduler()->IsBackingOff()); |
| 1026 EXPECT_FALSE(scheduler()->IsCurrentlyThrottled()); |
| 1027 |
| 1028 // This won't cause a sync cycle because the types are throttled or backed |
| 1029 // off. |
| 1030 scheduler()->ScheduleLocalNudge(Union(throttled_types, backed_off_types), |
| 1031 FROM_HERE); |
| 1032 PumpLoop(); |
| 1033 |
| 1034 StopSyncScheduler(); |
| 1035 } |
| 1036 |
| 837 TEST_F(SyncSchedulerImplTest, TypeThrottlingDoesBlockOtherSources) { | 1037 TEST_F(SyncSchedulerImplTest, TypeThrottlingDoesBlockOtherSources) { |
| 838 UseMockDelayProvider(); | 1038 UseMockDelayProvider(); |
| 839 EXPECT_CALL(*delay(), GetDelay(_)).WillRepeatedly(Return(default_delay())); | 1039 EXPECT_CALL(*delay(), GetDelay(_)).WillRepeatedly(Return(default_delay())); |
| 840 | 1040 |
| 841 SyncShareTimes times; | 1041 SyncShareTimes times; |
| 842 TimeDelta poll(TimeDelta::FromDays(1)); | 1042 TimeDelta poll(TimeDelta::FromDays(1)); |
| 843 TimeDelta throttle1(TimeDelta::FromSeconds(60)); | 1043 TimeDelta throttle1(TimeDelta::FromSeconds(60)); |
| 844 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 1044 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
| 845 | 1045 |
| 846 const ModelTypeSet throttled_types(THEMES); | 1046 const ModelTypeSet throttled_types(THEMES); |
| 847 const ModelTypeSet unthrottled_types(PREFERENCES); | 1047 const ModelTypeSet unthrottled_types(PREFERENCES); |
| 848 | 1048 |
| 849 ::testing::InSequence seq; | 1049 ::testing::InSequence seq; |
| 850 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 1050 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 851 .WillOnce(DoAll(WithArg<2>(test_util::SimulateTypesThrottled( | 1051 .WillOnce(DoAll(WithArg<2>(test_util::SimulateTypesThrottled( |
| 852 throttled_types, throttle1)), | 1052 throttled_types, throttle1)), |
| 853 Return(false))) | 1053 Return(true))) |
| 854 .RetiresOnSaturation(); | 1054 .RetiresOnSaturation(); |
| 855 | 1055 |
| 856 StartSyncScheduler(base::Time()); | 1056 StartSyncScheduler(base::Time()); |
| 857 scheduler()->ScheduleLocalNudge(throttled_types, FROM_HERE); | 1057 scheduler()->ScheduleLocalNudge(throttled_types, FROM_HERE); |
| 858 PumpLoop(); // To get PerformDelayedNudge called. | 1058 PumpLoop(); // To get PerformDelayedNudge called. |
| 859 PumpLoop(); // To get TrySyncCycleJob called | 1059 PumpLoop(); // To get TrySyncCycleJob called |
| 860 EXPECT_TRUE(GetThrottledTypes().HasAll(throttled_types)); | 1060 EXPECT_TRUE(GetThrottledTypes().HasAll(throttled_types)); |
| 1061 EXPECT_FALSE(scheduler()->IsBackingOff()); |
| 1062 EXPECT_FALSE(scheduler()->IsCurrentlyThrottled()); |
| 861 | 1063 |
| 862 // Ignore invalidations for throttled types. | 1064 // Ignore invalidations for throttled types. |
| 863 scheduler()->ScheduleInvalidationNudge(THEMES, BuildInvalidation(10, "test"), | 1065 scheduler()->ScheduleInvalidationNudge(THEMES, BuildInvalidation(10, "test"), |
| 864 FROM_HERE); | 1066 FROM_HERE); |
| 865 PumpLoop(); | 1067 PumpLoop(); |
| 866 | 1068 |
| 867 // Ignore refresh requests for throttled types. | 1069 // Ignore refresh requests for throttled types. |
| 868 scheduler()->ScheduleLocalRefreshRequest(throttled_types, FROM_HERE); | 1070 scheduler()->ScheduleLocalRefreshRequest(throttled_types, FROM_HERE); |
| 869 PumpLoop(); | 1071 PumpLoop(); |
| 870 | 1072 |
| 871 Mock::VerifyAndClearExpectations(syncer()); | 1073 Mock::VerifyAndClearExpectations(syncer()); |
| 872 | 1074 |
| 873 // Local nudges for non-throttled types will trigger a sync. | 1075 // Local nudges for non-throttled types will trigger a sync. |
| 874 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 1076 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 875 .WillRepeatedly(DoAll(Invoke(test_util::SimulateNormalSuccess), | 1077 .WillRepeatedly(DoAll(Invoke(test_util::SimulateNormalSuccess), |
| 876 RecordSyncShare(×, true))); | 1078 RecordSyncShare(×, true))); |
| 877 scheduler()->ScheduleLocalNudge(unthrottled_types, FROM_HERE); | 1079 scheduler()->ScheduleLocalNudge(unthrottled_types, FROM_HERE); |
| 878 RunLoop(); | 1080 RunLoop(); |
| 879 Mock::VerifyAndClearExpectations(syncer()); | 1081 Mock::VerifyAndClearExpectations(syncer()); |
| 880 | 1082 |
| 881 StopSyncScheduler(); | 1083 StopSyncScheduler(); |
| 882 } | 1084 } |
| 883 | 1085 |
| 1086 TEST_F(SyncSchedulerImplTest, TypeBackingOffDoesBlockOtherSources) { |
| 1087 UseMockDelayProvider(); |
| 1088 EXPECT_CALL(*delay(), GetDelay(_)).WillRepeatedly(Return(long_delay())); |
| 1089 |
| 1090 SyncShareTimes times; |
| 1091 TimeDelta poll(TimeDelta::FromDays(1)); |
| 1092 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
| 1093 |
| 1094 const ModelTypeSet backed_off_types(THEMES); |
| 1095 const ModelTypeSet unbacked_off_types(PREFERENCES); |
| 1096 |
| 1097 ::testing::InSequence seq; |
| 1098 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 1099 .WillOnce( |
| 1100 DoAll(WithArg<2>(test_util::SimulatePartialFailure(backed_off_types)), |
| 1101 Return(true))) |
| 1102 .RetiresOnSaturation(); |
| 1103 |
| 1104 StartSyncScheduler(base::Time()); |
| 1105 scheduler()->ScheduleLocalNudge(backed_off_types, FROM_HERE); |
| 1106 PumpLoop(); // To get PerformDelayedNudge called. |
| 1107 PumpLoop(); // To get TrySyncCycleJob called |
| 1108 EXPECT_TRUE(GetBackedOffTypes().HasAll(backed_off_types)); |
| 1109 EXPECT_FALSE(scheduler()->IsBackingOff()); |
| 1110 EXPECT_FALSE(scheduler()->IsCurrentlyThrottled()); |
| 1111 |
| 1112 // Ignore invalidations for backed off types. |
| 1113 scheduler()->ScheduleInvalidationNudge(THEMES, BuildInvalidation(10, "test"), |
| 1114 FROM_HERE); |
| 1115 PumpLoop(); |
| 1116 |
| 1117 // Ignore refresh requests for backed off types. |
| 1118 scheduler()->ScheduleLocalRefreshRequest(backed_off_types, FROM_HERE); |
| 1119 PumpLoop(); |
| 1120 |
| 1121 Mock::VerifyAndClearExpectations(syncer()); |
| 1122 |
| 1123 // Local nudges for non-backed off types will trigger a sync. |
| 1124 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 1125 .WillRepeatedly(DoAll(Invoke(test_util::SimulateNormalSuccess), |
| 1126 RecordSyncShare(×, true))); |
| 1127 scheduler()->ScheduleLocalNudge(unbacked_off_types, FROM_HERE); |
| 1128 RunLoop(); |
| 1129 Mock::VerifyAndClearExpectations(syncer()); |
| 1130 |
| 1131 StopSyncScheduler(); |
| 1132 } |
| 1133 |
| 884 // Test nudges / polls don't run in config mode and config tasks do. | 1134 // Test nudges / polls don't run in config mode and config tasks do. |
| 885 TEST_F(SyncSchedulerImplTest, ConfigurationMode) { | 1135 TEST_F(SyncSchedulerImplTest, ConfigurationMode) { |
| 886 TimeDelta poll(TimeDelta::FromMilliseconds(15)); | 1136 TimeDelta poll(TimeDelta::FromMilliseconds(15)); |
| 887 SyncShareTimes times; | 1137 SyncShareTimes times; |
| 888 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 1138 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
| 889 | 1139 |
| 890 StartSyncConfiguration(); | 1140 StartSyncConfiguration(); |
| 891 | 1141 |
| 892 const ModelTypeSet nudge_types(TYPED_URLS); | 1142 const ModelTypeSet nudge_types(TYPED_URLS); |
| 893 scheduler()->ScheduleLocalNudge(nudge_types, FROM_HERE); | 1143 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()); | 1682 ASSERT_EQ(0, success_counter.times_called()); |
| 1433 ASSERT_TRUE(scheduler()->IsBackingOff()); | 1683 ASSERT_TRUE(scheduler()->IsBackingOff()); |
| 1434 | 1684 |
| 1435 // Now succeed. | 1685 // Now succeed. |
| 1436 connection()->SetServerReachable(); | 1686 connection()->SetServerReachable(); |
| 1437 PumpLoopFor(2 * delta); | 1687 PumpLoopFor(2 * delta); |
| 1438 ASSERT_EQ(1, success_counter.times_called()); | 1688 ASSERT_EQ(1, success_counter.times_called()); |
| 1439 ASSERT_FALSE(scheduler()->IsBackingOff()); | 1689 ASSERT_FALSE(scheduler()->IsBackingOff()); |
| 1440 } | 1690 } |
| 1441 | 1691 |
| 1692 TEST_F(SyncSchedulerImplTest, PartialFailureWillExponentialBackoff) { |
| 1693 TimeDelta poll(TimeDelta::FromDays(1)); |
| 1694 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
| 1695 |
| 1696 const ModelTypeSet types(THEMES); |
| 1697 |
| 1698 ::testing::InSequence seq; |
| 1699 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 1700 .WillRepeatedly(DoAll( |
| 1701 WithArg<2>(test_util::SimulatePartialFailure(types)), Return(true))) |
| 1702 .RetiresOnSaturation(); |
| 1703 |
| 1704 StartSyncScheduler(base::Time()); |
| 1705 scheduler()->ScheduleLocalNudge(types, FROM_HERE); |
| 1706 PumpLoop(); // To get PerformDelayedNudge called. |
| 1707 PumpLoop(); // To get TrySyncCycleJob called |
| 1708 EXPECT_TRUE(GetBackedOffTypes().HasAll(types)); |
| 1709 EXPECT_FALSE(scheduler()->IsBackingOff()); |
| 1710 EXPECT_FALSE(scheduler()->IsCurrentlyThrottled()); |
| 1711 base::TimeDelta first_blocking_time = GetTypeBlockingTime(THEMES); |
| 1712 |
| 1713 SetTypeBlockingMode(THEMES, WaitInterval::EXPONENTIAL_BACKOFF_RETRYING); |
| 1714 // This won't cause a sync cycle because the types are backed off. |
| 1715 scheduler()->ScheduleLocalNudge(types, FROM_HERE); |
| 1716 PumpLoop(); |
| 1717 PumpLoop(); |
| 1718 base::TimeDelta second_blocking_time = GetTypeBlockingTime(THEMES); |
| 1719 |
| 1720 // The Exponential backoff should be between previous backoff 1.5 and 2.5 |
| 1721 // times. |
| 1722 EXPECT_LE(first_blocking_time * 1.5, second_blocking_time); |
| 1723 EXPECT_GE(first_blocking_time * 2.5, second_blocking_time); |
| 1724 |
| 1725 StopSyncScheduler(); |
| 1726 } |
| 1727 |
| 1442 } // namespace syncer | 1728 } // namespace syncer |
| OLD | NEW |