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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/callback.h" | 6 #include "base/callback.h" |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/test/test_timeouts.h" | 10 #include "base/test/test_timeouts.h" |
(...skipping 844 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
855 // Test that no polls or extraneous nudges occur when in backoff. | 855 // Test that no polls or extraneous nudges occur when in backoff. |
856 TEST_F(SyncSchedulerTest, BackoffDropsJobs) { | 856 TEST_F(SyncSchedulerTest, BackoffDropsJobs) { |
857 SyncShareRecords r; | 857 SyncShareRecords r; |
858 TimeDelta poll(TimeDelta::FromMilliseconds(5)); | 858 TimeDelta poll(TimeDelta::FromMilliseconds(5)); |
859 const ModelTypeSet types(syncable::BOOKMARKS); | 859 const ModelTypeSet types(syncable::BOOKMARKS); |
860 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 860 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
861 UseMockDelayProvider(); | 861 UseMockDelayProvider(); |
862 | 862 |
863 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(1) | 863 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(1) |
864 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), | 864 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), |
865 RecordSyncShareMultiple(&r, 1U))); | 865 RecordSyncShareMultiple(&r, 1U))); |
866 EXPECT_CALL(*delay(), GetDelay(_)). | 866 EXPECT_CALL(*delay(), GetDelay(_)). |
867 WillRepeatedly(Return(TimeDelta::FromDays(1))); | 867 WillRepeatedly(Return(TimeDelta::FromDays(1))); |
868 | 868 |
869 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 869 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
870 RunLoop(); | 870 RunLoop(); |
871 | 871 |
872 // This nudge should fail and put us into backoff. Thanks to our mock | 872 // This nudge should fail and put us into backoff. Thanks to our mock |
873 // GetDelay() setup above, this will be a long backoff. | 873 // GetDelay() setup above, this will be a long backoff. |
874 scheduler()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE); | 874 scheduler()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE); |
875 RunLoop(); | 875 RunLoop(); |
876 | 876 |
877 Mock::VerifyAndClearExpectations(syncer()); | 877 Mock::VerifyAndClearExpectations(syncer()); |
878 ASSERT_EQ(1U, r.snapshots.size()); | 878 ASSERT_EQ(1U, r.snapshots.size()); |
879 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, | 879 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, |
880 r.snapshots[0].source().updates_source); | 880 r.snapshots[0].source().updates_source); |
881 | 881 |
882 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(1) | 882 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(1) |
883 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), | 883 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), |
884 RecordSyncShare(&r))); | 884 RecordSyncShare(&r))); |
885 | 885 |
886 // We schedule a nudge with enough delay (10X poll interval) that at least | 886 // We schedule a nudge with enough delay (10X poll interval) that at least |
887 // one or two polls would have taken place. The nudge should succeed. | 887 // one or two polls would have taken place. The nudge should succeed. |
888 scheduler()->ScheduleNudge(poll * 10, NUDGE_SOURCE_LOCAL, types, FROM_HERE); | 888 scheduler()->ScheduleNudge(poll * 10, NUDGE_SOURCE_LOCAL, types, FROM_HERE); |
889 RunLoop(); | 889 RunLoop(); |
890 | 890 |
891 Mock::VerifyAndClearExpectations(syncer()); | 891 Mock::VerifyAndClearExpectations(syncer()); |
892 Mock::VerifyAndClearExpectations(delay()); | 892 Mock::VerifyAndClearExpectations(delay()); |
893 ASSERT_EQ(2U, r.snapshots.size()); | 893 ASSERT_EQ(2U, r.snapshots.size()); |
894 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, | 894 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, |
895 r.snapshots[1].source().updates_source); | 895 r.snapshots[1].source().updates_source); |
896 | 896 |
897 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(0); | 897 // Cleanup is not affected by backoff, but it should not relieve it either. |
| 898 EXPECT_CALL(*syncer(), |
| 899 SyncShare(_, CLEANUP_DISABLED_TYPES, CLEANUP_DISABLED_TYPES)) |
| 900 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)); |
898 EXPECT_CALL(*delay(), GetDelay(_)).Times(0); | 901 EXPECT_CALL(*delay(), GetDelay(_)).Times(0); |
899 | 902 |
900 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 903 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
901 RunLoop(); | 904 RunLoop(); |
902 | 905 |
| 906 scheduler()->ScheduleCleanupDisabledTypes(); |
903 scheduler()->ScheduleConfig( | 907 scheduler()->ScheduleConfig( |
904 types, GetUpdatesCallerInfo::RECONFIGURATION); | 908 types, GetUpdatesCallerInfo::RECONFIGURATION); |
905 PumpLoop(); | 909 PumpLoop(); |
906 | 910 |
907 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 911 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
908 RunLoop(); | 912 RunLoop(); |
909 | 913 |
910 scheduler()->ScheduleNudge( | 914 scheduler()->ScheduleNudge( |
911 zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE); | 915 zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE); |
912 scheduler()->ScheduleNudge( | 916 scheduler()->ScheduleNudge( |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1046 TimeDelta::FromSeconds(kMaxBackoffSeconds))); | 1050 TimeDelta::FromSeconds(kMaxBackoffSeconds))); |
1047 EXPECT_EQ(TimeDelta::FromSeconds(kMaxBackoffSeconds), | 1051 EXPECT_EQ(TimeDelta::FromSeconds(kMaxBackoffSeconds), |
1048 SyncScheduler::GetRecommendedDelay( | 1052 SyncScheduler::GetRecommendedDelay( |
1049 TimeDelta::FromSeconds(kMaxBackoffSeconds + 1))); | 1053 TimeDelta::FromSeconds(kMaxBackoffSeconds + 1))); |
1050 } | 1054 } |
1051 | 1055 |
1052 // Test that appropriate syncer steps are requested for each job type. | 1056 // Test that appropriate syncer steps are requested for each job type. |
1053 TEST_F(SyncSchedulerTest, SyncerSteps) { | 1057 TEST_F(SyncSchedulerTest, SyncerSteps) { |
1054 // Nudges. | 1058 // Nudges. |
1055 EXPECT_CALL(*syncer(), SyncShare(_, SYNCER_BEGIN, SYNCER_END)) | 1059 EXPECT_CALL(*syncer(), SyncShare(_, SYNCER_BEGIN, SYNCER_END)) |
1056 .Times(1); | 1060 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)); |
1057 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 1061 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
1058 RunLoop(); | 1062 RunLoop(); |
1059 | 1063 |
1060 scheduler()->ScheduleNudge( | 1064 scheduler()->ScheduleNudge( |
1061 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(), FROM_HERE); | 1065 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(), FROM_HERE); |
1062 PumpLoop(); | 1066 PumpLoop(); |
1063 // Pump again to run job. | 1067 // Pump again to run job. |
1064 PumpLoop(); | 1068 PumpLoop(); |
1065 | 1069 |
1066 StopSyncScheduler(); | 1070 StopSyncScheduler(); |
1067 Mock::VerifyAndClearExpectations(syncer()); | 1071 Mock::VerifyAndClearExpectations(syncer()); |
1068 | 1072 |
1069 // ClearUserData. | 1073 // ClearUserData. |
1070 EXPECT_CALL(*syncer(), SyncShare(_, CLEAR_PRIVATE_DATA, CLEAR_PRIVATE_DATA)) | 1074 EXPECT_CALL(*syncer(), SyncShare(_, CLEAR_PRIVATE_DATA, CLEAR_PRIVATE_DATA)) |
1071 .Times(1); | 1075 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)); |
1072 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 1076 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
1073 RunLoop(); | 1077 RunLoop(); |
1074 | 1078 |
1075 scheduler()->ScheduleClearUserData(); | 1079 scheduler()->ScheduleClearUserData(); |
1076 PumpLoop(); | 1080 PumpLoop(); |
1077 PumpLoop(); | 1081 PumpLoop(); |
1078 | 1082 |
1079 StopSyncScheduler(); | 1083 StopSyncScheduler(); |
1080 Mock::VerifyAndClearExpectations(syncer()); | 1084 Mock::VerifyAndClearExpectations(syncer()); |
1081 | 1085 |
1082 // Configuration. | 1086 // Configuration. |
1083 EXPECT_CALL(*syncer(), SyncShare(_, DOWNLOAD_UPDATES, APPLY_UPDATES)); | 1087 EXPECT_CALL(*syncer(), SyncShare(_, DOWNLOAD_UPDATES, APPLY_UPDATES)) |
| 1088 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)); |
1084 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 1089 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
1085 RunLoop(); | 1090 RunLoop(); |
1086 | 1091 |
1087 scheduler()->ScheduleConfig( | 1092 scheduler()->ScheduleConfig( |
1088 ModelTypeSet(), GetUpdatesCallerInfo::RECONFIGURATION); | 1093 ModelTypeSet(), GetUpdatesCallerInfo::RECONFIGURATION); |
1089 PumpLoop(); | 1094 PumpLoop(); |
1090 PumpLoop(); | 1095 PumpLoop(); |
1091 | 1096 |
1092 StopSyncScheduler(); | 1097 StopSyncScheduler(); |
1093 Mock::VerifyAndClearExpectations(syncer()); | 1098 Mock::VerifyAndClearExpectations(syncer()); |
1094 | 1099 |
1095 // Cleanup disabled types. | 1100 // Cleanup disabled types. |
1096 EXPECT_CALL(*syncer(), | 1101 EXPECT_CALL(*syncer(), |
1097 SyncShare(_, CLEANUP_DISABLED_TYPES, CLEANUP_DISABLED_TYPES)); | 1102 SyncShare(_, CLEANUP_DISABLED_TYPES, CLEANUP_DISABLED_TYPES)) |
| 1103 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)); |
1098 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 1104 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
1099 RunLoop(); | 1105 RunLoop(); |
1100 | 1106 |
1101 scheduler()->ScheduleCleanupDisabledTypes(); | 1107 scheduler()->ScheduleCleanupDisabledTypes(); |
1102 // Only need to pump once, as ScheduleCleanupDisabledTypes() | 1108 // Only need to pump once, as ScheduleCleanupDisabledTypes() |
1103 // schedules the job directly. | 1109 // schedules the job directly. |
1104 PumpLoop(); | 1110 PumpLoop(); |
1105 | 1111 |
1106 StopSyncScheduler(); | 1112 StopSyncScheduler(); |
1107 Mock::VerifyAndClearExpectations(syncer()); | 1113 Mock::VerifyAndClearExpectations(syncer()); |
1108 | 1114 |
1109 // Poll. | 1115 // Poll. |
1110 EXPECT_CALL(*syncer(), SyncShare(_, SYNCER_BEGIN, SYNCER_END)) | 1116 EXPECT_CALL(*syncer(), SyncShare(_, SYNCER_BEGIN, SYNCER_END)) |
1111 .Times(AtLeast(1)) | 1117 .Times(AtLeast(1)) |
1112 .WillRepeatedly(QuitLoopNowAction()); | 1118 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 1119 QuitLoopNowAction())); |
1113 const TimeDelta poll(TimeDelta::FromMilliseconds(10)); | 1120 const TimeDelta poll(TimeDelta::FromMilliseconds(10)); |
1114 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 1121 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
1115 | 1122 |
1116 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 1123 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
1117 RunLoop(); | 1124 RunLoop(); |
1118 | 1125 |
1119 // Run again to wait for polling. | 1126 // Run again to wait for polling. |
1120 RunLoop(); | 1127 RunLoop(); |
1121 | 1128 |
1122 StopSyncScheduler(); | 1129 StopSyncScheduler(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1165 PumpLoop(); | 1172 PumpLoop(); |
1166 // Pump again to run job. | 1173 // Pump again to run job. |
1167 PumpLoop(); | 1174 PumpLoop(); |
1168 | 1175 |
1169 StopSyncScheduler(); | 1176 StopSyncScheduler(); |
1170 | 1177 |
1171 EXPECT_TRUE(expected == context()->previous_session_routing_info()); | 1178 EXPECT_TRUE(expected == context()->previous_session_routing_info()); |
1172 } | 1179 } |
1173 | 1180 |
1174 } // namespace browser_sync | 1181 } // namespace browser_sync |
OLD | NEW |