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/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/test/test_timeouts.h" | 10 #include "base/test/test_timeouts.h" |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 } | 87 } |
88 | 88 |
89 ModelSafeRoutingInfo TypesToRoutingInfo(ModelTypeSet types) { | 89 ModelSafeRoutingInfo TypesToRoutingInfo(ModelTypeSet types) { |
90 ModelSafeRoutingInfo routes; | 90 ModelSafeRoutingInfo routes; |
91 for (ModelTypeSet::Iterator iter = types.First(); iter.Good(); iter.Inc()) { | 91 for (ModelTypeSet::Iterator iter = types.First(); iter.Good(); iter.Inc()) { |
92 routes[iter.Get()] = GROUP_PASSIVE; | 92 routes[iter.Get()] = GROUP_PASSIVE; |
93 } | 93 } |
94 return routes; | 94 return routes; |
95 } | 95 } |
96 | 96 |
97 // Convenient to use in tests wishing to analyze SyncShare calls over time. | 97 |
98 static const size_t kMinNumSamples = 5; | 98 static const size_t kMinNumSamples = 5; |
| 99 |
| 100 // Test harness for the SyncScheduler. Test the delays and backoff timers used |
| 101 // in response to various events. |
| 102 // |
| 103 // These tests execute in real time with real timers. We try to keep the |
| 104 // delays short, but there is a limit to how short we can make them. The |
| 105 // timers on some platforms (ie. Windows) have a timer resolution greater than |
| 106 // 1ms. Using 1ms delays may result in test flakiness. |
| 107 // |
| 108 // See crbug.com/402212 for more info. |
99 class SyncSchedulerTest : public testing::Test { | 109 class SyncSchedulerTest : public testing::Test { |
100 public: | 110 public: |
101 SyncSchedulerTest() : syncer_(NULL), delay_(NULL), weak_ptr_factory_(this) {} | 111 SyncSchedulerTest() : syncer_(NULL), delay_(NULL), weak_ptr_factory_(this) {} |
102 | 112 |
103 class MockDelayProvider : public BackoffDelayProvider { | 113 class MockDelayProvider : public BackoffDelayProvider { |
104 public: | 114 public: |
105 MockDelayProvider() : BackoffDelayProvider( | 115 MockDelayProvider() : BackoffDelayProvider( |
106 TimeDelta::FromSeconds(kInitialBackoffRetrySeconds), | 116 TimeDelta::FromSeconds(kInitialBackoffRetrySeconds), |
107 TimeDelta::FromSeconds(kInitialBackoffImmediateRetrySeconds)) { | 117 TimeDelta::FromSeconds(kInitialBackoffImmediateRetrySeconds)) { |
108 } | 118 } |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 scheduler()->ScheduleConfiguration(params); | 346 scheduler()->ScheduleConfiguration(params); |
337 PumpLoop(); | 347 PumpLoop(); |
338 ASSERT_EQ(1, ready_counter.times_called()); | 348 ASSERT_EQ(1, ready_counter.times_called()); |
339 ASSERT_EQ(0, retry_counter.times_called()); | 349 ASSERT_EQ(0, retry_counter.times_called()); |
340 } | 350 } |
341 | 351 |
342 // Simulate a failure and make sure the config request is retried. | 352 // Simulate a failure and make sure the config request is retried. |
343 TEST_F(SyncSchedulerTest, ConfigWithBackingOff) { | 353 TEST_F(SyncSchedulerTest, ConfigWithBackingOff) { |
344 UseMockDelayProvider(); | 354 UseMockDelayProvider(); |
345 EXPECT_CALL(*delay(), GetDelay(_)) | 355 EXPECT_CALL(*delay(), GetDelay(_)) |
346 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(1))); | 356 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(20))); |
347 SyncShareTimes times; | 357 SyncShareTimes times; |
348 const ModelTypeSet model_types(BOOKMARKS); | 358 const ModelTypeSet model_types(BOOKMARKS); |
349 | 359 |
350 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 360 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
351 | 361 |
352 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) | 362 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) |
353 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureFailed), | 363 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureFailed), |
354 RecordSyncShare(×))) | 364 RecordSyncShare(×))) |
355 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureFailed), | 365 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureFailed), |
356 RecordSyncShare(×))); | 366 RecordSyncShare(×))); |
(...skipping 25 matching lines...) Expand all Loading... |
382 RunLoop(); | 392 RunLoop(); |
383 | 393 |
384 ASSERT_EQ(1, ready_counter.times_called()); | 394 ASSERT_EQ(1, ready_counter.times_called()); |
385 } | 395 } |
386 | 396 |
387 // Simuilate SyncSchedulerImpl::Stop being called in the middle of Configure. | 397 // Simuilate SyncSchedulerImpl::Stop being called in the middle of Configure. |
388 // This can happen if server returns NOT_MY_BIRTHDAY. | 398 // This can happen if server returns NOT_MY_BIRTHDAY. |
389 TEST_F(SyncSchedulerTest, ConfigWithStop) { | 399 TEST_F(SyncSchedulerTest, ConfigWithStop) { |
390 UseMockDelayProvider(); | 400 UseMockDelayProvider(); |
391 EXPECT_CALL(*delay(), GetDelay(_)) | 401 EXPECT_CALL(*delay(), GetDelay(_)) |
392 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(1))); | 402 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(20))); |
393 SyncShareTimes times; | 403 SyncShareTimes times; |
394 const ModelTypeSet model_types(BOOKMARKS); | 404 const ModelTypeSet model_types(BOOKMARKS); |
395 | 405 |
396 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 406 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
397 | 407 |
398 // Make ConfigureSyncShare call scheduler->Stop(). It is not supposed to call | 408 // Make ConfigureSyncShare call scheduler->Stop(). It is not supposed to call |
399 // retry_task or dereference configuration params. | 409 // retry_task or dereference configuration params. |
400 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) | 410 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) |
401 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureFailed), | 411 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureFailed), |
402 StopScheduler(scheduler()), | 412 StopScheduler(scheduler()), |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
645 scheduler()->ScheduleLocalNudge(zero(), model_types, FROM_HERE); | 655 scheduler()->ScheduleLocalNudge(zero(), model_types, FROM_HERE); |
646 RunLoop(); | 656 RunLoop(); |
647 | 657 |
648 EXPECT_EQ(delay2, scheduler()->GetSessionsCommitDelay()); | 658 EXPECT_EQ(delay2, scheduler()->GetSessionsCommitDelay()); |
649 StopSyncScheduler(); | 659 StopSyncScheduler(); |
650 } | 660 } |
651 | 661 |
652 // Test that no syncing occurs when throttled. | 662 // Test that no syncing occurs when throttled. |
653 TEST_F(SyncSchedulerTest, ThrottlingDoesThrottle) { | 663 TEST_F(SyncSchedulerTest, ThrottlingDoesThrottle) { |
654 const ModelTypeSet types(BOOKMARKS); | 664 const ModelTypeSet types(BOOKMARKS); |
655 TimeDelta poll(TimeDelta::FromMilliseconds(5)); | 665 TimeDelta poll(TimeDelta::FromMilliseconds(20)); |
656 TimeDelta throttle(TimeDelta::FromMinutes(10)); | 666 TimeDelta throttle(TimeDelta::FromMinutes(10)); |
657 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 667 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
658 | 668 |
659 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) | 669 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) |
660 .WillOnce(DoAll( | 670 .WillOnce(DoAll( |
661 WithArg<2>(sessions::test_util::SimulateThrottled(throttle)), | 671 WithArg<2>(sessions::test_util::SimulateThrottled(throttle)), |
662 Return(true))) | 672 Return(true))) |
663 .WillRepeatedly(AddFailureAndQuitLoopNow()); | 673 .WillRepeatedly(AddFailureAndQuitLoopNow()); |
664 | 674 |
665 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 675 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
909 | 919 |
910 RunLoop(); | 920 RunLoop(); |
911 Mock::VerifyAndClearExpectations(syncer()); | 921 Mock::VerifyAndClearExpectations(syncer()); |
912 } | 922 } |
913 | 923 |
914 class BackoffTriggersSyncSchedulerTest : public SyncSchedulerTest { | 924 class BackoffTriggersSyncSchedulerTest : public SyncSchedulerTest { |
915 virtual void SetUp() { | 925 virtual void SetUp() { |
916 SyncSchedulerTest::SetUp(); | 926 SyncSchedulerTest::SetUp(); |
917 UseMockDelayProvider(); | 927 UseMockDelayProvider(); |
918 EXPECT_CALL(*delay(), GetDelay(_)) | 928 EXPECT_CALL(*delay(), GetDelay(_)) |
919 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(1))); | 929 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(10))); |
920 } | 930 } |
921 | 931 |
922 virtual void TearDown() { | 932 virtual void TearDown() { |
923 StopSyncScheduler(); | 933 StopSyncScheduler(); |
924 SyncSchedulerTest::TearDown(); | 934 SyncSchedulerTest::TearDown(); |
925 } | 935 } |
926 }; | 936 }; |
927 | 937 |
928 // Have the sycner fail during commit. Expect that the scheduler enters | 938 // Have the sycner fail during commit. Expect that the scheduler enters |
929 // backoff. | 939 // backoff. |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
994 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); | 1004 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); |
995 scheduler()->ScheduleConfiguration(params); | 1005 scheduler()->ScheduleConfiguration(params); |
996 RunLoop(); | 1006 RunLoop(); |
997 | 1007 |
998 EXPECT_TRUE(scheduler()->IsBackingOff()); | 1008 EXPECT_TRUE(scheduler()->IsBackingOff()); |
999 } | 1009 } |
1000 | 1010 |
1001 // Test that no polls or extraneous nudges occur when in backoff. | 1011 // Test that no polls or extraneous nudges occur when in backoff. |
1002 TEST_F(SyncSchedulerTest, BackoffDropsJobs) { | 1012 TEST_F(SyncSchedulerTest, BackoffDropsJobs) { |
1003 SyncShareTimes times; | 1013 SyncShareTimes times; |
1004 TimeDelta poll(TimeDelta::FromMilliseconds(5)); | 1014 TimeDelta poll(TimeDelta::FromMilliseconds(10)); |
1005 const ModelTypeSet types(BOOKMARKS); | 1015 const ModelTypeSet types(BOOKMARKS); |
1006 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 1016 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
1007 UseMockDelayProvider(); | 1017 UseMockDelayProvider(); |
1008 | 1018 |
1009 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 1019 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
1010 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), | 1020 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), |
1011 RecordSyncShareMultiple(×, 1U))); | 1021 RecordSyncShareMultiple(×, 1U))); |
1012 EXPECT_CALL(*delay(), GetDelay(_)). | 1022 EXPECT_CALL(*delay(), GetDelay(_)). |
1013 WillRepeatedly(Return(TimeDelta::FromDays(1))); | 1023 WillRepeatedly(Return(TimeDelta::FromDays(1))); |
1014 | 1024 |
1015 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 1025 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
1016 | 1026 |
1017 // This nudge should fail and put us into backoff. Thanks to our mock | 1027 // This nudge should fail and put us into backoff. Thanks to our mock |
1018 // GetDelay() setup above, this will be a long backoff. | 1028 // GetDelay() setup above, this will be a long backoff. |
1019 scheduler()->ScheduleLocalNudge(zero(), types, FROM_HERE); | 1029 scheduler()->ScheduleLocalNudge(zero(), types, FROM_HERE); |
1020 RunLoop(); | 1030 RunLoop(); |
1021 | 1031 |
1022 // From this point forward, no SyncShare functions should be invoked. | 1032 // From this point forward, no SyncShare functions should be invoked. |
1023 Mock::VerifyAndClearExpectations(syncer()); | 1033 Mock::VerifyAndClearExpectations(syncer()); |
1024 | 1034 |
1025 // Wait a while (10x poll interval) so a few poll jobs will be attempted. | 1035 // Wait a while (10x poll interval) so a few poll jobs will be attempted. |
1026 PumpLoopFor(poll * 10); | 1036 PumpLoopFor(poll * 10); |
1027 | 1037 |
1028 // Try (and fail) to schedule a nudge. | 1038 // Try (and fail) to schedule a nudge. |
1029 scheduler()->ScheduleLocalNudge( | 1039 scheduler()->ScheduleLocalNudge( |
1030 base::TimeDelta::FromMilliseconds(1), | 1040 base::TimeDelta::FromMilliseconds(10), |
1031 types, | 1041 types, |
1032 FROM_HERE); | 1042 FROM_HERE); |
1033 | 1043 |
1034 Mock::VerifyAndClearExpectations(syncer()); | 1044 Mock::VerifyAndClearExpectations(syncer()); |
1035 Mock::VerifyAndClearExpectations(delay()); | 1045 Mock::VerifyAndClearExpectations(delay()); |
1036 | 1046 |
1037 EXPECT_CALL(*delay(), GetDelay(_)).Times(0); | 1047 EXPECT_CALL(*delay(), GetDelay(_)).Times(0); |
1038 | 1048 |
1039 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 1049 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
1040 | 1050 |
(...skipping 15 matching lines...) Expand all Loading... |
1056 // Test that backoff is shaping traffic properly with consecutive errors. | 1066 // Test that backoff is shaping traffic properly with consecutive errors. |
1057 TEST_F(SyncSchedulerTest, BackoffElevation) { | 1067 TEST_F(SyncSchedulerTest, BackoffElevation) { |
1058 SyncShareTimes times; | 1068 SyncShareTimes times; |
1059 UseMockDelayProvider(); | 1069 UseMockDelayProvider(); |
1060 | 1070 |
1061 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)).Times(kMinNumSamples) | 1071 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)).Times(kMinNumSamples) |
1062 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), | 1072 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), |
1063 RecordSyncShareMultiple(×, kMinNumSamples))); | 1073 RecordSyncShareMultiple(×, kMinNumSamples))); |
1064 | 1074 |
1065 const TimeDelta first = TimeDelta::FromSeconds(kInitialBackoffRetrySeconds); | 1075 const TimeDelta first = TimeDelta::FromSeconds(kInitialBackoffRetrySeconds); |
1066 const TimeDelta second = TimeDelta::FromMilliseconds(2); | 1076 const TimeDelta second = TimeDelta::FromMilliseconds(20); |
1067 const TimeDelta third = TimeDelta::FromMilliseconds(3); | 1077 const TimeDelta third = TimeDelta::FromMilliseconds(30); |
1068 const TimeDelta fourth = TimeDelta::FromMilliseconds(4); | 1078 const TimeDelta fourth = TimeDelta::FromMilliseconds(40); |
1069 const TimeDelta fifth = TimeDelta::FromMilliseconds(5); | 1079 const TimeDelta fifth = TimeDelta::FromMilliseconds(50); |
1070 const TimeDelta sixth = TimeDelta::FromDays(1); | 1080 const TimeDelta sixth = TimeDelta::FromDays(1); |
1071 | 1081 |
1072 EXPECT_CALL(*delay(), GetDelay(first)).WillOnce(Return(second)) | 1082 EXPECT_CALL(*delay(), GetDelay(first)).WillOnce(Return(second)) |
1073 .RetiresOnSaturation(); | 1083 .RetiresOnSaturation(); |
1074 EXPECT_CALL(*delay(), GetDelay(second)).WillOnce(Return(third)) | 1084 EXPECT_CALL(*delay(), GetDelay(second)).WillOnce(Return(third)) |
1075 .RetiresOnSaturation(); | 1085 .RetiresOnSaturation(); |
1076 EXPECT_CALL(*delay(), GetDelay(third)).WillOnce(Return(fourth)) | 1086 EXPECT_CALL(*delay(), GetDelay(third)).WillOnce(Return(fourth)) |
1077 .RetiresOnSaturation(); | 1087 .RetiresOnSaturation(); |
1078 EXPECT_CALL(*delay(), GetDelay(fourth)).WillOnce(Return(fifth)) | 1088 EXPECT_CALL(*delay(), GetDelay(fourth)).WillOnce(Return(fifth)) |
1079 .RetiresOnSaturation(); | 1089 .RetiresOnSaturation(); |
(...skipping 12 matching lines...) Expand all Loading... |
1092 EXPECT_GE(times[4] - times[3], fifth); | 1102 EXPECT_GE(times[4] - times[3], fifth); |
1093 } | 1103 } |
1094 | 1104 |
1095 // Test that things go back to normal once a retry makes forward progress. | 1105 // Test that things go back to normal once a retry makes forward progress. |
1096 TEST_F(SyncSchedulerTest, BackoffRelief) { | 1106 TEST_F(SyncSchedulerTest, BackoffRelief) { |
1097 SyncShareTimes times; | 1107 SyncShareTimes times; |
1098 const TimeDelta poll(TimeDelta::FromMilliseconds(10)); | 1108 const TimeDelta poll(TimeDelta::FromMilliseconds(10)); |
1099 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 1109 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
1100 UseMockDelayProvider(); | 1110 UseMockDelayProvider(); |
1101 | 1111 |
1102 const TimeDelta backoff = TimeDelta::FromMilliseconds(5); | 1112 const TimeDelta backoff = TimeDelta::FromMilliseconds(10); |
1103 EXPECT_CALL(*delay(), GetDelay(_)).WillOnce(Return(backoff)); | 1113 EXPECT_CALL(*delay(), GetDelay(_)).WillOnce(Return(backoff)); |
1104 | 1114 |
1105 // Optimal start for the post-backoff poll party. | 1115 // Optimal start for the post-backoff poll party. |
1106 TimeTicks optimal_start = TimeTicks::Now(); | 1116 TimeTicks optimal_start = TimeTicks::Now(); |
1107 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 1117 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
1108 | 1118 |
1109 // Kick off the test with a failed nudge. | 1119 // Kick off the test with a failed nudge. |
1110 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 1120 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
1111 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), | 1121 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), |
1112 RecordSyncShare(×))); | 1122 RecordSyncShare(×))); |
(...skipping 29 matching lines...) Expand all Loading... |
1142 EXPECT_GE(times[i], optimal_job_time); | 1152 EXPECT_GE(times[i], optimal_job_time); |
1143 } | 1153 } |
1144 | 1154 |
1145 StopSyncScheduler(); | 1155 StopSyncScheduler(); |
1146 } | 1156 } |
1147 | 1157 |
1148 // Test that poll failures are ignored. They should have no effect on | 1158 // Test that poll failures are ignored. They should have no effect on |
1149 // subsequent poll attempts, nor should they trigger a backoff/retry. | 1159 // subsequent poll attempts, nor should they trigger a backoff/retry. |
1150 TEST_F(SyncSchedulerTest, TransientPollFailure) { | 1160 TEST_F(SyncSchedulerTest, TransientPollFailure) { |
1151 SyncShareTimes times; | 1161 SyncShareTimes times; |
1152 const TimeDelta poll_interval(TimeDelta::FromMilliseconds(1)); | 1162 const TimeDelta poll_interval(TimeDelta::FromMilliseconds(10)); |
1153 scheduler()->OnReceivedLongPollIntervalUpdate(poll_interval); | 1163 scheduler()->OnReceivedLongPollIntervalUpdate(poll_interval); |
1154 UseMockDelayProvider(); // Will cause test failure if backoff is initiated. | 1164 UseMockDelayProvider(); // Will cause test failure if backoff is initiated. |
1155 | 1165 |
1156 EXPECT_CALL(*syncer(), PollSyncShare(_,_)) | 1166 EXPECT_CALL(*syncer(), PollSyncShare(_,_)) |
1157 .WillOnce(DoAll(Invoke(sessions::test_util::SimulatePollFailed), | 1167 .WillOnce(DoAll(Invoke(sessions::test_util::SimulatePollFailed), |
1158 RecordSyncShare(×))) | 1168 RecordSyncShare(×))) |
1159 .WillOnce(DoAll(Invoke(sessions::test_util::SimulatePollSuccess), | 1169 .WillOnce(DoAll(Invoke(sessions::test_util::SimulatePollSuccess), |
1160 RecordSyncShare(×))); | 1170 RecordSyncShare(×))); |
1161 | 1171 |
1162 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 1172 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1304 // poll once more | 1314 // poll once more |
1305 EXPECT_CALL(*syncer(), PollSyncShare(_,_)) | 1315 EXPECT_CALL(*syncer(), PollSyncShare(_,_)) |
1306 .WillOnce(DoAll(Invoke(sessions::test_util::SimulatePollSuccess), | 1316 .WillOnce(DoAll(Invoke(sessions::test_util::SimulatePollSuccess), |
1307 RecordSyncShare(×))); | 1317 RecordSyncShare(×))); |
1308 scheduler()->OnCredentialsUpdated(); | 1318 scheduler()->OnCredentialsUpdated(); |
1309 connection()->SetServerStatus(HttpResponse::SERVER_CONNECTION_OK); | 1319 connection()->SetServerStatus(HttpResponse::SERVER_CONNECTION_OK); |
1310 RunLoop(); | 1320 RunLoop(); |
1311 StopSyncScheduler(); | 1321 StopSyncScheduler(); |
1312 } | 1322 } |
1313 | 1323 |
1314 #if defined(OS_WIN) | 1324 TEST_F(SyncSchedulerTest, SuccessfulRetry) { |
1315 // Times out: http://crbug.com/402212 | |
1316 #define MAYBE_SuccessfulRetry DISABLED_SuccessfulRetry | |
1317 #else | |
1318 #define MAYBE_SuccessfulRetry SuccessfulRetry | |
1319 #endif | |
1320 TEST_F(SyncSchedulerTest, MAYBE_SuccessfulRetry) { | |
1321 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 1325 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
1322 | 1326 |
1323 SyncShareTimes times; | 1327 SyncShareTimes times; |
1324 base::TimeDelta delay = base::TimeDelta::FromMilliseconds(1); | 1328 base::TimeDelta delay = base::TimeDelta::FromMilliseconds(10); |
1325 scheduler()->OnReceivedGuRetryDelay(delay); | 1329 scheduler()->OnReceivedGuRetryDelay(delay); |
1326 EXPECT_EQ(delay, GetRetryTimerDelay()); | 1330 EXPECT_EQ(delay, GetRetryTimerDelay()); |
1327 | 1331 |
1328 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 1332 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
1329 .WillOnce( | 1333 .WillOnce( |
1330 DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 1334 DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), |
1331 RecordSyncShare(×))); | 1335 RecordSyncShare(×))); |
1332 | 1336 |
1333 // Run to wait for retrying. | 1337 // Run to wait for retrying. |
1334 RunLoop(); | 1338 RunLoop(); |
1335 | 1339 |
1336 StopSyncScheduler(); | 1340 StopSyncScheduler(); |
1337 } | 1341 } |
1338 | 1342 |
1339 #if defined(OS_WIN) | 1343 TEST_F(SyncSchedulerTest, FailedRetry) { |
1340 // Times out: http://crbug.com/402212 | |
1341 #define MAYBE_FailedRetry DISABLED_FailedRetry | |
1342 #else | |
1343 #define MAYBE_FailedRetry FailedRetry | |
1344 #endif | |
1345 TEST_F(SyncSchedulerTest, MAYBE_FailedRetry) { | |
1346 UseMockDelayProvider(); | 1344 UseMockDelayProvider(); |
1347 EXPECT_CALL(*delay(), GetDelay(_)) | 1345 EXPECT_CALL(*delay(), GetDelay(_)) |
1348 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(1))); | 1346 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(10))); |
1349 | 1347 |
1350 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 1348 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
1351 | 1349 |
1352 base::TimeDelta delay = base::TimeDelta::FromMilliseconds(1); | 1350 base::TimeDelta delay = base::TimeDelta::FromMilliseconds(10); |
1353 scheduler()->OnReceivedGuRetryDelay(delay); | 1351 scheduler()->OnReceivedGuRetryDelay(delay); |
1354 | 1352 |
1355 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 1353 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
1356 .WillOnce( | 1354 .WillOnce( |
1357 DoAll(Invoke(sessions::test_util::SimulateDownloadUpdatesFailed), | 1355 DoAll(Invoke(sessions::test_util::SimulateDownloadUpdatesFailed), |
1358 QuitLoopNowAction())); | 1356 QuitLoopNowAction())); |
1359 | 1357 |
1360 // Run to wait for retrying. | 1358 // Run to wait for retrying. |
1361 RunLoop(); | 1359 RunLoop(); |
1362 | 1360 |
1363 EXPECT_TRUE(scheduler()->IsBackingOff()); | 1361 EXPECT_TRUE(scheduler()->IsBackingOff()); |
1364 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 1362 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
1365 .WillOnce( | 1363 .WillOnce( |
1366 DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 1364 DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), |
1367 QuitLoopNowAction())); | 1365 QuitLoopNowAction())); |
1368 | 1366 |
1369 // Run to wait for second retrying. | 1367 // Run to wait for second retrying. |
1370 RunLoop(); | 1368 RunLoop(); |
1371 | 1369 |
1372 StopSyncScheduler(); | 1370 StopSyncScheduler(); |
1373 } | 1371 } |
1374 | 1372 |
1375 ACTION_P2(VerifyRetryTimerDelay, scheduler_test, expected_delay) { | 1373 ACTION_P2(VerifyRetryTimerDelay, scheduler_test, expected_delay) { |
1376 EXPECT_EQ(expected_delay, scheduler_test->GetRetryTimerDelay()); | 1374 EXPECT_EQ(expected_delay, scheduler_test->GetRetryTimerDelay()); |
1377 } | 1375 } |
1378 | 1376 |
1379 #if defined(OS_WIN) | 1377 TEST_F(SyncSchedulerTest, ReceiveNewRetryDelay) { |
1380 // Times out: http://crbug.com/402212 | |
1381 #define MAYBE_ReceiveNewRetryDelay DISABLED_ReceiveNewRetryDelay | |
1382 #else | |
1383 #define MAYBE_ReceiveNewRetryDelay ReceiveNewRetryDelay | |
1384 #endif | |
1385 TEST_F(SyncSchedulerTest, MAYBE_ReceiveNewRetryDelay) { | |
1386 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 1378 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
1387 | 1379 |
1388 SyncShareTimes times; | 1380 SyncShareTimes times; |
1389 base::TimeDelta delay1 = base::TimeDelta::FromMilliseconds(100); | 1381 base::TimeDelta delay1 = base::TimeDelta::FromMilliseconds(100); |
1390 base::TimeDelta delay2 = base::TimeDelta::FromMilliseconds(200); | 1382 base::TimeDelta delay2 = base::TimeDelta::FromMilliseconds(200); |
1391 | 1383 |
1392 scheduler()->ScheduleLocalRefreshRequest(zero(), ModelTypeSet(BOOKMARKS), | 1384 scheduler()->ScheduleLocalRefreshRequest(zero(), ModelTypeSet(BOOKMARKS), |
1393 FROM_HERE); | 1385 FROM_HERE); |
1394 scheduler()->OnReceivedGuRetryDelay(delay1); | 1386 scheduler()->OnReceivedGuRetryDelay(delay1); |
1395 EXPECT_EQ(delay1, GetRetryTimerDelay()); | 1387 EXPECT_EQ(delay1, GetRetryTimerDelay()); |
(...skipping 12 matching lines...) Expand all Loading... |
1408 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 1400 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), |
1409 RecordSyncShare(×))); | 1401 RecordSyncShare(×))); |
1410 | 1402 |
1411 // Run to wait for retrying. | 1403 // Run to wait for retrying. |
1412 RunLoop(); | 1404 RunLoop(); |
1413 | 1405 |
1414 StopSyncScheduler(); | 1406 StopSyncScheduler(); |
1415 } | 1407 } |
1416 | 1408 |
1417 } // namespace syncer | 1409 } // namespace syncer |
OLD | NEW |