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 715 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
726 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 726 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
727 RunLoop(); | 727 RunLoop(); |
728 | 728 |
729 scheduler()->ScheduleNudge( | 729 scheduler()->ScheduleNudge( |
730 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(), FROM_HERE); | 730 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(), FROM_HERE); |
731 RunLoop(); | 731 RunLoop(); |
732 // If more nudges are scheduled, they'll be waited on by TearDown, and would | 732 // If more nudges are scheduled, they'll be waited on by TearDown, and would |
733 // cause our expectation to break. | 733 // cause our expectation to break. |
734 } | 734 } |
735 | 735 |
| 736 // Test that continuations can go into backoff. |
| 737 TEST_F(SyncSchedulerTest, HasMoreToSyncThenFails) { |
| 738 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 739 .WillOnce(Invoke(sessions::test_util::SimulateHasMoreToSync)) |
| 740 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), |
| 741 QuitLoopNowAction())); |
| 742 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
| 743 RunLoop(); |
| 744 |
| 745 scheduler()->ScheduleNudge( |
| 746 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(), FROM_HERE); |
| 747 |
| 748 // We should detect the failure on the second sync share, and go into backoff. |
| 749 EXPECT_TRUE(RunAndGetBackoff()); |
| 750 } |
| 751 |
736 // Test that no syncing occurs when throttled. | 752 // Test that no syncing occurs when throttled. |
737 TEST_F(SyncSchedulerTest, ThrottlingDoesThrottle) { | 753 TEST_F(SyncSchedulerTest, ThrottlingDoesThrottle) { |
738 const ModelTypeSet types(syncable::BOOKMARKS); | 754 const ModelTypeSet types(syncable::BOOKMARKS); |
739 TimeDelta poll(TimeDelta::FromMilliseconds(5)); | 755 TimeDelta poll(TimeDelta::FromMilliseconds(5)); |
740 TimeDelta throttle(TimeDelta::FromMinutes(10)); | 756 TimeDelta throttle(TimeDelta::FromMinutes(10)); |
741 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 757 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
742 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 758 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
743 .WillOnce(WithArg<0>(sessions::test_util::SimulateThrottled(throttle))) | 759 .WillOnce(WithArg<0>(sessions::test_util::SimulateThrottled(throttle))) |
744 .WillRepeatedly(AddFailureAndQuitLoopNow()); | 760 .WillRepeatedly(AddFailureAndQuitLoopNow()); |
745 | 761 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
855 // Test that no polls or extraneous nudges occur when in backoff. | 871 // Test that no polls or extraneous nudges occur when in backoff. |
856 TEST_F(SyncSchedulerTest, BackoffDropsJobs) { | 872 TEST_F(SyncSchedulerTest, BackoffDropsJobs) { |
857 SyncShareRecords r; | 873 SyncShareRecords r; |
858 TimeDelta poll(TimeDelta::FromMilliseconds(5)); | 874 TimeDelta poll(TimeDelta::FromMilliseconds(5)); |
859 const ModelTypeSet types(syncable::BOOKMARKS); | 875 const ModelTypeSet types(syncable::BOOKMARKS); |
860 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 876 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
861 UseMockDelayProvider(); | 877 UseMockDelayProvider(); |
862 | 878 |
863 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(1) | 879 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(1) |
864 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), | 880 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), |
865 RecordSyncShareMultiple(&r, 1U))); | 881 RecordSyncShareMultiple(&r, 1U))); |
866 EXPECT_CALL(*delay(), GetDelay(_)). | 882 EXPECT_CALL(*delay(), GetDelay(_)). |
867 WillRepeatedly(Return(TimeDelta::FromDays(1))); | 883 WillRepeatedly(Return(TimeDelta::FromDays(1))); |
868 | 884 |
869 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 885 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
870 RunLoop(); | 886 RunLoop(); |
871 | 887 |
872 // This nudge should fail and put us into backoff. Thanks to our mock | 888 // This nudge should fail and put us into backoff. Thanks to our mock |
873 // GetDelay() setup above, this will be a long backoff. | 889 // GetDelay() setup above, this will be a long backoff. |
874 scheduler()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE); | 890 scheduler()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE); |
875 RunLoop(); | 891 RunLoop(); |
876 | 892 |
877 Mock::VerifyAndClearExpectations(syncer()); | 893 Mock::VerifyAndClearExpectations(syncer()); |
878 ASSERT_EQ(1U, r.snapshots.size()); | 894 ASSERT_EQ(1U, r.snapshots.size()); |
879 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, | 895 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, |
880 r.snapshots[0].source().updates_source); | 896 r.snapshots[0].source().updates_source); |
881 | 897 |
882 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(1) | 898 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(1) |
883 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), | 899 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), |
884 RecordSyncShare(&r))); | 900 RecordSyncShare(&r))); |
885 | 901 |
886 // We schedule a nudge with enough delay (10X poll interval) that at least | 902 // 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. | 903 // one or two polls would have taken place. The nudge should succeed. |
888 scheduler()->ScheduleNudge(poll * 10, NUDGE_SOURCE_LOCAL, types, FROM_HERE); | 904 scheduler()->ScheduleNudge(poll * 10, NUDGE_SOURCE_LOCAL, types, FROM_HERE); |
889 RunLoop(); | 905 RunLoop(); |
890 | 906 |
891 Mock::VerifyAndClearExpectations(syncer()); | 907 Mock::VerifyAndClearExpectations(syncer()); |
892 Mock::VerifyAndClearExpectations(delay()); | 908 Mock::VerifyAndClearExpectations(delay()); |
893 ASSERT_EQ(2U, r.snapshots.size()); | 909 ASSERT_EQ(2U, r.snapshots.size()); |
894 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, | 910 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, |
895 r.snapshots[1].source().updates_source); | 911 r.snapshots[1].source().updates_source); |
896 | 912 |
897 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(0); | 913 // Cleanup is not affected by backoff, but it should not relieve it either. |
| 914 EXPECT_CALL(*syncer(), |
| 915 SyncShare(_, CLEANUP_DISABLED_TYPES, CLEANUP_DISABLED_TYPES)) |
| 916 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)); |
898 EXPECT_CALL(*delay(), GetDelay(_)).Times(0); | 917 EXPECT_CALL(*delay(), GetDelay(_)).Times(0); |
899 | 918 |
900 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 919 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
901 RunLoop(); | 920 RunLoop(); |
902 | 921 |
| 922 scheduler()->ScheduleCleanupDisabledTypes(); |
903 scheduler()->ScheduleConfig( | 923 scheduler()->ScheduleConfig( |
904 types, GetUpdatesCallerInfo::RECONFIGURATION); | 924 types, GetUpdatesCallerInfo::RECONFIGURATION); |
905 PumpLoop(); | 925 PumpLoop(); |
906 | 926 |
907 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 927 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
908 RunLoop(); | 928 RunLoop(); |
909 | 929 |
910 scheduler()->ScheduleNudge( | 930 scheduler()->ScheduleNudge( |
911 zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE); | 931 zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE); |
912 scheduler()->ScheduleNudge( | 932 scheduler()->ScheduleNudge( |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1046 TimeDelta::FromSeconds(kMaxBackoffSeconds))); | 1066 TimeDelta::FromSeconds(kMaxBackoffSeconds))); |
1047 EXPECT_EQ(TimeDelta::FromSeconds(kMaxBackoffSeconds), | 1067 EXPECT_EQ(TimeDelta::FromSeconds(kMaxBackoffSeconds), |
1048 SyncScheduler::GetRecommendedDelay( | 1068 SyncScheduler::GetRecommendedDelay( |
1049 TimeDelta::FromSeconds(kMaxBackoffSeconds + 1))); | 1069 TimeDelta::FromSeconds(kMaxBackoffSeconds + 1))); |
1050 } | 1070 } |
1051 | 1071 |
1052 // Test that appropriate syncer steps are requested for each job type. | 1072 // Test that appropriate syncer steps are requested for each job type. |
1053 TEST_F(SyncSchedulerTest, SyncerSteps) { | 1073 TEST_F(SyncSchedulerTest, SyncerSteps) { |
1054 // Nudges. | 1074 // Nudges. |
1055 EXPECT_CALL(*syncer(), SyncShare(_, SYNCER_BEGIN, SYNCER_END)) | 1075 EXPECT_CALL(*syncer(), SyncShare(_, SYNCER_BEGIN, SYNCER_END)) |
1056 .Times(1); | 1076 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)); |
1057 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 1077 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
1058 RunLoop(); | 1078 RunLoop(); |
1059 | 1079 |
1060 scheduler()->ScheduleNudge( | 1080 scheduler()->ScheduleNudge( |
1061 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(), FROM_HERE); | 1081 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(), FROM_HERE); |
1062 PumpLoop(); | 1082 PumpLoop(); |
1063 // Pump again to run job. | 1083 // Pump again to run job. |
1064 PumpLoop(); | 1084 PumpLoop(); |
1065 | 1085 |
1066 StopSyncScheduler(); | 1086 StopSyncScheduler(); |
1067 Mock::VerifyAndClearExpectations(syncer()); | 1087 Mock::VerifyAndClearExpectations(syncer()); |
1068 | 1088 |
1069 // ClearUserData. | 1089 // ClearUserData. |
1070 EXPECT_CALL(*syncer(), SyncShare(_, CLEAR_PRIVATE_DATA, CLEAR_PRIVATE_DATA)) | 1090 EXPECT_CALL(*syncer(), SyncShare(_, CLEAR_PRIVATE_DATA, CLEAR_PRIVATE_DATA)) |
1071 .Times(1); | 1091 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)); |
1072 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 1092 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
1073 RunLoop(); | 1093 RunLoop(); |
1074 | 1094 |
1075 scheduler()->ScheduleClearUserData(); | 1095 scheduler()->ScheduleClearUserData(); |
1076 PumpLoop(); | 1096 PumpLoop(); |
1077 PumpLoop(); | 1097 PumpLoop(); |
1078 | 1098 |
1079 StopSyncScheduler(); | 1099 StopSyncScheduler(); |
1080 Mock::VerifyAndClearExpectations(syncer()); | 1100 Mock::VerifyAndClearExpectations(syncer()); |
1081 | 1101 |
1082 // Configuration. | 1102 // Configuration. |
1083 EXPECT_CALL(*syncer(), SyncShare(_, DOWNLOAD_UPDATES, APPLY_UPDATES)); | 1103 EXPECT_CALL(*syncer(), SyncShare(_, DOWNLOAD_UPDATES, APPLY_UPDATES)) |
| 1104 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)); |
1084 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 1105 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
1085 RunLoop(); | 1106 RunLoop(); |
1086 | 1107 |
1087 scheduler()->ScheduleConfig( | 1108 scheduler()->ScheduleConfig( |
1088 ModelTypeSet(), GetUpdatesCallerInfo::RECONFIGURATION); | 1109 ModelTypeSet(), GetUpdatesCallerInfo::RECONFIGURATION); |
1089 PumpLoop(); | 1110 PumpLoop(); |
1090 PumpLoop(); | 1111 PumpLoop(); |
1091 | 1112 |
1092 StopSyncScheduler(); | 1113 StopSyncScheduler(); |
1093 Mock::VerifyAndClearExpectations(syncer()); | 1114 Mock::VerifyAndClearExpectations(syncer()); |
1094 | 1115 |
1095 // Cleanup disabled types. | 1116 // Cleanup disabled types. |
1096 EXPECT_CALL(*syncer(), | 1117 EXPECT_CALL(*syncer(), |
1097 SyncShare(_, CLEANUP_DISABLED_TYPES, CLEANUP_DISABLED_TYPES)); | 1118 SyncShare(_, CLEANUP_DISABLED_TYPES, CLEANUP_DISABLED_TYPES)) |
| 1119 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)); |
1098 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 1120 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
1099 RunLoop(); | 1121 RunLoop(); |
1100 | 1122 |
1101 scheduler()->ScheduleCleanupDisabledTypes(); | 1123 scheduler()->ScheduleCleanupDisabledTypes(); |
1102 // Only need to pump once, as ScheduleCleanupDisabledTypes() | 1124 // Only need to pump once, as ScheduleCleanupDisabledTypes() |
1103 // schedules the job directly. | 1125 // schedules the job directly. |
1104 PumpLoop(); | 1126 PumpLoop(); |
1105 | 1127 |
1106 StopSyncScheduler(); | 1128 StopSyncScheduler(); |
1107 Mock::VerifyAndClearExpectations(syncer()); | 1129 Mock::VerifyAndClearExpectations(syncer()); |
1108 | 1130 |
1109 // Poll. | 1131 // Poll. |
1110 EXPECT_CALL(*syncer(), SyncShare(_, SYNCER_BEGIN, SYNCER_END)) | 1132 EXPECT_CALL(*syncer(), SyncShare(_, SYNCER_BEGIN, SYNCER_END)) |
1111 .Times(AtLeast(1)) | 1133 .Times(AtLeast(1)) |
1112 .WillRepeatedly(QuitLoopNowAction()); | 1134 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 1135 QuitLoopNowAction())); |
1113 const TimeDelta poll(TimeDelta::FromMilliseconds(10)); | 1136 const TimeDelta poll(TimeDelta::FromMilliseconds(10)); |
1114 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 1137 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
1115 | 1138 |
1116 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 1139 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
1117 RunLoop(); | 1140 RunLoop(); |
1118 | 1141 |
1119 // Run again to wait for polling. | 1142 // Run again to wait for polling. |
1120 RunLoop(); | 1143 RunLoop(); |
1121 | 1144 |
1122 StopSyncScheduler(); | 1145 StopSyncScheduler(); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1165 PumpLoop(); | 1188 PumpLoop(); |
1166 // Pump again to run job. | 1189 // Pump again to run job. |
1167 PumpLoop(); | 1190 PumpLoop(); |
1168 | 1191 |
1169 StopSyncScheduler(); | 1192 StopSyncScheduler(); |
1170 | 1193 |
1171 EXPECT_TRUE(expected == context()->previous_session_routing_info()); | 1194 EXPECT_TRUE(expected == context()->previous_session_routing_info()); |
1172 } | 1195 } |
1173 | 1196 |
1174 } // namespace browser_sync | 1197 } // namespace browser_sync |
OLD | NEW |