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