OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/callback.h" | 6 #include "base/callback.h" |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/test/test_timeouts.h" | 10 #include "base/test/test_timeouts.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 using testing::WithArg; | 35 using testing::WithArg; |
36 | 36 |
37 namespace syncer { | 37 namespace syncer { |
38 using sessions::SyncSession; | 38 using sessions::SyncSession; |
39 using sessions::SyncSessionContext; | 39 using sessions::SyncSessionContext; |
40 using sessions::SyncSessionSnapshot; | 40 using sessions::SyncSessionSnapshot; |
41 using sync_pb::GetUpdatesCallerInfo; | 41 using sync_pb::GetUpdatesCallerInfo; |
42 | 42 |
43 class MockSyncer : public Syncer { | 43 class MockSyncer : public Syncer { |
44 public: | 44 public: |
45 MOCK_METHOD3(SyncShare, void(sessions::SyncSession*, SyncerStep, | 45 MOCK_METHOD3(SyncShare, bool(sessions::SyncSession*, SyncerStep, |
46 SyncerStep)); | 46 SyncerStep)); |
47 }; | 47 }; |
48 | 48 |
49 // Used when tests want to record syncing activity to examine later. | 49 // Used when tests want to record syncing activity to examine later. |
50 struct SyncShareRecords { | 50 struct SyncShareRecords { |
51 std::vector<TimeTicks> times; | 51 std::vector<TimeTicks> times; |
52 std::vector<SyncSessionSnapshot> snapshots; | 52 std::vector<SyncSessionSnapshot> snapshots; |
53 }; | 53 }; |
54 | 54 |
55 void QuitLoopNow() { | 55 void QuitLoopNow() { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 public: | 94 public: |
95 MockDelayProvider() : BackoffDelayProvider( | 95 MockDelayProvider() : BackoffDelayProvider( |
96 TimeDelta::FromSeconds(kInitialBackoffRetrySeconds), | 96 TimeDelta::FromSeconds(kInitialBackoffRetrySeconds), |
97 TimeDelta::FromSeconds(kInitialBackoffShortRetrySeconds)) { | 97 TimeDelta::FromSeconds(kInitialBackoffShortRetrySeconds)) { |
98 } | 98 } |
99 | 99 |
100 MOCK_METHOD1(GetDelay, TimeDelta(const TimeDelta&)); | 100 MOCK_METHOD1(GetDelay, TimeDelta(const TimeDelta&)); |
101 }; | 101 }; |
102 | 102 |
103 virtual void SetUp() { | 103 virtual void SetUp() { |
| 104 message_loop_.reset(new MessageLoop()); |
104 dir_maker_.SetUp(); | 105 dir_maker_.SetUp(); |
105 syncer_ = new MockSyncer(); | 106 syncer_ = new MockSyncer(); |
106 delay_ = NULL; | 107 delay_ = NULL; |
107 | 108 |
108 routing_info_[BOOKMARKS] = GROUP_UI; | 109 routing_info_[BOOKMARKS] = GROUP_UI; |
109 routing_info_[AUTOFILL] = GROUP_DB; | 110 routing_info_[AUTOFILL] = GROUP_DB; |
110 routing_info_[THEMES] = GROUP_UI; | 111 routing_info_[THEMES] = GROUP_UI; |
111 routing_info_[NIGORI] = GROUP_PASSIVE; | 112 routing_info_[NIGORI] = GROUP_PASSIVE; |
112 | 113 |
| 114 workers_.clear(); |
113 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_UI))); | 115 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_UI))); |
114 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_DB))); | 116 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_DB))); |
115 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_PASSIVE))); | 117 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_PASSIVE))); |
116 | 118 |
117 std::vector<ModelSafeWorker*> workers; | 119 std::vector<ModelSafeWorker*> workers; |
118 for (std::vector<scoped_refptr<FakeModelWorker> >::iterator it = | 120 for (std::vector<scoped_refptr<FakeModelWorker> >::iterator it = |
119 workers_.begin(); it != workers_.end(); ++it) { | 121 workers_.begin(); it != workers_.end(); ++it) { |
120 workers.push_back(it->get()); | 122 workers.push_back(it->get()); |
121 } | 123 } |
122 | 124 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 } | 218 } |
217 | 219 |
218 SyncSessionContext* context() { return context_.get(); } | 220 SyncSessionContext* context() { return context_.get(); } |
219 | 221 |
220 private: | 222 private: |
221 syncable::Directory* directory() { | 223 syncable::Directory* directory() { |
222 return dir_maker_.directory(); | 224 return dir_maker_.directory(); |
223 } | 225 } |
224 | 226 |
225 base::WeakPtrFactory<SyncSchedulerTest> weak_ptr_factory_; | 227 base::WeakPtrFactory<SyncSchedulerTest> weak_ptr_factory_; |
226 MessageLoop message_loop_; | 228 scoped_ptr<MessageLoop> message_loop_; |
227 TestDirectorySetterUpper dir_maker_; | 229 TestDirectorySetterUpper dir_maker_; |
228 scoped_ptr<MockConnectionManager> connection_; | 230 scoped_ptr<MockConnectionManager> connection_; |
229 scoped_ptr<SyncSessionContext> context_; | 231 scoped_ptr<SyncSessionContext> context_; |
230 scoped_ptr<SyncSchedulerImpl> scheduler_; | 232 scoped_ptr<SyncSchedulerImpl> scheduler_; |
231 MockSyncer* syncer_; | 233 MockSyncer* syncer_; |
232 MockDelayProvider* delay_; | 234 MockDelayProvider* delay_; |
233 std::vector<scoped_refptr<FakeModelWorker> > workers_; | 235 std::vector<scoped_refptr<FakeModelWorker> > workers_; |
234 FakeExtensionsActivityMonitor extensions_activity_monitor_; | 236 FakeExtensionsActivityMonitor extensions_activity_monitor_; |
235 scoped_ptr<ThrottledDataTypeTracker> throttled_data_type_tracker_; | 237 scoped_ptr<ThrottledDataTypeTracker> throttled_data_type_tracker_; |
236 ModelSafeRoutingInfo routing_info_; | 238 ModelSafeRoutingInfo routing_info_; |
237 }; | 239 }; |
238 | 240 |
239 void RecordSyncShareImpl(SyncSession* s, SyncShareRecords* record) { | 241 void RecordSyncShareImpl(SyncSession* s, SyncShareRecords* record) { |
240 record->times.push_back(TimeTicks::Now()); | 242 record->times.push_back(TimeTicks::Now()); |
241 record->snapshots.push_back(s->TakeSnapshot()); | 243 record->snapshots.push_back(s->TakeSnapshot()); |
242 } | 244 } |
243 | 245 |
244 ACTION_P(RecordSyncShare, record) { | 246 ACTION_P(RecordSyncShare, record) { |
245 RecordSyncShareImpl(arg0, record); | 247 RecordSyncShareImpl(arg0, record); |
246 if (MessageLoop::current()->is_running()) | 248 if (MessageLoop::current()->is_running()) |
247 QuitLoopNow(); | 249 QuitLoopNow(); |
| 250 return true; |
248 } | 251 } |
249 | 252 |
250 ACTION_P2(RecordSyncShareMultiple, record, quit_after) { | 253 ACTION_P2(RecordSyncShareMultiple, record, quit_after) { |
251 RecordSyncShareImpl(arg0, record); | 254 RecordSyncShareImpl(arg0, record); |
252 EXPECT_LE(record->times.size(), quit_after); | 255 EXPECT_LE(record->times.size(), quit_after); |
253 if (record->times.size() >= quit_after && | 256 if (record->times.size() >= quit_after && |
254 MessageLoop::current()->is_running()) { | 257 MessageLoop::current()->is_running()) { |
255 QuitLoopNow(); | 258 QuitLoopNow(); |
256 } | 259 } |
| 260 return true; |
257 } | 261 } |
258 | 262 |
259 ACTION(AddFailureAndQuitLoopNow) { | 263 ACTION(AddFailureAndQuitLoopNow) { |
260 ADD_FAILURE(); | 264 ADD_FAILURE(); |
261 QuitLoopNow(); | 265 QuitLoopNow(); |
| 266 return true; |
262 } | 267 } |
263 | 268 |
264 ACTION(QuitLoopNowAction) { | 269 ACTION(QuitLoopNowAction) { |
265 QuitLoopNow(); | 270 QuitLoopNow(); |
| 271 return true; |
266 } | 272 } |
267 | 273 |
268 // Test nudge scheduling. | 274 // Test nudge scheduling. |
269 TEST_F(SyncSchedulerTest, Nudge) { | 275 TEST_F(SyncSchedulerTest, Nudge) { |
270 SyncShareRecords records; | 276 SyncShareRecords records; |
271 ModelTypeSet model_types(BOOKMARKS); | 277 ModelTypeSet model_types(BOOKMARKS); |
272 | 278 |
273 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 279 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
274 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 280 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
275 WithArg<0>(RecordSyncShare(&records)))) | 281 WithArg<0>(RecordSyncShare(&records)))) |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 AnalyzePollRun(records, kMinNumSamples, optimal_start, poll_interval); | 644 AnalyzePollRun(records, kMinNumSamples, optimal_start, poll_interval); |
639 } | 645 } |
640 | 646 |
641 // Test that polling intervals are updated when needed. | 647 // Test that polling intervals are updated when needed. |
642 TEST_F(SyncSchedulerTest, PollIntervalUpdate) { | 648 TEST_F(SyncSchedulerTest, PollIntervalUpdate) { |
643 SyncShareRecords records; | 649 SyncShareRecords records; |
644 TimeDelta poll1(TimeDelta::FromMilliseconds(120)); | 650 TimeDelta poll1(TimeDelta::FromMilliseconds(120)); |
645 TimeDelta poll2(TimeDelta::FromMilliseconds(30)); | 651 TimeDelta poll2(TimeDelta::FromMilliseconds(30)); |
646 scheduler()->OnReceivedLongPollIntervalUpdate(poll1); | 652 scheduler()->OnReceivedLongPollIntervalUpdate(poll1); |
647 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(AtLeast(kMinNumSamples)) | 653 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(AtLeast(kMinNumSamples)) |
648 .WillOnce(WithArg<0>( | 654 .WillOnce(DoAll( |
649 sessions::test_util::SimulatePollIntervalUpdate(poll2))) | 655 WithArg<0>( |
| 656 sessions::test_util::SimulatePollIntervalUpdate(poll2)), |
| 657 Return(true))) |
650 .WillRepeatedly( | 658 .WillRepeatedly( |
651 DoAll(Invoke(sessions::test_util::SimulateSuccess), | 659 DoAll(Invoke(sessions::test_util::SimulateSuccess), |
652 WithArg<0>( | 660 WithArg<0>( |
653 RecordSyncShareMultiple(&records, kMinNumSamples)))); | 661 RecordSyncShareMultiple(&records, kMinNumSamples)))); |
654 | 662 |
655 TimeTicks optimal_start = TimeTicks::Now() + poll1 + poll2; | 663 TimeTicks optimal_start = TimeTicks::Now() + poll1 + poll2; |
656 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 664 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
657 | 665 |
658 // Run again to wait for polling. | 666 // Run again to wait for polling. |
659 RunLoop(); | 667 RunLoop(); |
(...skipping 27 matching lines...) Expand all Loading... |
687 zero(), NUDGE_SOURCE_LOCAL, model_types, FROM_HERE); | 695 zero(), NUDGE_SOURCE_LOCAL, model_types, FROM_HERE); |
688 RunLoop(); | 696 RunLoop(); |
689 | 697 |
690 EXPECT_EQ(delay2, scheduler()->GetSessionsCommitDelay()); | 698 EXPECT_EQ(delay2, scheduler()->GetSessionsCommitDelay()); |
691 StopSyncScheduler(); | 699 StopSyncScheduler(); |
692 } | 700 } |
693 | 701 |
694 // Test that a sync session is run through to completion. | 702 // Test that a sync session is run through to completion. |
695 TEST_F(SyncSchedulerTest, HasMoreToSync) { | 703 TEST_F(SyncSchedulerTest, HasMoreToSync) { |
696 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 704 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
697 .WillOnce(Invoke(sessions::test_util::SimulateHasMoreToSync)) | 705 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateHasMoreToSync), |
| 706 Return(true))) |
698 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 707 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
699 QuitLoopNowAction())); | 708 QuitLoopNowAction())); |
700 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 709 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
701 | 710 |
702 scheduler()->ScheduleNudgeAsync( | 711 scheduler()->ScheduleNudgeAsync( |
703 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(BOOKMARKS), FROM_HERE); | 712 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(BOOKMARKS), FROM_HERE); |
704 RunLoop(); | 713 RunLoop(); |
705 // If more nudges are scheduled, they'll be waited on by TearDown, and would | 714 // If more nudges are scheduled, they'll be waited on by TearDown, and would |
706 // cause our expectation to break. | 715 // cause our expectation to break. |
707 } | 716 } |
708 | 717 |
709 // Test that continuations can go into backoff. | 718 // Test that continuations can go into backoff. |
710 TEST_F(SyncSchedulerTest, HasMoreToSyncThenFails) { | 719 TEST_F(SyncSchedulerTest, HasMoreToSyncThenFails) { |
711 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 720 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
712 .WillOnce(Invoke(sessions::test_util::SimulateHasMoreToSync)) | 721 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateHasMoreToSync), |
| 722 Return(true))) |
713 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), | 723 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), |
714 QuitLoopNowAction())); | 724 QuitLoopNowAction())); |
715 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 725 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
716 | 726 |
717 scheduler()->ScheduleNudgeAsync( | 727 scheduler()->ScheduleNudgeAsync( |
718 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(BOOKMARKS), FROM_HERE); | 728 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(BOOKMARKS), FROM_HERE); |
719 | 729 |
720 // We should detect the failure on the second sync share, and go into backoff. | 730 // We should detect the failure on the second sync share, and go into backoff. |
721 EXPECT_TRUE(RunAndGetBackoff()); | 731 EXPECT_TRUE(RunAndGetBackoff()); |
722 } | 732 } |
723 | 733 |
724 // Test that no syncing occurs when throttled. | 734 // Test that no syncing occurs when throttled. |
725 TEST_F(SyncSchedulerTest, ThrottlingDoesThrottle) { | 735 TEST_F(SyncSchedulerTest, ThrottlingDoesThrottle) { |
726 const ModelTypeSet types(BOOKMARKS); | 736 const ModelTypeSet types(BOOKMARKS); |
727 TimeDelta poll(TimeDelta::FromMilliseconds(5)); | 737 TimeDelta poll(TimeDelta::FromMilliseconds(5)); |
728 TimeDelta throttle(TimeDelta::FromMinutes(10)); | 738 TimeDelta throttle(TimeDelta::FromMinutes(10)); |
729 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 739 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
730 | 740 |
731 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 741 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
732 .WillOnce(WithArg<0>(sessions::test_util::SimulateThrottled(throttle))) | 742 .WillOnce(DoAll( |
| 743 WithArg<0>(sessions::test_util::SimulateThrottled(throttle)), |
| 744 Return(true))) |
733 .WillRepeatedly(AddFailureAndQuitLoopNow()); | 745 .WillRepeatedly(AddFailureAndQuitLoopNow()); |
734 | 746 |
735 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 747 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
736 | 748 |
737 scheduler()->ScheduleNudgeAsync( | 749 scheduler()->ScheduleNudgeAsync( |
738 zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE); | 750 zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE); |
739 PumpLoop(); | 751 PumpLoop(); |
740 | 752 |
741 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 753 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
742 | 754 |
743 CallbackCounter counter; | 755 CallbackCounter counter; |
744 ConfigurationParams params( | 756 ConfigurationParams params( |
745 GetUpdatesCallerInfo::RECONFIGURATION, | 757 GetUpdatesCallerInfo::RECONFIGURATION, |
746 types, | 758 types, |
747 TypesToRoutingInfo(types), | 759 TypesToRoutingInfo(types), |
748 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); | 760 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); |
749 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params)); | 761 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params)); |
750 ASSERT_EQ(0, counter.times_called()); | 762 ASSERT_EQ(0, counter.times_called()); |
751 } | 763 } |
752 | 764 |
753 TEST_F(SyncSchedulerTest, ThrottlingExpires) { | 765 TEST_F(SyncSchedulerTest, ThrottlingExpires) { |
754 SyncShareRecords records; | 766 SyncShareRecords records; |
755 TimeDelta poll(TimeDelta::FromMilliseconds(15)); | 767 TimeDelta poll(TimeDelta::FromMilliseconds(15)); |
756 TimeDelta throttle1(TimeDelta::FromMilliseconds(150)); | 768 TimeDelta throttle1(TimeDelta::FromMilliseconds(150)); |
757 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 769 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
758 | 770 |
759 ::testing::InSequence seq; | 771 ::testing::InSequence seq; |
760 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 772 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
761 .WillOnce(WithArg<0>(sessions::test_util::SimulateThrottled(throttle1))) | 773 .WillOnce(DoAll( |
| 774 WithArg<0>(sessions::test_util::SimulateThrottled(throttle1)), |
| 775 Return(true))) |
762 .RetiresOnSaturation(); | 776 .RetiresOnSaturation(); |
763 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 777 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
764 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 778 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
765 WithArg<0>(RecordSyncShareMultiple(&records, kMinNumSamples)))); | 779 WithArg<0>(RecordSyncShareMultiple(&records, kMinNumSamples)))); |
766 | 780 |
767 TimeTicks optimal_start = TimeTicks::Now() + poll + throttle1; | 781 TimeTicks optimal_start = TimeTicks::Now() + poll + throttle1; |
768 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 782 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
769 | 783 |
770 // Run again to wait for polling. | 784 // Run again to wait for polling. |
771 RunLoop(); | 785 RunLoop(); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
849 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 863 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
850 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), | 864 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), |
851 QuitLoopNowAction())); | 865 QuitLoopNowAction())); |
852 EXPECT_TRUE(RunAndGetBackoff()); | 866 EXPECT_TRUE(RunAndGetBackoff()); |
853 } | 867 } |
854 | 868 |
855 // Have the syncer fail during download updates and succeed on the first | 869 // Have the syncer fail during download updates and succeed on the first |
856 // retry. Expect that this clears the backoff state. | 870 // retry. Expect that this clears the backoff state. |
857 TEST_F(BackoffTriggersSyncSchedulerTest, FailDownloadOnceThenSucceed) { | 871 TEST_F(BackoffTriggersSyncSchedulerTest, FailDownloadOnceThenSucceed) { |
858 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 872 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
859 .WillOnce(Invoke(sessions::test_util::SimulateDownloadUpdatesFailed)) | 873 .WillOnce(DoAll( |
| 874 Invoke(sessions::test_util::SimulateDownloadUpdatesFailed), |
| 875 Return(true))) |
860 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 876 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
861 QuitLoopNowAction())); | 877 QuitLoopNowAction())); |
862 EXPECT_FALSE(RunAndGetBackoff()); | 878 EXPECT_FALSE(RunAndGetBackoff()); |
863 } | 879 } |
864 | 880 |
865 // Have the syncer fail during commit and succeed on the first retry. Expect | 881 // Have the syncer fail during commit and succeed on the first retry. Expect |
866 // that this clears the backoff state. | 882 // that this clears the backoff state. |
867 TEST_F(BackoffTriggersSyncSchedulerTest, FailCommitOnceThenSucceed) { | 883 TEST_F(BackoffTriggersSyncSchedulerTest, FailCommitOnceThenSucceed) { |
868 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 884 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
869 .WillOnce(Invoke(sessions::test_util::SimulateCommitFailed)) | 885 .WillOnce(DoAll( |
| 886 Invoke(sessions::test_util::SimulateCommitFailed), |
| 887 Return(true))) |
870 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 888 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
871 QuitLoopNowAction())); | 889 QuitLoopNowAction())); |
872 EXPECT_FALSE(RunAndGetBackoff()); | 890 EXPECT_FALSE(RunAndGetBackoff()); |
873 } | 891 } |
874 | 892 |
875 // Have the syncer fail to download updates and fail again on the retry. | 893 // Have the syncer fail to download updates and fail again on the retry. |
876 // Expect this will leave the scheduler in backoff. | 894 // Expect this will leave the scheduler in backoff. |
877 TEST_F(BackoffTriggersSyncSchedulerTest, FailDownloadTwice) { | 895 TEST_F(BackoffTriggersSyncSchedulerTest, FailDownloadTwice) { |
878 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 896 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
879 .WillOnce(Invoke(sessions::test_util::SimulateDownloadUpdatesFailed)) | 897 .WillOnce(DoAll( |
| 898 Invoke(sessions::test_util::SimulateDownloadUpdatesFailed), |
| 899 Return(true))) |
880 .WillRepeatedly(DoAll( | 900 .WillRepeatedly(DoAll( |
881 Invoke(sessions::test_util::SimulateDownloadUpdatesFailed), | 901 Invoke(sessions::test_util::SimulateDownloadUpdatesFailed), |
882 QuitLoopNowAction())); | 902 QuitLoopNowAction())); |
883 EXPECT_TRUE(RunAndGetBackoff()); | 903 EXPECT_TRUE(RunAndGetBackoff()); |
884 } | 904 } |
885 | 905 |
886 // Have the syncer fail to get the encryption key yet succeed in downloading | 906 // Have the syncer fail to get the encryption key yet succeed in downloading |
887 // updates. Expect this will leave the scheduler in backoff. | 907 // updates. Expect this will leave the scheduler in backoff. |
888 TEST_F(BackoffTriggersSyncSchedulerTest, FailGetEncryptionKey) { | 908 TEST_F(BackoffTriggersSyncSchedulerTest, FailGetEncryptionKey) { |
889 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 909 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
890 .WillOnce(Invoke(sessions::test_util::SimulateGetEncryptionKeyFailed)) | 910 .WillOnce(DoAll( |
| 911 Invoke(sessions::test_util::SimulateGetEncryptionKeyFailed), |
| 912 Return(true))) |
891 .WillRepeatedly(DoAll( | 913 .WillRepeatedly(DoAll( |
892 Invoke(sessions::test_util::SimulateGetEncryptionKeyFailed), | 914 Invoke(sessions::test_util::SimulateGetEncryptionKeyFailed), |
893 QuitLoopNowAction())); | 915 QuitLoopNowAction())); |
894 EXPECT_TRUE(RunAndGetBackoff()); | 916 EXPECT_TRUE(RunAndGetBackoff()); |
895 } | 917 } |
896 | 918 |
897 // Test that no polls or extraneous nudges occur when in backoff. | 919 // Test that no polls or extraneous nudges occur when in backoff. |
898 TEST_F(SyncSchedulerTest, BackoffDropsJobs) { | 920 TEST_F(SyncSchedulerTest, BackoffDropsJobs) { |
899 SyncShareRecords r; | 921 SyncShareRecords r; |
900 TimeDelta poll(TimeDelta::FromMilliseconds(5)); | 922 TimeDelta poll(TimeDelta::FromMilliseconds(5)); |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1062 | 1084 |
1063 // Run the successful poll. | 1085 // Run the successful poll. |
1064 RunLoop(); | 1086 RunLoop(); |
1065 EXPECT_FALSE(scheduler()->IsBackingOff()); | 1087 EXPECT_FALSE(scheduler()->IsBackingOff()); |
1066 } | 1088 } |
1067 | 1089 |
1068 // Test that appropriate syncer steps are requested for each job type. | 1090 // Test that appropriate syncer steps are requested for each job type. |
1069 TEST_F(SyncSchedulerTest, SyncerSteps) { | 1091 TEST_F(SyncSchedulerTest, SyncerSteps) { |
1070 // Nudges. | 1092 // Nudges. |
1071 EXPECT_CALL(*syncer(), SyncShare(_, SYNCER_BEGIN, SYNCER_END)) | 1093 EXPECT_CALL(*syncer(), SyncShare(_, SYNCER_BEGIN, SYNCER_END)) |
1072 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)); | 1094 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 1095 Return(true))); |
1073 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 1096 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
1074 | 1097 |
1075 scheduler()->ScheduleNudgeAsync( | 1098 scheduler()->ScheduleNudgeAsync( |
1076 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(BOOKMARKS), FROM_HERE); | 1099 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(BOOKMARKS), FROM_HERE); |
1077 PumpLoop(); | 1100 PumpLoop(); |
1078 // Pump again to run job. | 1101 // Pump again to run job. |
1079 PumpLoop(); | 1102 PumpLoop(); |
1080 | 1103 |
1081 StopSyncScheduler(); | 1104 StopSyncScheduler(); |
1082 Mock::VerifyAndClearExpectations(syncer()); | 1105 Mock::VerifyAndClearExpectations(syncer()); |
1083 | 1106 |
1084 // Configuration. | 1107 // Configuration. |
1085 EXPECT_CALL(*syncer(), SyncShare(_, DOWNLOAD_UPDATES, APPLY_UPDATES)) | 1108 EXPECT_CALL(*syncer(), SyncShare(_, DOWNLOAD_UPDATES, APPLY_UPDATES)) |
1086 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)); | 1109 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 1110 Return(true))); |
1087 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 1111 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
1088 | 1112 |
1089 ModelTypeSet model_types(BOOKMARKS); | 1113 ModelTypeSet model_types(BOOKMARKS); |
1090 CallbackCounter counter; | 1114 CallbackCounter counter; |
1091 ConfigurationParams params( | 1115 ConfigurationParams params( |
1092 GetUpdatesCallerInfo::RECONFIGURATION, | 1116 GetUpdatesCallerInfo::RECONFIGURATION, |
1093 model_types, | 1117 model_types, |
1094 TypesToRoutingInfo(model_types), | 1118 TypesToRoutingInfo(model_types), |
1095 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); | 1119 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); |
1096 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params)); | 1120 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params)); |
(...skipping 20 matching lines...) Expand all Loading... |
1117 StopSyncScheduler(); | 1141 StopSyncScheduler(); |
1118 Mock::VerifyAndClearExpectations(syncer()); | 1142 Mock::VerifyAndClearExpectations(syncer()); |
1119 } | 1143 } |
1120 | 1144 |
1121 // Test that starting the syncer thread without a valid connection doesn't | 1145 // Test that starting the syncer thread without a valid connection doesn't |
1122 // break things when a connection is detected. | 1146 // break things when a connection is detected. |
1123 TEST_F(SyncSchedulerTest, StartWhenNotConnected) { | 1147 TEST_F(SyncSchedulerTest, StartWhenNotConnected) { |
1124 connection()->SetServerNotReachable(); | 1148 connection()->SetServerNotReachable(); |
1125 connection()->UpdateConnectionStatus(); | 1149 connection()->UpdateConnectionStatus(); |
1126 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 1150 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
1127 .WillOnce(Invoke(sessions::test_util::SimulateConnectionFailure)) | 1151 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConnectionFailure), |
1128 .WillOnce(QuitLoopNowAction()); | 1152 Return(true))) |
| 1153 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
| 1154 QuitLoopNowAction())); |
1129 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 1155 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
1130 | 1156 |
1131 scheduler()->ScheduleNudgeAsync( | 1157 scheduler()->ScheduleNudgeAsync( |
1132 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(BOOKMARKS), FROM_HERE); | 1158 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(BOOKMARKS), FROM_HERE); |
1133 // Should save the nudge for until after the server is reachable. | 1159 // Should save the nudge for until after the server is reachable. |
1134 MessageLoop::current()->RunAllPending(); | 1160 MessageLoop::current()->RunAllPending(); |
1135 | 1161 |
1136 connection()->SetServerReachable(); | 1162 connection()->SetServerReachable(); |
1137 connection()->UpdateConnectionStatus(); | 1163 connection()->UpdateConnectionStatus(); |
1138 scheduler()->OnConnectionStatusChange(); | 1164 scheduler()->OnConnectionStatusChange(); |
1139 MessageLoop::current()->RunAllPending(); | 1165 MessageLoop::current()->RunAllPending(); |
1140 } | 1166 } |
1141 | 1167 |
1142 } // namespace syncer | 1168 } // namespace syncer |
OLD | NEW |