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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
120 MOCK_METHOD1(GetDelay, TimeDelta(const TimeDelta&)); | 120 MOCK_METHOD1(GetDelay, TimeDelta(const TimeDelta&)); |
121 }; | 121 }; |
122 | 122 |
123 virtual void SetUp() { | 123 virtual void SetUp() { |
124 dir_maker_.SetUp(); | 124 dir_maker_.SetUp(); |
125 syncer_ = new testing::StrictMock<MockSyncer>(); | 125 syncer_ = new testing::StrictMock<MockSyncer>(); |
126 delay_ = NULL; | 126 delay_ = NULL; |
127 extensions_activity_ = new ExtensionsActivity(); | 127 extensions_activity_ = new ExtensionsActivity(); |
128 | 128 |
129 routing_info_[BOOKMARKS] = GROUP_UI; | 129 routing_info_[BOOKMARKS] = GROUP_UI; |
130 routing_info_[AUTOFILL] = GROUP_DB; | 130 routing_info_[TYPED_URLS] = GROUP_DB; |
131 routing_info_[THEMES] = GROUP_UI; | 131 routing_info_[THEMES] = GROUP_UI; |
132 routing_info_[NIGORI] = GROUP_PASSIVE; | 132 routing_info_[NIGORI] = GROUP_PASSIVE; |
133 | 133 |
134 workers_.clear(); | 134 workers_.clear(); |
135 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_UI))); | 135 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_UI))); |
136 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_DB))); | 136 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_DB))); |
137 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_PASSIVE))); | 137 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_PASSIVE))); |
138 | 138 |
139 connection_.reset(new MockConnectionManager(directory(), | 139 connection_.reset(new MockConnectionManager(directory(), |
140 &cancelation_signal_)); | 140 &cancelation_signal_)); |
(...skipping 11 matching lines...) Expand all Loading... | |
152 false, // force enable pre-commit GU avoidance | 152 false, // force enable pre-commit GU avoidance |
153 "fake_invalidator_client_id")); | 153 "fake_invalidator_client_id")); |
154 context_->SetRoutingInfo(routing_info_); | 154 context_->SetRoutingInfo(routing_info_); |
155 context_->set_notifications_enabled(true); | 155 context_->set_notifications_enabled(true); |
156 context_->set_account_name("Test"); | 156 context_->set_account_name("Test"); |
157 scheduler_.reset( | 157 scheduler_.reset( |
158 new SyncSchedulerImpl("TestSyncScheduler", | 158 new SyncSchedulerImpl("TestSyncScheduler", |
159 BackoffDelayProvider::FromDefaults(), | 159 BackoffDelayProvider::FromDefaults(), |
160 context(), | 160 context(), |
161 syncer_)); | 161 syncer_)); |
162 scheduler_->SetDefaultNudgeDelay(default_delay().InMilliseconds()); | |
163 std::map<ModelType, int> delay_map; | |
164 // Override the bookmarks value since so many tests rely on it. | |
165 delay_map[BOOKMARKS] = default_delay().InMilliseconds(); | |
166 scheduler_->OnReceivedCustomNudgeDelays(delay_map); | |
162 } | 167 } |
163 | 168 |
164 SyncSchedulerImpl* scheduler() { return scheduler_.get(); } | 169 SyncSchedulerImpl* scheduler() { return scheduler_.get(); } |
165 const ModelSafeRoutingInfo& routing_info() { return routing_info_; } | 170 const ModelSafeRoutingInfo& routing_info() { return routing_info_; } |
166 MockSyncer* syncer() { return syncer_; } | 171 MockSyncer* syncer() { return syncer_; } |
167 MockDelayProvider* delay() { return delay_; } | 172 MockDelayProvider* delay() { return delay_; } |
168 MockConnectionManager* connection() { return connection_.get(); } | 173 MockConnectionManager* connection() { return connection_.get(); } |
169 TimeDelta zero() { return TimeDelta::FromSeconds(0); } | 174 TimeDelta default_delay() { return TimeDelta::FromSeconds(0); } |
170 TimeDelta timeout() { | 175 TimeDelta timeout() { |
171 return TestTimeouts::action_timeout(); | 176 return TestTimeouts::action_timeout(); |
172 } | 177 } |
173 | 178 |
174 virtual void TearDown() { | 179 virtual void TearDown() { |
175 PumpLoop(); | 180 PumpLoop(); |
176 scheduler_.reset(); | 181 scheduler_.reset(); |
177 PumpLoop(); | 182 PumpLoop(); |
178 dir_maker_.TearDown(); | 183 dir_maker_.TearDown(); |
179 } | 184 } |
(...skipping 22 matching lines...) Expand all Loading... | |
202 FROM_HERE, | 207 FROM_HERE, |
203 base::Bind(&SyncSchedulerTest::DoQuitLoopNow, | 208 base::Bind(&SyncSchedulerTest::DoQuitLoopNow, |
204 weak_ptr_factory_.GetWeakPtr())); | 209 weak_ptr_factory_.GetWeakPtr())); |
205 RunLoop(); | 210 RunLoop(); |
206 } | 211 } |
207 | 212 |
208 bool RunAndGetBackoff() { | 213 bool RunAndGetBackoff() { |
209 ModelTypeSet nudge_types(BOOKMARKS); | 214 ModelTypeSet nudge_types(BOOKMARKS); |
210 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 215 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
211 | 216 |
212 scheduler()->ScheduleLocalNudge(zero(), nudge_types, FROM_HERE); | 217 scheduler()->ScheduleLocalNudge(nudge_types, FROM_HERE); |
213 RunLoop(); | 218 RunLoop(); |
214 | 219 |
215 return scheduler()->IsBackingOff(); | 220 return scheduler()->IsBackingOff(); |
216 } | 221 } |
217 | 222 |
218 void UseMockDelayProvider() { | 223 void UseMockDelayProvider() { |
219 delay_ = new MockDelayProvider(); | 224 delay_ = new MockDelayProvider(); |
220 scheduler_->delay_provider_.reset(delay_); | 225 scheduler_->delay_provider_.reset(delay_); |
221 } | 226 } |
222 | 227 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
300 SyncShareTimes times; | 305 SyncShareTimes times; |
301 ModelTypeSet model_types(BOOKMARKS); | 306 ModelTypeSet model_types(BOOKMARKS); |
302 | 307 |
303 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 308 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
304 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 309 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), |
305 RecordSyncShare(×))) | 310 RecordSyncShare(×))) |
306 .RetiresOnSaturation(); | 311 .RetiresOnSaturation(); |
307 | 312 |
308 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 313 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
309 | 314 |
310 scheduler()->ScheduleLocalNudge(zero(), model_types, FROM_HERE); | 315 scheduler()->ScheduleLocalNudge(model_types, FROM_HERE); |
311 RunLoop(); | 316 RunLoop(); |
312 | 317 |
313 Mock::VerifyAndClearExpectations(syncer()); | 318 Mock::VerifyAndClearExpectations(syncer()); |
314 | 319 |
315 // Make sure a second, later, nudge is unaffected by first (no coalescing). | 320 // Make sure a second, later, nudge is unaffected by first (no coalescing). |
316 SyncShareTimes times2; | 321 SyncShareTimes times2; |
317 model_types.Remove(BOOKMARKS); | 322 model_types.Remove(BOOKMARKS); |
318 model_types.Put(AUTOFILL); | 323 model_types.Put(TYPED_URLS); |
319 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 324 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
320 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 325 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), |
321 RecordSyncShare(×2))); | 326 RecordSyncShare(×2))); |
322 scheduler()->ScheduleLocalNudge(zero(), model_types, FROM_HERE); | 327 scheduler()->ScheduleLocalNudge(model_types, FROM_HERE); |
323 RunLoop(); | 328 RunLoop(); |
324 } | 329 } |
325 | 330 |
326 // Make sure a regular config command is scheduled fine in the absence of any | 331 // Make sure a regular config command is scheduled fine in the absence of any |
327 // errors. | 332 // errors. |
328 TEST_F(SyncSchedulerTest, Config) { | 333 TEST_F(SyncSchedulerTest, Config) { |
329 SyncShareTimes times; | 334 SyncShareTimes times; |
330 const ModelTypeSet model_types(BOOKMARKS); | 335 const ModelTypeSet model_types(BOOKMARKS); |
331 | 336 |
332 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) | 337 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
452 scheduler()->ScheduleConfiguration(params); | 457 scheduler()->ScheduleConfiguration(params); |
453 RunLoop(); | 458 RunLoop(); |
454 ASSERT_EQ(0, ready_counter.times_called()); | 459 ASSERT_EQ(0, ready_counter.times_called()); |
455 ASSERT_EQ(1, retry_counter.times_called()); | 460 ASSERT_EQ(1, retry_counter.times_called()); |
456 Mock::VerifyAndClearExpectations(syncer()); | 461 Mock::VerifyAndClearExpectations(syncer()); |
457 | 462 |
458 // Ask for a nudge while dealing with repeated configure failure. | 463 // Ask for a nudge while dealing with repeated configure failure. |
459 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) | 464 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) |
460 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureFailed), | 465 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureFailed), |
461 RecordSyncShare(×))); | 466 RecordSyncShare(×))); |
462 scheduler()->ScheduleLocalNudge(zero(), model_types, FROM_HERE); | 467 scheduler()->ScheduleLocalNudge(model_types, FROM_HERE); |
463 RunLoop(); | 468 RunLoop(); |
464 // Note that we're not RunLoop()ing for the NUDGE we just scheduled, but | 469 // Note that we're not RunLoop()ing for the NUDGE we just scheduled, but |
465 // for the first retry attempt from the config job (after | 470 // for the first retry attempt from the config job (after |
466 // waiting ~+/- 50ms). | 471 // waiting ~+/- 50ms). |
467 Mock::VerifyAndClearExpectations(syncer()); | 472 Mock::VerifyAndClearExpectations(syncer()); |
468 ASSERT_EQ(0, ready_counter.times_called()); | 473 ASSERT_EQ(0, ready_counter.times_called()); |
469 | 474 |
470 // Let the next configure retry succeed. | 475 // Let the next configure retry succeed. |
471 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) | 476 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) |
472 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess), | 477 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess), |
473 RecordSyncShare(×))); | 478 RecordSyncShare(×))); |
474 RunLoop(); | 479 RunLoop(); |
475 | 480 |
476 // Now change the mode so nudge can execute. | 481 // Now change the mode so nudge can execute. |
477 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 482 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
478 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 483 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), |
479 RecordSyncShare(×))); | 484 RecordSyncShare(×))); |
480 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 485 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
481 PumpLoop(); | 486 PumpLoop(); |
482 } | 487 } |
483 | 488 |
484 // Test that nudges are coalesced. | 489 // Test that nudges are coalesced. |
485 TEST_F(SyncSchedulerTest, NudgeCoalescing) { | 490 TEST_F(SyncSchedulerTest, NudgeCoalescing) { |
486 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 491 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
487 | 492 |
488 SyncShareTimes times; | 493 SyncShareTimes times; |
489 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 494 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
490 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 495 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), |
491 RecordSyncShare(×))); | 496 RecordSyncShare(×))); |
492 const ModelTypeSet types1(BOOKMARKS), types2(AUTOFILL), types3(THEMES); | 497 const ModelTypeSet types1(BOOKMARKS), types2(TYPED_URLS), types3(THEMES); |
493 TimeDelta delay = zero(); | 498 TimeDelta delay = default_delay(); |
rlarocque
2014/08/20 00:13:31
Remove |delay|?
Nicolas Zea
2014/08/20 22:49:43
Done.
| |
494 TimeTicks optimal_time = TimeTicks::Now() + delay; | 499 TimeTicks optimal_time = TimeTicks::Now() + delay; |
495 scheduler()->ScheduleLocalNudge(delay, types1, FROM_HERE); | 500 scheduler()->ScheduleLocalNudge(types1, FROM_HERE); |
496 scheduler()->ScheduleLocalNudge(zero(), types2, FROM_HERE); | 501 scheduler()->ScheduleLocalNudge(types2, FROM_HERE); |
497 RunLoop(); | 502 RunLoop(); |
498 | 503 |
499 ASSERT_EQ(1U, times.size()); | 504 ASSERT_EQ(1U, times.size()); |
500 EXPECT_GE(times[0], optimal_time); | 505 EXPECT_GE(times[0], optimal_time); |
501 | 506 |
502 Mock::VerifyAndClearExpectations(syncer()); | 507 Mock::VerifyAndClearExpectations(syncer()); |
503 | 508 |
504 SyncShareTimes times2; | 509 SyncShareTimes times2; |
505 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 510 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
506 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 511 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), |
507 RecordSyncShare(×2))); | 512 RecordSyncShare(×2))); |
508 scheduler()->ScheduleLocalNudge(zero(), types3, FROM_HERE); | 513 scheduler()->ScheduleLocalNudge(types3, FROM_HERE); |
509 RunLoop(); | 514 RunLoop(); |
510 } | 515 } |
511 | 516 |
512 // Test that nudges are coalesced. | 517 // Test that nudges are coalesced. |
513 TEST_F(SyncSchedulerTest, NudgeCoalescingWithDifferentTimings) { | 518 TEST_F(SyncSchedulerTest, NudgeCoalescingWithDifferentTimings) { |
514 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 519 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
515 | 520 |
516 SyncShareTimes times; | 521 SyncShareTimes times; |
517 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 522 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
518 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 523 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), |
519 RecordSyncShare(×))); | 524 RecordSyncShare(×))); |
520 ModelTypeSet types1(BOOKMARKS), types2(AUTOFILL), types3; | 525 ModelTypeSet types1(BOOKMARKS), types2(TYPED_URLS), types3; |
521 | 526 |
522 // Create a huge time delay. | 527 // Create a huge time delay. |
523 TimeDelta delay = TimeDelta::FromDays(1); | 528 TimeDelta delay = TimeDelta::FromDays(1); |
524 | 529 |
525 scheduler()->ScheduleLocalNudge(delay, types1, FROM_HERE); | 530 std::map<ModelType, int> delay_map; |
526 scheduler()->ScheduleLocalNudge(zero(), types2, FROM_HERE); | 531 delay_map[types1.First().Get()] = delay.InMilliseconds(); |
532 scheduler()->OnReceivedCustomNudgeDelays(delay_map); | |
533 scheduler()->ScheduleLocalNudge(types1, FROM_HERE); | |
534 scheduler()->ScheduleLocalNudge(types2, FROM_HERE); | |
527 | 535 |
528 TimeTicks min_time = TimeTicks::Now(); | 536 TimeTicks min_time = TimeTicks::Now(); |
529 TimeTicks max_time = TimeTicks::Now() + delay; | 537 TimeTicks max_time = TimeTicks::Now() + delay; |
530 | 538 |
531 RunLoop(); | 539 RunLoop(); |
532 Mock::VerifyAndClearExpectations(syncer()); | 540 Mock::VerifyAndClearExpectations(syncer()); |
533 | 541 |
534 // Make sure the sync happened at the right time. | 542 // Make sure the sync happened at the right time. |
535 ASSERT_EQ(1U, times.size()); | 543 ASSERT_EQ(1U, times.size()); |
536 EXPECT_GE(times[0], min_time); | 544 EXPECT_GE(times[0], min_time); |
537 EXPECT_LE(times[0], max_time); | 545 EXPECT_LE(times[0], max_time); |
538 } | 546 } |
539 | 547 |
540 // Test nudge scheduling. | 548 // Test nudge scheduling. |
541 TEST_F(SyncSchedulerTest, NudgeWithStates) { | 549 TEST_F(SyncSchedulerTest, NudgeWithStates) { |
542 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 550 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
543 | 551 |
544 SyncShareTimes times1; | 552 SyncShareTimes times1; |
545 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 553 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
546 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 554 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), |
547 RecordSyncShare(×1))) | 555 RecordSyncShare(×1))) |
548 .RetiresOnSaturation(); | 556 .RetiresOnSaturation(); |
549 scheduler()->ScheduleInvalidationNudge( | 557 scheduler()->ScheduleInvalidationNudge( |
550 zero(), BOOKMARKS, BuildInvalidation(10, "test"), FROM_HERE); | 558 BOOKMARKS, BuildInvalidation(10, "test"), FROM_HERE); |
551 RunLoop(); | 559 RunLoop(); |
552 | 560 |
553 Mock::VerifyAndClearExpectations(syncer()); | 561 Mock::VerifyAndClearExpectations(syncer()); |
554 | 562 |
555 // Make sure a second, later, nudge is unaffected by first (no coalescing). | 563 // Make sure a second, later, nudge is unaffected by first (no coalescing). |
556 SyncShareTimes times2; | 564 SyncShareTimes times2; |
557 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 565 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
558 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 566 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), |
559 RecordSyncShare(×2))); | 567 RecordSyncShare(×2))); |
560 scheduler()->ScheduleInvalidationNudge( | 568 scheduler()->ScheduleInvalidationNudge( |
561 zero(), AUTOFILL, BuildInvalidation(10, "test2"), FROM_HERE); | 569 TYPED_URLS, BuildInvalidation(10, "test2"), FROM_HERE); |
562 RunLoop(); | 570 RunLoop(); |
563 } | 571 } |
564 | 572 |
565 // Test that polling works as expected. | 573 // Test that polling works as expected. |
566 TEST_F(SyncSchedulerTest, Polling) { | 574 TEST_F(SyncSchedulerTest, Polling) { |
567 SyncShareTimes times; | 575 SyncShareTimes times; |
568 TimeDelta poll_interval(TimeDelta::FromMilliseconds(30)); | 576 TimeDelta poll_interval(TimeDelta::FromMilliseconds(30)); |
569 EXPECT_CALL(*syncer(), PollSyncShare(_,_)).Times(AtLeast(kMinNumSamples)) | 577 EXPECT_CALL(*syncer(), PollSyncShare(_,_)).Times(AtLeast(kMinNumSamples)) |
570 .WillRepeatedly( | 578 .WillRepeatedly( |
571 DoAll(Invoke(sessions::test_util::SimulatePollSuccess), | 579 DoAll(Invoke(sessions::test_util::SimulatePollSuccess), |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
625 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 633 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
626 | 634 |
627 // Run again to wait for polling. | 635 // Run again to wait for polling. |
628 RunLoop(); | 636 RunLoop(); |
629 | 637 |
630 StopSyncScheduler(); | 638 StopSyncScheduler(); |
631 AnalyzePollRun(times, kMinNumSamples, optimal_start, poll2); | 639 AnalyzePollRun(times, kMinNumSamples, optimal_start, poll2); |
632 } | 640 } |
633 | 641 |
634 // Test that the sessions commit delay is updated when needed. | 642 // Test that the sessions commit delay is updated when needed. |
635 TEST_F(SyncSchedulerTest, SessionsCommitDelay) { | 643 TEST_F(SyncSchedulerTest, CustomNudgeDelays) { |
636 SyncShareTimes times; | 644 SyncShareTimes times; |
637 TimeDelta delay1(TimeDelta::FromMilliseconds(120)); | 645 TimeDelta delay1(TimeDelta::FromMilliseconds(120)); |
638 TimeDelta delay2(TimeDelta::FromMilliseconds(30)); | 646 TimeDelta delay2(TimeDelta::FromMilliseconds(30)); |
639 scheduler()->OnReceivedSessionsCommitDelay(delay1); | 647 std::map<ModelType, int> delay_map; |
648 delay_map[SESSIONS] = delay1.InMilliseconds(); | |
649 scheduler()->OnReceivedCustomNudgeDelays(delay_map); | |
640 | 650 |
641 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 651 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
642 .WillOnce( | 652 .WillOnce( |
643 DoAll( | 653 DoAll( |
644 WithArgs<0,1,2>( | 654 WithArgs<0,1,2>( |
645 sessions::test_util::SimulateSessionsCommitDelayUpdate( | 655 sessions::test_util::SimulateSessionsCommitDelayUpdate( |
646 delay2)), | 656 delay2)), |
647 Invoke(sessions::test_util::SimulateNormalSuccess), | 657 Invoke(sessions::test_util::SimulateNormalSuccess), |
648 QuitLoopNowAction())); | 658 QuitLoopNowAction())); |
649 | 659 |
650 EXPECT_EQ(delay1, scheduler()->GetSessionsCommitDelay()); | 660 EXPECT_EQ(delay1, scheduler()->GetNudgeDelayForTypes(ModelTypeSet(SESSIONS))); |
651 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 661 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
652 | 662 |
653 EXPECT_EQ(delay1, scheduler()->GetSessionsCommitDelay()); | 663 EXPECT_EQ(delay1, scheduler()->GetNudgeDelayForTypes(ModelTypeSet(SESSIONS))); |
654 const ModelTypeSet model_types(BOOKMARKS); | 664 const ModelTypeSet model_types(BOOKMARKS); |
655 scheduler()->ScheduleLocalNudge(zero(), model_types, FROM_HERE); | 665 scheduler()->ScheduleLocalNudge(model_types, FROM_HERE); |
656 RunLoop(); | 666 RunLoop(); |
657 | 667 |
658 EXPECT_EQ(delay2, scheduler()->GetSessionsCommitDelay()); | 668 EXPECT_EQ(delay2, scheduler()->GetNudgeDelayForTypes(ModelTypeSet(SESSIONS))); |
659 StopSyncScheduler(); | 669 StopSyncScheduler(); |
660 } | 670 } |
661 | 671 |
662 // Test that no syncing occurs when throttled. | 672 // Test that no syncing occurs when throttled. |
663 TEST_F(SyncSchedulerTest, ThrottlingDoesThrottle) { | 673 TEST_F(SyncSchedulerTest, ThrottlingDoesThrottle) { |
664 const ModelTypeSet types(BOOKMARKS); | 674 const ModelTypeSet types(BOOKMARKS); |
665 TimeDelta poll(TimeDelta::FromMilliseconds(20)); | 675 TimeDelta poll(TimeDelta::FromMilliseconds(20)); |
666 TimeDelta throttle(TimeDelta::FromMinutes(10)); | 676 TimeDelta throttle(TimeDelta::FromMinutes(10)); |
667 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 677 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
668 | 678 |
669 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) | 679 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) |
670 .WillOnce(DoAll( | 680 .WillOnce(DoAll( |
671 WithArg<2>(sessions::test_util::SimulateThrottled(throttle)), | 681 WithArg<2>(sessions::test_util::SimulateThrottled(throttle)), |
672 Return(true))) | 682 Return(true))) |
673 .WillRepeatedly(AddFailureAndQuitLoopNow()); | 683 .WillRepeatedly(AddFailureAndQuitLoopNow()); |
674 | 684 |
675 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 685 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
676 | 686 |
677 scheduler()->ScheduleLocalNudge( | 687 scheduler()->ScheduleLocalNudge(types, FROM_HERE); |
678 TimeDelta::FromMicroseconds(1), types, FROM_HERE); | |
679 PumpLoop(); | 688 PumpLoop(); |
680 | 689 |
681 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 690 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
682 | 691 |
683 CallbackCounter ready_counter; | 692 CallbackCounter ready_counter; |
684 CallbackCounter retry_counter; | 693 CallbackCounter retry_counter; |
685 ConfigurationParams params( | 694 ConfigurationParams params( |
686 GetUpdatesCallerInfo::RECONFIGURATION, | 695 GetUpdatesCallerInfo::RECONFIGURATION, |
687 types, | 696 types, |
688 TypesToRoutingInfo(types), | 697 TypesToRoutingInfo(types), |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
733 .WillOnce(DoAll( | 742 .WillOnce(DoAll( |
734 WithArg<2>(sessions::test_util::SimulateThrottled(throttle1)), | 743 WithArg<2>(sessions::test_util::SimulateThrottled(throttle1)), |
735 Return(true))) | 744 Return(true))) |
736 .RetiresOnSaturation(); | 745 .RetiresOnSaturation(); |
737 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 746 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
738 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 747 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), |
739 QuitLoopNowAction())); | 748 QuitLoopNowAction())); |
740 | 749 |
741 const ModelTypeSet types(BOOKMARKS); | 750 const ModelTypeSet types(BOOKMARKS); |
742 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 751 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
743 scheduler()->ScheduleLocalNudge(zero(), types, FROM_HERE); | 752 scheduler()->ScheduleLocalNudge(types, FROM_HERE); |
744 | 753 |
745 PumpLoop(); // To get PerformDelayedNudge called. | 754 PumpLoop(); // To get PerformDelayedNudge called. |
746 PumpLoop(); // To get TrySyncSessionJob called | 755 PumpLoop(); // To get TrySyncSessionJob called |
747 EXPECT_TRUE(scheduler()->IsCurrentlyThrottled()); | 756 EXPECT_TRUE(scheduler()->IsCurrentlyThrottled()); |
748 RunLoop(); | 757 RunLoop(); |
749 EXPECT_FALSE(scheduler()->IsCurrentlyThrottled()); | 758 EXPECT_FALSE(scheduler()->IsCurrentlyThrottled()); |
750 | 759 |
751 StopSyncScheduler(); | 760 StopSyncScheduler(); |
752 } | 761 } |
753 | 762 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
786 | 795 |
787 RunLoop(); | 796 RunLoop(); |
788 EXPECT_FALSE(scheduler()->IsCurrentlyThrottled()); | 797 EXPECT_FALSE(scheduler()->IsCurrentlyThrottled()); |
789 | 798 |
790 StopSyncScheduler(); | 799 StopSyncScheduler(); |
791 } | 800 } |
792 | 801 |
793 TEST_F(SyncSchedulerTest, TypeThrottlingBlocksNudge) { | 802 TEST_F(SyncSchedulerTest, TypeThrottlingBlocksNudge) { |
794 UseMockDelayProvider(); | 803 UseMockDelayProvider(); |
795 EXPECT_CALL(*delay(), GetDelay(_)) | 804 EXPECT_CALL(*delay(), GetDelay(_)) |
796 .WillRepeatedly(Return(zero())); | 805 .WillRepeatedly(Return(default_delay())); |
797 | 806 |
798 TimeDelta poll(TimeDelta::FromDays(1)); | 807 TimeDelta poll(TimeDelta::FromDays(1)); |
799 TimeDelta throttle1(TimeDelta::FromSeconds(60)); | 808 TimeDelta throttle1(TimeDelta::FromSeconds(60)); |
800 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 809 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
801 | 810 |
802 const ModelTypeSet types(BOOKMARKS); | 811 const ModelTypeSet types(BOOKMARKS); |
803 | 812 |
804 ::testing::InSequence seq; | 813 ::testing::InSequence seq; |
805 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 814 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
806 .WillOnce(DoAll( | 815 .WillOnce(DoAll( |
807 WithArg<2>( | 816 WithArg<2>( |
808 sessions::test_util::SimulateTypesThrottled(types, throttle1)), | 817 sessions::test_util::SimulateTypesThrottled(types, throttle1)), |
809 Return(true))) | 818 Return(true))) |
810 .RetiresOnSaturation(); | 819 .RetiresOnSaturation(); |
811 | 820 |
812 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 821 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
813 scheduler()->ScheduleLocalNudge(zero(), types, FROM_HERE); | 822 scheduler()->ScheduleLocalNudge(types, FROM_HERE); |
814 PumpLoop(); // To get PerformDelayedNudge called. | 823 PumpLoop(); // To get PerformDelayedNudge called. |
815 PumpLoop(); // To get TrySyncSessionJob called | 824 PumpLoop(); // To get TrySyncSessionJob called |
816 EXPECT_TRUE(GetThrottledTypes().HasAll(types)); | 825 EXPECT_TRUE(GetThrottledTypes().HasAll(types)); |
817 | 826 |
818 // This won't cause a sync cycle because the types are throttled. | 827 // This won't cause a sync cycle because the types are throttled. |
819 scheduler()->ScheduleLocalNudge(zero(), types, FROM_HERE); | 828 scheduler()->ScheduleLocalNudge(types, FROM_HERE); |
820 PumpLoop(); | 829 PumpLoop(); |
821 | 830 |
822 StopSyncScheduler(); | 831 StopSyncScheduler(); |
823 } | 832 } |
824 | 833 |
825 TEST_F(SyncSchedulerTest, TypeThrottlingDoesBlockOtherSources) { | 834 TEST_F(SyncSchedulerTest, TypeThrottlingDoesBlockOtherSources) { |
826 UseMockDelayProvider(); | 835 UseMockDelayProvider(); |
827 EXPECT_CALL(*delay(), GetDelay(_)) | 836 EXPECT_CALL(*delay(), GetDelay(_)) |
828 .WillRepeatedly(Return(zero())); | 837 .WillRepeatedly(Return(default_delay())); |
829 | 838 |
830 SyncShareTimes times; | 839 SyncShareTimes times; |
831 TimeDelta poll(TimeDelta::FromDays(1)); | 840 TimeDelta poll(TimeDelta::FromDays(1)); |
832 TimeDelta throttle1(TimeDelta::FromSeconds(60)); | 841 TimeDelta throttle1(TimeDelta::FromSeconds(60)); |
833 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 842 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
834 | 843 |
835 const ModelTypeSet throttled_types(BOOKMARKS); | 844 const ModelTypeSet throttled_types(BOOKMARKS); |
836 const ModelTypeSet unthrottled_types(PREFERENCES); | 845 const ModelTypeSet unthrottled_types(PREFERENCES); |
837 | 846 |
838 ::testing::InSequence seq; | 847 ::testing::InSequence seq; |
839 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 848 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
840 .WillOnce(DoAll( | 849 .WillOnce(DoAll( |
841 WithArg<2>( | 850 WithArg<2>( |
842 sessions::test_util::SimulateTypesThrottled( | 851 sessions::test_util::SimulateTypesThrottled( |
843 throttled_types, throttle1)), | 852 throttled_types, throttle1)), |
844 Return(true))) | 853 Return(true))) |
845 .RetiresOnSaturation(); | 854 .RetiresOnSaturation(); |
846 | 855 |
847 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 856 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
848 scheduler()->ScheduleLocalNudge(zero(), throttled_types, FROM_HERE); | 857 scheduler()->ScheduleLocalNudge(throttled_types, FROM_HERE); |
849 PumpLoop(); // To get PerformDelayedNudge called. | 858 PumpLoop(); // To get PerformDelayedNudge called. |
850 PumpLoop(); // To get TrySyncSessionJob called | 859 PumpLoop(); // To get TrySyncSessionJob called |
851 EXPECT_TRUE(GetThrottledTypes().HasAll(throttled_types)); | 860 EXPECT_TRUE(GetThrottledTypes().HasAll(throttled_types)); |
852 | 861 |
853 // Ignore invalidations for throttled types. | 862 // Ignore invalidations for throttled types. |
854 scheduler()->ScheduleInvalidationNudge( | 863 scheduler()->ScheduleInvalidationNudge( |
855 zero(), BOOKMARKS, BuildInvalidation(10, "test"), FROM_HERE); | 864 BOOKMARKS, BuildInvalidation(10, "test"), FROM_HERE); |
856 PumpLoop(); | 865 PumpLoop(); |
857 | 866 |
858 // Ignore refresh requests for throttled types. | 867 // Ignore refresh requests for throttled types. |
859 scheduler()->ScheduleLocalRefreshRequest(zero(), throttled_types, FROM_HERE); | 868 scheduler()->ScheduleLocalRefreshRequest(throttled_types, FROM_HERE); |
860 PumpLoop(); | 869 PumpLoop(); |
861 | 870 |
862 Mock::VerifyAndClearExpectations(syncer()); | 871 Mock::VerifyAndClearExpectations(syncer()); |
863 | 872 |
864 // Local nudges for non-throttled types will trigger a sync. | 873 // Local nudges for non-throttled types will trigger a sync. |
865 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 874 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
866 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 875 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), |
867 RecordSyncShare(×))); | 876 RecordSyncShare(×))); |
868 scheduler()->ScheduleLocalNudge(zero(), unthrottled_types, FROM_HERE); | 877 scheduler()->ScheduleLocalNudge(unthrottled_types, FROM_HERE); |
869 RunLoop(); | 878 RunLoop(); |
870 Mock::VerifyAndClearExpectations(syncer()); | 879 Mock::VerifyAndClearExpectations(syncer()); |
871 | 880 |
872 StopSyncScheduler(); | 881 StopSyncScheduler(); |
873 } | 882 } |
874 | 883 |
875 // Test nudges / polls don't run in config mode and config tasks do. | 884 // Test nudges / polls don't run in config mode and config tasks do. |
876 TEST_F(SyncSchedulerTest, ConfigurationMode) { | 885 TEST_F(SyncSchedulerTest, ConfigurationMode) { |
877 TimeDelta poll(TimeDelta::FromMilliseconds(15)); | 886 TimeDelta poll(TimeDelta::FromMilliseconds(15)); |
878 SyncShareTimes times; | 887 SyncShareTimes times; |
879 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 888 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
880 | 889 |
881 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 890 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
882 | 891 |
883 const ModelTypeSet nudge_types(AUTOFILL); | 892 const ModelTypeSet nudge_types(TYPED_URLS); |
884 scheduler()->ScheduleLocalNudge(zero(), nudge_types, FROM_HERE); | 893 scheduler()->ScheduleLocalNudge(nudge_types, FROM_HERE); |
885 scheduler()->ScheduleLocalNudge(zero(), nudge_types, FROM_HERE); | 894 scheduler()->ScheduleLocalNudge(nudge_types, FROM_HERE); |
886 | 895 |
887 const ModelTypeSet config_types(BOOKMARKS); | 896 const ModelTypeSet config_types(BOOKMARKS); |
888 | 897 |
889 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) | 898 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) |
890 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess), | 899 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess), |
891 RecordSyncShare(×))) | 900 RecordSyncShare(×))) |
892 .RetiresOnSaturation(); | 901 .RetiresOnSaturation(); |
893 CallbackCounter ready_counter; | 902 CallbackCounter ready_counter; |
894 CallbackCounter retry_counter; | 903 CallbackCounter retry_counter; |
895 ConfigurationParams params( | 904 ConfigurationParams params( |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1019 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 1028 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
1020 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), | 1029 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), |
1021 RecordSyncShareMultiple(×, 1U))); | 1030 RecordSyncShareMultiple(×, 1U))); |
1022 EXPECT_CALL(*delay(), GetDelay(_)). | 1031 EXPECT_CALL(*delay(), GetDelay(_)). |
1023 WillRepeatedly(Return(TimeDelta::FromDays(1))); | 1032 WillRepeatedly(Return(TimeDelta::FromDays(1))); |
1024 | 1033 |
1025 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 1034 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
1026 | 1035 |
1027 // This nudge should fail and put us into backoff. Thanks to our mock | 1036 // This nudge should fail and put us into backoff. Thanks to our mock |
1028 // GetDelay() setup above, this will be a long backoff. | 1037 // GetDelay() setup above, this will be a long backoff. |
1029 scheduler()->ScheduleLocalNudge(zero(), types, FROM_HERE); | 1038 scheduler()->ScheduleLocalNudge(types, FROM_HERE); |
1030 RunLoop(); | 1039 RunLoop(); |
1031 | 1040 |
1032 // From this point forward, no SyncShare functions should be invoked. | 1041 // From this point forward, no SyncShare functions should be invoked. |
1033 Mock::VerifyAndClearExpectations(syncer()); | 1042 Mock::VerifyAndClearExpectations(syncer()); |
1034 | 1043 |
1035 // Wait a while (10x poll interval) so a few poll jobs will be attempted. | 1044 // Wait a while (10x poll interval) so a few poll jobs will be attempted. |
1036 PumpLoopFor(poll * 10); | 1045 PumpLoopFor(poll * 10); |
1037 | 1046 |
1038 // Try (and fail) to schedule a nudge. | 1047 // Try (and fail) to schedule a nudge. |
1039 scheduler()->ScheduleLocalNudge( | 1048 scheduler()->ScheduleLocalNudge(types, FROM_HERE); |
1040 base::TimeDelta::FromMilliseconds(10), | |
1041 types, | |
1042 FROM_HERE); | |
1043 | 1049 |
1044 Mock::VerifyAndClearExpectations(syncer()); | 1050 Mock::VerifyAndClearExpectations(syncer()); |
1045 Mock::VerifyAndClearExpectations(delay()); | 1051 Mock::VerifyAndClearExpectations(delay()); |
1046 | 1052 |
1047 EXPECT_CALL(*delay(), GetDelay(_)).Times(0); | 1053 EXPECT_CALL(*delay(), GetDelay(_)).Times(0); |
1048 | 1054 |
1049 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 1055 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
1050 | 1056 |
1051 CallbackCounter ready_counter; | 1057 CallbackCounter ready_counter; |
1052 CallbackCounter retry_counter; | 1058 CallbackCounter retry_counter; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1085 .RetiresOnSaturation(); | 1091 .RetiresOnSaturation(); |
1086 EXPECT_CALL(*delay(), GetDelay(third)).WillOnce(Return(fourth)) | 1092 EXPECT_CALL(*delay(), GetDelay(third)).WillOnce(Return(fourth)) |
1087 .RetiresOnSaturation(); | 1093 .RetiresOnSaturation(); |
1088 EXPECT_CALL(*delay(), GetDelay(fourth)).WillOnce(Return(fifth)) | 1094 EXPECT_CALL(*delay(), GetDelay(fourth)).WillOnce(Return(fifth)) |
1089 .RetiresOnSaturation(); | 1095 .RetiresOnSaturation(); |
1090 EXPECT_CALL(*delay(), GetDelay(fifth)).WillOnce(Return(sixth)); | 1096 EXPECT_CALL(*delay(), GetDelay(fifth)).WillOnce(Return(sixth)); |
1091 | 1097 |
1092 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 1098 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
1093 | 1099 |
1094 // Run again with a nudge. | 1100 // Run again with a nudge. |
1095 scheduler()->ScheduleLocalNudge(zero(), ModelTypeSet(BOOKMARKS), FROM_HERE); | 1101 scheduler()->ScheduleLocalNudge(ModelTypeSet(BOOKMARKS), FROM_HERE); |
1096 RunLoop(); | 1102 RunLoop(); |
1097 | 1103 |
1098 ASSERT_EQ(kMinNumSamples, times.size()); | 1104 ASSERT_EQ(kMinNumSamples, times.size()); |
1099 EXPECT_GE(times[1] - times[0], second); | 1105 EXPECT_GE(times[1] - times[0], second); |
1100 EXPECT_GE(times[2] - times[1], third); | 1106 EXPECT_GE(times[2] - times[1], third); |
1101 EXPECT_GE(times[3] - times[2], fourth); | 1107 EXPECT_GE(times[3] - times[2], fourth); |
1102 EXPECT_GE(times[4] - times[3], fifth); | 1108 EXPECT_GE(times[4] - times[3], fifth); |
1103 } | 1109 } |
1104 | 1110 |
1105 // Test that things go back to normal once a retry makes forward progress. | 1111 // Test that things go back to normal once a retry makes forward progress. |
1106 TEST_F(SyncSchedulerTest, BackoffRelief) { | 1112 TEST_F(SyncSchedulerTest, BackoffRelief) { |
1107 SyncShareTimes times; | 1113 SyncShareTimes times; |
1108 const TimeDelta poll(TimeDelta::FromMilliseconds(10)); | 1114 const TimeDelta poll(TimeDelta::FromMilliseconds(10)); |
1109 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 1115 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
1110 UseMockDelayProvider(); | 1116 UseMockDelayProvider(); |
1111 | 1117 |
1112 const TimeDelta backoff = TimeDelta::FromMilliseconds(10); | 1118 const TimeDelta backoff = TimeDelta::FromMilliseconds(10); |
1113 EXPECT_CALL(*delay(), GetDelay(_)).WillOnce(Return(backoff)); | 1119 EXPECT_CALL(*delay(), GetDelay(_)).WillOnce(Return(backoff)); |
1114 | 1120 |
1115 // Optimal start for the post-backoff poll party. | 1121 // Optimal start for the post-backoff poll party. |
1116 TimeTicks optimal_start = TimeTicks::Now(); | 1122 TimeTicks optimal_start = TimeTicks::Now(); |
1117 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 1123 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
1118 | 1124 |
1119 // Kick off the test with a failed nudge. | 1125 // Kick off the test with a failed nudge. |
1120 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 1126 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
1121 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), | 1127 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), |
1122 RecordSyncShare(×))); | 1128 RecordSyncShare(×))); |
1123 scheduler()->ScheduleLocalNudge(zero(), ModelTypeSet(BOOKMARKS), FROM_HERE); | 1129 scheduler()->ScheduleLocalNudge(ModelTypeSet(BOOKMARKS), FROM_HERE); |
1124 RunLoop(); | 1130 RunLoop(); |
1125 Mock::VerifyAndClearExpectations(syncer()); | 1131 Mock::VerifyAndClearExpectations(syncer()); |
1126 TimeTicks optimal_job_time = optimal_start; | 1132 TimeTicks optimal_job_time = optimal_start; |
1127 ASSERT_EQ(1U, times.size()); | 1133 ASSERT_EQ(1U, times.size()); |
1128 EXPECT_GE(times[0], optimal_job_time); | 1134 EXPECT_GE(times[0], optimal_job_time); |
1129 | 1135 |
1130 // The retry succeeds. | 1136 // The retry succeeds. |
1131 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 1137 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
1132 .WillOnce(DoAll( | 1138 .WillOnce(DoAll( |
1133 Invoke(sessions::test_util::SimulateNormalSuccess), | 1139 Invoke(sessions::test_util::SimulateNormalSuccess), |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1185 TEST_F(SyncSchedulerTest, StartWhenNotConnected) { | 1191 TEST_F(SyncSchedulerTest, StartWhenNotConnected) { |
1186 connection()->SetServerNotReachable(); | 1192 connection()->SetServerNotReachable(); |
1187 connection()->UpdateConnectionStatus(); | 1193 connection()->UpdateConnectionStatus(); |
1188 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 1194 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
1189 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConnectionFailure), | 1195 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConnectionFailure), |
1190 Return(true))) | 1196 Return(true))) |
1191 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 1197 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), |
1192 Return(true))); | 1198 Return(true))); |
1193 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 1199 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
1194 | 1200 |
1195 scheduler()->ScheduleLocalNudge(zero(), ModelTypeSet(BOOKMARKS), FROM_HERE); | 1201 scheduler()->ScheduleLocalNudge(ModelTypeSet(BOOKMARKS), FROM_HERE); |
1196 // Should save the nudge for until after the server is reachable. | 1202 // Should save the nudge for until after the server is reachable. |
1197 base::MessageLoop::current()->RunUntilIdle(); | 1203 base::MessageLoop::current()->RunUntilIdle(); |
1198 | 1204 |
1199 scheduler()->OnConnectionStatusChange(); | 1205 scheduler()->OnConnectionStatusChange(); |
1200 connection()->SetServerReachable(); | 1206 connection()->SetServerReachable(); |
1201 connection()->UpdateConnectionStatus(); | 1207 connection()->UpdateConnectionStatus(); |
1202 base::MessageLoop::current()->RunUntilIdle(); | 1208 base::MessageLoop::current()->RunUntilIdle(); |
1203 } | 1209 } |
1204 | 1210 |
1205 TEST_F(SyncSchedulerTest, ServerConnectionChangeDuringBackoff) { | 1211 TEST_F(SyncSchedulerTest, ServerConnectionChangeDuringBackoff) { |
1206 UseMockDelayProvider(); | 1212 UseMockDelayProvider(); |
1207 EXPECT_CALL(*delay(), GetDelay(_)) | 1213 EXPECT_CALL(*delay(), GetDelay(_)) |
1208 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(0))); | 1214 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(0))); |
1209 | 1215 |
1210 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 1216 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
1211 connection()->SetServerNotReachable(); | 1217 connection()->SetServerNotReachable(); |
1212 connection()->UpdateConnectionStatus(); | 1218 connection()->UpdateConnectionStatus(); |
1213 | 1219 |
1214 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 1220 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
1215 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConnectionFailure), | 1221 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConnectionFailure), |
1216 Return(true))) | 1222 Return(true))) |
1217 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 1223 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), |
1218 Return(true))); | 1224 Return(true))); |
1219 | 1225 |
1220 scheduler()->ScheduleLocalNudge(zero(), ModelTypeSet(BOOKMARKS), FROM_HERE); | 1226 scheduler()->ScheduleLocalNudge(ModelTypeSet(BOOKMARKS), FROM_HERE); |
1221 PumpLoop(); // To get PerformDelayedNudge called. | 1227 PumpLoop(); // To get PerformDelayedNudge called. |
1222 PumpLoop(); // Run the nudge, that will fail and schedule a quick retry. | 1228 PumpLoop(); // Run the nudge, that will fail and schedule a quick retry. |
1223 ASSERT_TRUE(scheduler()->IsBackingOff()); | 1229 ASSERT_TRUE(scheduler()->IsBackingOff()); |
1224 | 1230 |
1225 // Before we run the scheduled canary, trigger a server connection change. | 1231 // Before we run the scheduled canary, trigger a server connection change. |
1226 scheduler()->OnConnectionStatusChange(); | 1232 scheduler()->OnConnectionStatusChange(); |
1227 connection()->SetServerReachable(); | 1233 connection()->SetServerReachable(); |
1228 connection()->UpdateConnectionStatus(); | 1234 connection()->UpdateConnectionStatus(); |
1229 base::MessageLoop::current()->RunUntilIdle(); | 1235 base::MessageLoop::current()->RunUntilIdle(); |
1230 } | 1236 } |
(...skipping 11 matching lines...) Expand all Loading... | |
1242 connection()->UpdateConnectionStatus(); | 1248 connection()->UpdateConnectionStatus(); |
1243 | 1249 |
1244 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 1250 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
1245 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConnectionFailure), | 1251 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConnectionFailure), |
1246 Return(true))) | 1252 Return(true))) |
1247 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 1253 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), |
1248 Return(true))) | 1254 Return(true))) |
1249 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 1255 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), |
1250 QuitLoopNowAction())); | 1256 QuitLoopNowAction())); |
1251 | 1257 |
1252 scheduler()->ScheduleLocalNudge(zero(), ModelTypeSet(BOOKMARKS), FROM_HERE); | 1258 scheduler()->ScheduleLocalNudge(ModelTypeSet(BOOKMARKS), FROM_HERE); |
1253 | 1259 |
1254 PumpLoop(); // To get PerformDelayedNudge called. | 1260 PumpLoop(); // To get PerformDelayedNudge called. |
1255 PumpLoop(); // Run the nudge, that will fail and schedule a quick retry. | 1261 PumpLoop(); // Run the nudge, that will fail and schedule a quick retry. |
1256 ASSERT_TRUE(scheduler()->IsBackingOff()); | 1262 ASSERT_TRUE(scheduler()->IsBackingOff()); |
1257 | 1263 |
1258 // Before we run the scheduled canary, trigger a server connection change. | 1264 // Before we run the scheduled canary, trigger a server connection change. |
1259 scheduler()->OnConnectionStatusChange(); | 1265 scheduler()->OnConnectionStatusChange(); |
1260 PumpLoop(); | 1266 PumpLoop(); |
1261 connection()->SetServerReachable(); | 1267 connection()->SetServerReachable(); |
1262 connection()->UpdateConnectionStatus(); | 1268 connection()->UpdateConnectionStatus(); |
1263 scheduler()->ScheduleLocalNudge(zero(), ModelTypeSet(BOOKMARKS), FROM_HERE); | 1269 scheduler()->ScheduleLocalNudge(ModelTypeSet(BOOKMARKS), FROM_HERE); |
1264 base::MessageLoop::current()->RunUntilIdle(); | 1270 base::MessageLoop::current()->RunUntilIdle(); |
1265 } | 1271 } |
1266 | 1272 |
1267 // Tests that we don't crash trying to run two canaries at once if we receive | 1273 // Tests that we don't crash trying to run two canaries at once if we receive |
1268 // extra connection status change notifications. See crbug.com/190085. | 1274 // extra connection status change notifications. See crbug.com/190085. |
1269 TEST_F(SyncSchedulerTest, DoubleCanaryInConfigure) { | 1275 TEST_F(SyncSchedulerTest, DoubleCanaryInConfigure) { |
1270 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) | 1276 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) |
1271 .WillRepeatedly(DoAll( | 1277 .WillRepeatedly(DoAll( |
1272 Invoke(sessions::test_util::SimulateConfigureConnectionFailure), | 1278 Invoke(sessions::test_util::SimulateConfigureConnectionFailure), |
1273 Return(true))); | 1279 Return(true))); |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1374 EXPECT_EQ(expected_delay, scheduler_test->GetRetryTimerDelay()); | 1380 EXPECT_EQ(expected_delay, scheduler_test->GetRetryTimerDelay()); |
1375 } | 1381 } |
1376 | 1382 |
1377 TEST_F(SyncSchedulerTest, ReceiveNewRetryDelay) { | 1383 TEST_F(SyncSchedulerTest, ReceiveNewRetryDelay) { |
1378 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 1384 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
1379 | 1385 |
1380 SyncShareTimes times; | 1386 SyncShareTimes times; |
1381 base::TimeDelta delay1 = base::TimeDelta::FromMilliseconds(100); | 1387 base::TimeDelta delay1 = base::TimeDelta::FromMilliseconds(100); |
1382 base::TimeDelta delay2 = base::TimeDelta::FromMilliseconds(200); | 1388 base::TimeDelta delay2 = base::TimeDelta::FromMilliseconds(200); |
1383 | 1389 |
1384 scheduler()->ScheduleLocalRefreshRequest(zero(), ModelTypeSet(BOOKMARKS), | 1390 scheduler()->ScheduleLocalNudge(ModelTypeSet(BOOKMARKS), FROM_HERE); |
1385 FROM_HERE); | |
1386 scheduler()->OnReceivedGuRetryDelay(delay1); | 1391 scheduler()->OnReceivedGuRetryDelay(delay1); |
1387 EXPECT_EQ(delay1, GetRetryTimerDelay()); | 1392 EXPECT_EQ(delay1, GetRetryTimerDelay()); |
1388 | 1393 |
1389 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 1394 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
1390 .WillOnce(DoAll( | 1395 .WillOnce(DoAll( |
1391 WithoutArgs(VerifyRetryTimerDelay(this, delay1)), | 1396 WithoutArgs(VerifyRetryTimerDelay(this, delay1)), |
1392 WithArg<2>(sessions::test_util::SimulateGuRetryDelayCommand(delay2)), | 1397 WithArg<2>(sessions::test_util::SimulateGuRetryDelayCommand(delay2)), |
1393 RecordSyncShare(×))); | 1398 RecordSyncShare(×))); |
1394 | 1399 |
1395 // Run nudge GU. | 1400 // Run nudge GU. |
1396 RunLoop(); | 1401 RunLoop(); |
1397 EXPECT_EQ(delay2, GetRetryTimerDelay()); | 1402 EXPECT_EQ(delay2, GetRetryTimerDelay()); |
1398 | 1403 |
1399 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 1404 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
1400 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 1405 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), |
1401 RecordSyncShare(×))); | 1406 RecordSyncShare(×))); |
1402 | 1407 |
1403 // Run to wait for retrying. | 1408 // Run to wait for retrying. |
1404 RunLoop(); | 1409 RunLoop(); |
1405 | 1410 |
1406 StopSyncScheduler(); | 1411 StopSyncScheduler(); |
1407 } | 1412 } |
1408 | 1413 |
1414 // Test the default nudge delays for various types, and that we can overwrite | |
1415 // them with custom delays. | |
1416 TEST_F(SyncSchedulerTest, NudgeDelayTest) { | |
1417 // Reset all delays to default | |
1418 std::map<ModelType, int> delay_map; | |
1419 ModelTypeSet protocol_types = syncer::ProtocolTypes(); | |
1420 for (ModelTypeSet::Iterator iter = protocol_types.First(); iter.Good(); | |
1421 iter.Inc()) { | |
1422 delay_map[iter.Get()] = -1; | |
1423 } | |
1424 scheduler()->OnReceivedCustomNudgeDelays(delay_map); | |
1425 | |
1426 // Bookmarks and preference both have "slow nudge" delays. | |
1427 EXPECT_EQ(scheduler()->GetNudgeDelayForTypes(ModelTypeSet(BOOKMARKS)), | |
1428 scheduler()->GetNudgeDelayForTypes(ModelTypeSet(PREFERENCES))); | |
1429 | |
1430 // Typed URLs has a default delay. | |
1431 EXPECT_EQ(scheduler()->GetNudgeDelayForTypes(ModelTypeSet(TYPED_URLS)), | |
1432 default_delay()); | |
1433 | |
1434 // "Slow nudge" delays are longer than the default. | |
1435 EXPECT_GT(scheduler()->GetNudgeDelayForTypes(ModelTypeSet(BOOKMARKS)), | |
1436 default_delay()); | |
1437 | |
1438 // Sessions is longer than "slow nudge". | |
1439 EXPECT_GT(scheduler()->GetNudgeDelayForTypes(ModelTypeSet(SESSIONS)), | |
1440 scheduler()->GetNudgeDelayForTypes(ModelTypeSet(BOOKMARKS))); | |
1441 | |
1442 // Favicons have the same delay as sessions. | |
1443 EXPECT_EQ(scheduler()->GetNudgeDelayForTypes(ModelTypeSet(SESSIONS)), | |
1444 scheduler()->GetNudgeDelayForTypes(ModelTypeSet(FAVICON_TRACKING))); | |
1445 | |
1446 // Autofill has the longer delay of all. | |
1447 EXPECT_GT(scheduler()->GetNudgeDelayForTypes(ModelTypeSet(AUTOFILL)), | |
1448 scheduler()->GetNudgeDelayForTypes(ModelTypeSet(SESSIONS))); | |
1449 | |
1450 // A nudge with no types takes the longest delay. | |
1451 EXPECT_GT(scheduler()->GetNudgeDelayForTypes(ModelTypeSet(AUTOFILL)), | |
1452 scheduler()->GetNudgeDelayForTypes(ModelTypeSet())); | |
1453 | |
1454 // The actual nudge delay should be the shortest of the set. | |
1455 EXPECT_EQ( | |
1456 scheduler()->GetNudgeDelayForTypes(ModelTypeSet(TYPED_URLS)), | |
1457 scheduler()->GetNudgeDelayForTypes(ModelTypeSet(TYPED_URLS, AUTOFILL))); | |
1458 | |
1459 // Set some custom delays. | |
1460 delay_map[BOOKMARKS] = 10000; | |
1461 delay_map[SESSIONS] = 2000; | |
1462 scheduler()->OnReceivedCustomNudgeDelays(delay_map); | |
1463 | |
1464 // Only those with custom delays should be affected, not another type. | |
1465 EXPECT_NE(scheduler()->GetNudgeDelayForTypes(ModelTypeSet(BOOKMARKS)), | |
1466 scheduler()->GetNudgeDelayForTypes(ModelTypeSet(PREFERENCES))); | |
1467 | |
1468 EXPECT_EQ(base::TimeDelta::FromMilliseconds(10000), | |
1469 scheduler()->GetNudgeDelayForTypes(ModelTypeSet(BOOKMARKS))); | |
1470 EXPECT_EQ(base::TimeDelta::FromMilliseconds(2000), | |
1471 scheduler()->GetNudgeDelayForTypes(ModelTypeSet(SESSIONS))); | |
1472 } | |
1473 | |
1409 } // namespace syncer | 1474 } // namespace syncer |
OLD | NEW |