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 16 matching lines...) Expand all Loading... |
27 using base::TimeDelta; | 27 using base::TimeDelta; |
28 using base::TimeTicks; | 28 using base::TimeTicks; |
29 using testing::_; | 29 using testing::_; |
30 using testing::AtLeast; | 30 using testing::AtLeast; |
31 using testing::DoAll; | 31 using testing::DoAll; |
32 using testing::Invoke; | 32 using testing::Invoke; |
33 using testing::Mock; | 33 using testing::Mock; |
34 using testing::Return; | 34 using testing::Return; |
35 using testing::WithArg; | 35 using testing::WithArg; |
36 using testing::WithArgs; | 36 using testing::WithArgs; |
37 using testing::WithoutArgs; | |
38 | 37 |
39 namespace syncer { | 38 namespace syncer { |
40 using sessions::SyncSession; | 39 using sessions::SyncSession; |
41 using sessions::SyncSessionContext; | 40 using sessions::SyncSessionContext; |
42 using sync_pb::GetUpdatesCallerInfo; | 41 using sync_pb::GetUpdatesCallerInfo; |
43 | 42 |
44 class MockSyncer : public Syncer { | 43 class MockSyncer : public Syncer { |
45 public: | 44 public: |
46 MockSyncer(); | 45 MockSyncer(); |
47 MOCK_METHOD3(NormalSyncShare, bool(ModelTypeSet, | 46 MOCK_METHOD3(NormalSyncShare, bool(ModelTypeSet, |
48 const sessions::NudgeTracker&, | 47 const sessions::NudgeTracker&, |
49 sessions::SyncSession*)); | 48 sessions::SyncSession*)); |
50 MOCK_METHOD3(ConfigureSyncShare, | 49 MOCK_METHOD3(ConfigureSyncShare, |
51 bool(ModelTypeSet, | 50 bool(ModelTypeSet, |
52 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource, | 51 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource, |
53 SyncSession*)); | 52 SyncSession*)); |
54 MOCK_METHOD2(PollSyncShare, bool(ModelTypeSet, sessions::SyncSession*)); | 53 MOCK_METHOD2(PollSyncShare, bool(ModelTypeSet, sessions::SyncSession*)); |
55 MOCK_METHOD2(RetrySyncShare, bool(ModelTypeSet, sessions::SyncSession*)); | |
56 }; | 54 }; |
57 | 55 |
58 MockSyncer::MockSyncer() | 56 MockSyncer::MockSyncer() |
59 : Syncer(NULL) {} | 57 : Syncer(NULL) {} |
60 | 58 |
61 typedef std::vector<TimeTicks> SyncShareTimes; | 59 typedef std::vector<TimeTicks> SyncShareTimes; |
62 | 60 |
63 void QuitLoopNow() { | 61 void QuitLoopNow() { |
64 // We use QuitNow() instead of Quit() as the latter may get stalled | 62 // We use QuitNow() instead of Quit() as the latter may get stalled |
65 // indefinitely in the presence of repeated timers with low delays | 63 // indefinitely in the presence of repeated timers with low delays |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 delay_ = new MockDelayProvider(); | 203 delay_ = new MockDelayProvider(); |
206 scheduler_->delay_provider_.reset(delay_); | 204 scheduler_->delay_provider_.reset(delay_); |
207 } | 205 } |
208 | 206 |
209 SyncSessionContext* context() { return context_.get(); } | 207 SyncSessionContext* context() { return context_.get(); } |
210 | 208 |
211 ModelTypeSet GetThrottledTypes() { | 209 ModelTypeSet GetThrottledTypes() { |
212 return scheduler_->nudge_tracker_.GetThrottledTypes(); | 210 return scheduler_->nudge_tracker_.GetThrottledTypes(); |
213 } | 211 } |
214 | 212 |
215 base::TimeDelta GetRetryTimerDelay() { | |
216 EXPECT_TRUE(scheduler_->retry_timer_.IsRunning()); | |
217 return scheduler_->retry_timer_.GetCurrentDelay(); | |
218 } | |
219 | |
220 private: | 213 private: |
221 syncable::Directory* directory() { | 214 syncable::Directory* directory() { |
222 return dir_maker_.directory(); | 215 return dir_maker_.directory(); |
223 } | 216 } |
224 | 217 |
225 base::MessageLoop loop_; | 218 base::MessageLoop loop_; |
226 TestDirectorySetterUpper dir_maker_; | 219 TestDirectorySetterUpper dir_maker_; |
227 CancelationSignal cancelation_signal_; | 220 CancelationSignal cancelation_signal_; |
228 scoped_ptr<MockConnectionManager> connection_; | 221 scoped_ptr<MockConnectionManager> connection_; |
229 scoped_ptr<SyncSessionContext> context_; | 222 scoped_ptr<SyncSessionContext> context_; |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 RecordSyncShare(×2))); | 532 RecordSyncShare(×2))); |
540 scheduler()->ScheduleInvalidationNudge(zero(), invalidations2, FROM_HERE); | 533 scheduler()->ScheduleInvalidationNudge(zero(), invalidations2, FROM_HERE); |
541 RunLoop(); | 534 RunLoop(); |
542 } | 535 } |
543 | 536 |
544 // Test that polling works as expected. | 537 // Test that polling works as expected. |
545 TEST_F(SyncSchedulerTest, Polling) { | 538 TEST_F(SyncSchedulerTest, Polling) { |
546 SyncShareTimes times; | 539 SyncShareTimes times; |
547 TimeDelta poll_interval(TimeDelta::FromMilliseconds(30)); | 540 TimeDelta poll_interval(TimeDelta::FromMilliseconds(30)); |
548 EXPECT_CALL(*syncer(), PollSyncShare(_,_)).Times(AtLeast(kMinNumSamples)) | 541 EXPECT_CALL(*syncer(), PollSyncShare(_,_)).Times(AtLeast(kMinNumSamples)) |
549 .WillRepeatedly( | 542 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulatePollSuccess), |
550 DoAll(Invoke(sessions::test_util::SimulatePollRetrySuccess), | 543 RecordSyncShareMultiple(×, kMinNumSamples))); |
551 RecordSyncShareMultiple(×, kMinNumSamples))); | |
552 | 544 |
553 scheduler()->OnReceivedLongPollIntervalUpdate(poll_interval); | 545 scheduler()->OnReceivedLongPollIntervalUpdate(poll_interval); |
554 | 546 |
555 TimeTicks optimal_start = TimeTicks::Now() + poll_interval; | 547 TimeTicks optimal_start = TimeTicks::Now() + poll_interval; |
556 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 548 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
557 | 549 |
558 // Run again to wait for polling. | 550 // Run again to wait for polling. |
559 RunLoop(); | 551 RunLoop(); |
560 | 552 |
561 StopSyncScheduler(); | 553 StopSyncScheduler(); |
562 AnalyzePollRun(times, kMinNumSamples, optimal_start, poll_interval); | 554 AnalyzePollRun(times, kMinNumSamples, optimal_start, poll_interval); |
563 } | 555 } |
564 | 556 |
565 // Test that the short poll interval is used. | 557 // Test that the short poll interval is used. |
566 TEST_F(SyncSchedulerTest, PollNotificationsDisabled) { | 558 TEST_F(SyncSchedulerTest, PollNotificationsDisabled) { |
567 SyncShareTimes times; | 559 SyncShareTimes times; |
568 TimeDelta poll_interval(TimeDelta::FromMilliseconds(30)); | 560 TimeDelta poll_interval(TimeDelta::FromMilliseconds(30)); |
569 EXPECT_CALL(*syncer(), PollSyncShare(_,_)).Times(AtLeast(kMinNumSamples)) | 561 EXPECT_CALL(*syncer(), PollSyncShare(_,_)).Times(AtLeast(kMinNumSamples)) |
570 .WillRepeatedly( | 562 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulatePollSuccess), |
571 DoAll(Invoke(sessions::test_util::SimulatePollRetrySuccess), | 563 RecordSyncShareMultiple(×, kMinNumSamples))); |
572 RecordSyncShareMultiple(×, kMinNumSamples))); | |
573 | 564 |
574 scheduler()->OnReceivedShortPollIntervalUpdate(poll_interval); | 565 scheduler()->OnReceivedShortPollIntervalUpdate(poll_interval); |
575 scheduler()->SetNotificationsEnabled(false); | 566 scheduler()->SetNotificationsEnabled(false); |
576 | 567 |
577 TimeTicks optimal_start = TimeTicks::Now() + poll_interval; | 568 TimeTicks optimal_start = TimeTicks::Now() + poll_interval; |
578 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 569 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
579 | 570 |
580 // Run again to wait for polling. | 571 // Run again to wait for polling. |
581 RunLoop(); | 572 RunLoop(); |
582 | 573 |
583 StopSyncScheduler(); | 574 StopSyncScheduler(); |
584 AnalyzePollRun(times, kMinNumSamples, optimal_start, poll_interval); | 575 AnalyzePollRun(times, kMinNumSamples, optimal_start, poll_interval); |
585 } | 576 } |
586 | 577 |
587 // Test that polling intervals are updated when needed. | 578 // Test that polling intervals are updated when needed. |
588 TEST_F(SyncSchedulerTest, PollIntervalUpdate) { | 579 TEST_F(SyncSchedulerTest, PollIntervalUpdate) { |
589 SyncShareTimes times; | 580 SyncShareTimes times; |
590 TimeDelta poll1(TimeDelta::FromMilliseconds(120)); | 581 TimeDelta poll1(TimeDelta::FromMilliseconds(120)); |
591 TimeDelta poll2(TimeDelta::FromMilliseconds(30)); | 582 TimeDelta poll2(TimeDelta::FromMilliseconds(30)); |
592 scheduler()->OnReceivedLongPollIntervalUpdate(poll1); | 583 scheduler()->OnReceivedLongPollIntervalUpdate(poll1); |
593 EXPECT_CALL(*syncer(), PollSyncShare(_,_)).Times(AtLeast(kMinNumSamples)) | 584 EXPECT_CALL(*syncer(), PollSyncShare(_,_)).Times(AtLeast(kMinNumSamples)) |
594 .WillOnce(DoAll( | 585 .WillOnce(DoAll( |
595 WithArgs<0,1>( | 586 WithArgs<0,1>( |
596 sessions::test_util::SimulatePollIntervalUpdate(poll2)), | 587 sessions::test_util::SimulatePollIntervalUpdate(poll2)), |
597 Return(true))) | 588 Return(true))) |
598 .WillRepeatedly( | 589 .WillRepeatedly( |
599 DoAll(Invoke(sessions::test_util::SimulatePollRetrySuccess), | 590 DoAll(Invoke(sessions::test_util::SimulatePollSuccess), |
600 WithArg<1>( | 591 WithArg<1>( |
601 RecordSyncShareMultiple(×, kMinNumSamples)))); | 592 RecordSyncShareMultiple(×, kMinNumSamples)))); |
602 | 593 |
603 TimeTicks optimal_start = TimeTicks::Now() + poll1 + poll2; | 594 TimeTicks optimal_start = TimeTicks::Now() + poll1 + poll2; |
604 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 595 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
605 | 596 |
606 // Run again to wait for polling. | 597 // Run again to wait for polling. |
607 RunLoop(); | 598 RunLoop(); |
608 | 599 |
609 StopSyncScheduler(); | 600 StopSyncScheduler(); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
680 TimeDelta throttle1(TimeDelta::FromMilliseconds(150)); | 671 TimeDelta throttle1(TimeDelta::FromMilliseconds(150)); |
681 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 672 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
682 | 673 |
683 ::testing::InSequence seq; | 674 ::testing::InSequence seq; |
684 EXPECT_CALL(*syncer(), PollSyncShare(_,_)) | 675 EXPECT_CALL(*syncer(), PollSyncShare(_,_)) |
685 .WillOnce(DoAll( | 676 .WillOnce(DoAll( |
686 WithArg<1>(sessions::test_util::SimulateThrottled(throttle1)), | 677 WithArg<1>(sessions::test_util::SimulateThrottled(throttle1)), |
687 Return(true))) | 678 Return(true))) |
688 .RetiresOnSaturation(); | 679 .RetiresOnSaturation(); |
689 EXPECT_CALL(*syncer(), PollSyncShare(_,_)) | 680 EXPECT_CALL(*syncer(), PollSyncShare(_,_)) |
690 .WillRepeatedly( | 681 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulatePollSuccess), |
691 DoAll(Invoke(sessions::test_util::SimulatePollRetrySuccess), | 682 RecordSyncShareMultiple(×, kMinNumSamples))); |
692 RecordSyncShareMultiple(×, kMinNumSamples))); | |
693 | 683 |
694 TimeTicks optimal_start = TimeTicks::Now() + poll + throttle1; | 684 TimeTicks optimal_start = TimeTicks::Now() + poll + throttle1; |
695 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 685 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
696 | 686 |
697 // Run again to wait for polling. | 687 // Run again to wait for polling. |
698 RunLoop(); | 688 RunLoop(); |
699 | 689 |
700 StopSyncScheduler(); | 690 StopSyncScheduler(); |
701 AnalyzePollRun(times, kMinNumSamples, optimal_start, poll); | 691 AnalyzePollRun(times, kMinNumSamples, optimal_start, poll); |
702 } | 692 } |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1114 RecordSyncShare(×))); | 1104 RecordSyncShare(×))); |
1115 RunLoop(); | 1105 RunLoop(); |
1116 Mock::VerifyAndClearExpectations(syncer()); | 1106 Mock::VerifyAndClearExpectations(syncer()); |
1117 optimal_job_time = optimal_job_time + backoff; | 1107 optimal_job_time = optimal_job_time + backoff; |
1118 ASSERT_EQ(2U, times.size()); | 1108 ASSERT_EQ(2U, times.size()); |
1119 EXPECT_GE(times[1], optimal_job_time); | 1109 EXPECT_GE(times[1], optimal_job_time); |
1120 | 1110 |
1121 // Now let the Poll timer do its thing. | 1111 // Now let the Poll timer do its thing. |
1122 EXPECT_CALL(*syncer(), PollSyncShare(_,_)) | 1112 EXPECT_CALL(*syncer(), PollSyncShare(_,_)) |
1123 .WillRepeatedly(DoAll( | 1113 .WillRepeatedly(DoAll( |
1124 Invoke(sessions::test_util::SimulatePollRetrySuccess), | 1114 Invoke(sessions::test_util::SimulatePollSuccess), |
1125 RecordSyncShareMultiple(×, kMinNumSamples))); | 1115 RecordSyncShareMultiple(×, kMinNumSamples))); |
1126 RunLoop(); | 1116 RunLoop(); |
1127 Mock::VerifyAndClearExpectations(syncer()); | 1117 Mock::VerifyAndClearExpectations(syncer()); |
1128 ASSERT_EQ(kMinNumSamples, times.size()); | 1118 ASSERT_EQ(kMinNumSamples, times.size()); |
1129 for (size_t i = 2; i < times.size(); i++) { | 1119 for (size_t i = 2; i < times.size(); i++) { |
1130 optimal_job_time = optimal_job_time + poll; | 1120 optimal_job_time = optimal_job_time + poll; |
1131 SCOPED_TRACE(testing::Message() << "SyncShare # (" << i << ")"); | 1121 SCOPED_TRACE(testing::Message() << "SyncShare # (" << i << ")"); |
1132 EXPECT_GE(times[i], optimal_job_time); | 1122 EXPECT_GE(times[i], optimal_job_time); |
1133 } | 1123 } |
1134 | 1124 |
1135 StopSyncScheduler(); | 1125 StopSyncScheduler(); |
1136 } | 1126 } |
1137 | 1127 |
1138 // Test that poll failures are ignored. They should have no effect on | 1128 // Test that poll failures are ignored. They should have no effect on |
1139 // subsequent poll attempts, nor should they trigger a backoff/retry. | 1129 // subsequent poll attempts, nor should they trigger a backoff/retry. |
1140 TEST_F(SyncSchedulerTest, TransientPollFailure) { | 1130 TEST_F(SyncSchedulerTest, TransientPollFailure) { |
1141 SyncShareTimes times; | 1131 SyncShareTimes times; |
1142 const TimeDelta poll_interval(TimeDelta::FromMilliseconds(1)); | 1132 const TimeDelta poll_interval(TimeDelta::FromMilliseconds(1)); |
1143 scheduler()->OnReceivedLongPollIntervalUpdate(poll_interval); | 1133 scheduler()->OnReceivedLongPollIntervalUpdate(poll_interval); |
1144 UseMockDelayProvider(); // Will cause test failure if backoff is initiated. | 1134 UseMockDelayProvider(); // Will cause test failure if backoff is initiated. |
1145 | 1135 |
1146 EXPECT_CALL(*syncer(), PollSyncShare(_,_)) | 1136 EXPECT_CALL(*syncer(), PollSyncShare(_,_)) |
1147 .WillOnce(DoAll(Invoke(sessions::test_util::SimulatePollRetryFailed), | 1137 .WillOnce(DoAll(Invoke(sessions::test_util::SimulatePollFailed), |
1148 RecordSyncShare(×))) | 1138 RecordSyncShare(×))) |
1149 .WillOnce(DoAll(Invoke(sessions::test_util::SimulatePollRetrySuccess), | 1139 .WillOnce(DoAll(Invoke(sessions::test_util::SimulatePollSuccess), |
1150 RecordSyncShare(×))); | 1140 RecordSyncShare(×))); |
1151 | 1141 |
1152 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 1142 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
1153 | 1143 |
1154 // Run the unsucessful poll. The failed poll should not trigger backoff. | 1144 // Run the unsucessful poll. The failed poll should not trigger backoff. |
1155 RunLoop(); | 1145 RunLoop(); |
1156 EXPECT_FALSE(scheduler()->IsBackingOff()); | 1146 EXPECT_FALSE(scheduler()->IsBackingOff()); |
1157 | 1147 |
1158 // Run the successful poll. | 1148 // Run the successful poll. |
1159 RunLoop(); | 1149 RunLoop(); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1272 PumpLoop(); // Run the nudge, that will fail and schedule a quick retry. | 1262 PumpLoop(); // Run the nudge, that will fail and schedule a quick retry. |
1273 } | 1263 } |
1274 | 1264 |
1275 TEST_F(SyncSchedulerTest, PollFromCanaryAfterAuthError) { | 1265 TEST_F(SyncSchedulerTest, PollFromCanaryAfterAuthError) { |
1276 SyncShareTimes times; | 1266 SyncShareTimes times; |
1277 TimeDelta poll(TimeDelta::FromMilliseconds(15)); | 1267 TimeDelta poll(TimeDelta::FromMilliseconds(15)); |
1278 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 1268 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
1279 | 1269 |
1280 ::testing::InSequence seq; | 1270 ::testing::InSequence seq; |
1281 EXPECT_CALL(*syncer(), PollSyncShare(_,_)) | 1271 EXPECT_CALL(*syncer(), PollSyncShare(_,_)) |
1282 .WillRepeatedly( | 1272 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulatePollSuccess), |
1283 DoAll(Invoke(sessions::test_util::SimulatePollRetrySuccess), | 1273 RecordSyncShareMultiple(×, kMinNumSamples))); |
1284 RecordSyncShareMultiple(×, kMinNumSamples))); | |
1285 | 1274 |
1286 connection()->SetServerStatus(HttpResponse::SYNC_AUTH_ERROR); | 1275 connection()->SetServerStatus(HttpResponse::SYNC_AUTH_ERROR); |
1287 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 1276 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
1288 | 1277 |
1289 // Run to wait for polling. | 1278 // Run to wait for polling. |
1290 RunLoop(); | 1279 RunLoop(); |
1291 | 1280 |
1292 // Normally OnCredentialsUpdated calls TryCanaryJob that doesn't run Poll, | 1281 // Normally OnCredentialsUpdated calls TryCanaryJob that doesn't run Poll, |
1293 // but after poll finished with auth error from poll timer it should retry | 1282 // but after poll finished with auth error from poll timer it should retry |
1294 // poll once more | 1283 // poll once more |
1295 EXPECT_CALL(*syncer(), PollSyncShare(_,_)) | 1284 EXPECT_CALL(*syncer(), PollSyncShare(_,_)) |
1296 .WillOnce(DoAll(Invoke(sessions::test_util::SimulatePollRetrySuccess), | 1285 .WillOnce(DoAll(Invoke(sessions::test_util::SimulatePollSuccess), |
1297 RecordSyncShare(×))); | 1286 RecordSyncShare(×))); |
1298 scheduler()->OnCredentialsUpdated(); | 1287 scheduler()->OnCredentialsUpdated(); |
1299 connection()->SetServerStatus(HttpResponse::SERVER_CONNECTION_OK); | 1288 connection()->SetServerStatus(HttpResponse::SERVER_CONNECTION_OK); |
1300 RunLoop(); | 1289 RunLoop(); |
1301 StopSyncScheduler(); | 1290 StopSyncScheduler(); |
1302 } | 1291 } |
1303 | 1292 |
1304 TEST_F(SyncSchedulerTest, SuccessfulRetry) { | |
1305 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | |
1306 | |
1307 SyncShareTimes times; | |
1308 base::TimeDelta delay = base::TimeDelta::FromMilliseconds(1); | |
1309 scheduler()->OnReceivedGuRetryDelay(delay); | |
1310 EXPECT_EQ(delay, GetRetryTimerDelay()); | |
1311 | |
1312 EXPECT_CALL(*syncer(), RetrySyncShare(_,_)) | |
1313 .WillOnce( | |
1314 DoAll(Invoke(sessions::test_util::SimulatePollRetrySuccess), | |
1315 RecordSyncShare(×))); | |
1316 | |
1317 // Run to wait for retrying. | |
1318 RunLoop(); | |
1319 | |
1320 StopSyncScheduler(); | |
1321 } | |
1322 | |
1323 TEST_F(SyncSchedulerTest, FailedRetry) { | |
1324 UseMockDelayProvider(); | |
1325 EXPECT_CALL(*delay(), GetDelay(_)) | |
1326 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(1))); | |
1327 | |
1328 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | |
1329 | |
1330 base::TimeDelta delay = base::TimeDelta::FromMilliseconds(1); | |
1331 scheduler()->OnReceivedGuRetryDelay(delay); | |
1332 | |
1333 EXPECT_CALL(*syncer(), RetrySyncShare(_,_)) | |
1334 .WillOnce( | |
1335 DoAll(Invoke(sessions::test_util::SimulatePollRetryFailed), | |
1336 QuitLoopNowAction())); | |
1337 | |
1338 // Run to wait for retrying. | |
1339 RunLoop(); | |
1340 | |
1341 EXPECT_TRUE(scheduler()->IsBackingOff()); | |
1342 EXPECT_CALL(*syncer(), RetrySyncShare(_,_)) | |
1343 .WillOnce( | |
1344 DoAll(Invoke(sessions::test_util::SimulatePollRetrySuccess), | |
1345 QuitLoopNowAction())); | |
1346 | |
1347 // Run to wait for second retrying. | |
1348 RunLoop(); | |
1349 | |
1350 StopSyncScheduler(); | |
1351 } | |
1352 | |
1353 ACTION_P2(VerifyRetryTimerDelay, scheduler_test, expected_delay) { | |
1354 EXPECT_EQ(expected_delay, scheduler_test->GetRetryTimerDelay()); | |
1355 } | |
1356 | |
1357 TEST_F(SyncSchedulerTest, ReceiveNewRetryDelay) { | |
1358 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | |
1359 | |
1360 SyncShareTimes times; | |
1361 base::TimeDelta delay1 = base::TimeDelta::FromMilliseconds(10); | |
1362 base::TimeDelta delay2 = base::TimeDelta::FromMilliseconds(20); | |
1363 | |
1364 scheduler()->OnReceivedGuRetryDelay(delay1); | |
1365 scheduler()->ScheduleLocalRefreshRequest(zero(), ModelTypeSet(BOOKMARKS), | |
1366 FROM_HERE); | |
1367 | |
1368 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | |
1369 .WillOnce(DoAll( | |
1370 WithoutArgs(VerifyRetryTimerDelay(this, delay1)), | |
1371 WithArg<2>(sessions::test_util::SimulateGuRetryDelayCommand(delay2)), | |
1372 WithoutArgs(VerifyRetryTimerDelay(this, delay2)), | |
1373 RecordSyncShare(×))); | |
1374 | |
1375 // Run nudge GU. | |
1376 RunLoop(); | |
1377 | |
1378 EXPECT_CALL(*syncer(), RetrySyncShare(_,_)) | |
1379 .WillOnce( | |
1380 DoAll(Invoke(sessions::test_util::SimulatePollRetrySuccess), | |
1381 RecordSyncShare(×))); | |
1382 | |
1383 // Run to wait for retrying. | |
1384 RunLoop(); | |
1385 | |
1386 StopSyncScheduler(); | |
1387 } | |
1388 | |
1389 } // namespace syncer | 1293 } // namespace syncer |
OLD | NEW |