Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(850)

Side by Side Diff: sync/engine/sync_scheduler_unittest.cc

Issue 10917234: sync: make scheduling logic and job ownership more obvious. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address review Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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
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
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_;
akalin 2012/10/26 06:52:29 why'd you have to do this?
tim (not reviewing) 2012/10/26 22:52:27 Ah, leftover from some debugging. Undone.
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 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 AnalyzePollRun(records, kMinNumSamples, optimal_start, poll_interval); 645 AnalyzePollRun(records, kMinNumSamples, optimal_start, poll_interval);
640 } 646 }
641 647
642 // Test that polling intervals are updated when needed. 648 // Test that polling intervals are updated when needed.
643 TEST_F(SyncSchedulerTest, PollIntervalUpdate) { 649 TEST_F(SyncSchedulerTest, PollIntervalUpdate) {
644 SyncShareRecords records; 650 SyncShareRecords records;
645 TimeDelta poll1(TimeDelta::FromMilliseconds(120)); 651 TimeDelta poll1(TimeDelta::FromMilliseconds(120));
646 TimeDelta poll2(TimeDelta::FromMilliseconds(30)); 652 TimeDelta poll2(TimeDelta::FromMilliseconds(30));
647 scheduler()->OnReceivedLongPollIntervalUpdate(poll1); 653 scheduler()->OnReceivedLongPollIntervalUpdate(poll1);
648 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(AtLeast(kMinNumSamples)) 654 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(AtLeast(kMinNumSamples))
649 .WillOnce(WithArg<0>( 655 .WillOnce(DoAll(
650 sessions::test_util::SimulatePollIntervalUpdate(poll2))) 656 WithArg<0>(
657 sessions::test_util::SimulatePollIntervalUpdate(poll2)),
658 Return(true)))
651 .WillRepeatedly( 659 .WillRepeatedly(
652 DoAll(Invoke(sessions::test_util::SimulateSuccess), 660 DoAll(Invoke(sessions::test_util::SimulateSuccess),
653 WithArg<0>( 661 WithArg<0>(
654 RecordSyncShareMultiple(&records, kMinNumSamples)))); 662 RecordSyncShareMultiple(&records, kMinNumSamples))));
655 663
656 TimeTicks optimal_start = TimeTicks::Now() + poll1 + poll2; 664 TimeTicks optimal_start = TimeTicks::Now() + poll1 + poll2;
657 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 665 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
658 666
659 // Run again to wait for polling. 667 // Run again to wait for polling.
660 RunLoop(); 668 RunLoop();
(...skipping 27 matching lines...) Expand all
688 zero(), NUDGE_SOURCE_LOCAL, model_types, FROM_HERE); 696 zero(), NUDGE_SOURCE_LOCAL, model_types, FROM_HERE);
689 RunLoop(); 697 RunLoop();
690 698
691 EXPECT_EQ(delay2, scheduler()->GetSessionsCommitDelay()); 699 EXPECT_EQ(delay2, scheduler()->GetSessionsCommitDelay());
692 StopSyncScheduler(); 700 StopSyncScheduler();
693 } 701 }
694 702
695 // Test that a sync session is run through to completion. 703 // Test that a sync session is run through to completion.
696 TEST_F(SyncSchedulerTest, HasMoreToSync) { 704 TEST_F(SyncSchedulerTest, HasMoreToSync) {
697 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 705 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
698 .WillOnce(Invoke(sessions::test_util::SimulateHasMoreToSync)) 706 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateHasMoreToSync),
707 Return(true)))
699 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 708 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
700 QuitLoopNowAction())); 709 QuitLoopNowAction()));
701 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 710 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
702 711
703 scheduler()->ScheduleNudgeAsync( 712 scheduler()->ScheduleNudgeAsync(
704 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(BOOKMARKS), FROM_HERE); 713 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(BOOKMARKS), FROM_HERE);
705 RunLoop(); 714 RunLoop();
706 // If more nudges are scheduled, they'll be waited on by TearDown, and would 715 // If more nudges are scheduled, they'll be waited on by TearDown, and would
707 // cause our expectation to break. 716 // cause our expectation to break.
708 } 717 }
709 718
710 // Test that continuations can go into backoff. 719 // Test that continuations can go into backoff.
711 TEST_F(SyncSchedulerTest, HasMoreToSyncThenFails) { 720 TEST_F(SyncSchedulerTest, HasMoreToSyncThenFails) {
712 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 721 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
713 .WillOnce(Invoke(sessions::test_util::SimulateHasMoreToSync)) 722 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateHasMoreToSync),
723 Return(true)))
714 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), 724 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed),
715 QuitLoopNowAction())); 725 QuitLoopNowAction()));
716 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 726 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
717 727
718 scheduler()->ScheduleNudgeAsync( 728 scheduler()->ScheduleNudgeAsync(
719 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(BOOKMARKS), FROM_HERE); 729 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(BOOKMARKS), FROM_HERE);
720 730
721 // We should detect the failure on the second sync share, and go into backoff. 731 // We should detect the failure on the second sync share, and go into backoff.
722 EXPECT_TRUE(RunAndGetBackoff()); 732 EXPECT_TRUE(RunAndGetBackoff());
723 } 733 }
724 734
725 // Test that no syncing occurs when throttled. 735 // Test that no syncing occurs when throttled.
726 TEST_F(SyncSchedulerTest, ThrottlingDoesThrottle) { 736 TEST_F(SyncSchedulerTest, ThrottlingDoesThrottle) {
727 const ModelTypeSet types(BOOKMARKS); 737 const ModelTypeSet types(BOOKMARKS);
728 TimeDelta poll(TimeDelta::FromMilliseconds(5)); 738 TimeDelta poll(TimeDelta::FromMilliseconds(5));
729 TimeDelta throttle(TimeDelta::FromMinutes(10)); 739 TimeDelta throttle(TimeDelta::FromMinutes(10));
730 scheduler()->OnReceivedLongPollIntervalUpdate(poll); 740 scheduler()->OnReceivedLongPollIntervalUpdate(poll);
731 741
732 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 742 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
733 .WillOnce(WithArg<0>(sessions::test_util::SimulateThrottled(throttle))) 743 .WillOnce(DoAll(
744 WithArg<0>(sessions::test_util::SimulateThrottled(throttle)),
745 Return(true)))
734 .WillRepeatedly(AddFailureAndQuitLoopNow()); 746 .WillRepeatedly(AddFailureAndQuitLoopNow());
735 747
736 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 748 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
737 749
738 scheduler()->ScheduleNudgeAsync( 750 scheduler()->ScheduleNudgeAsync(
739 zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE); 751 zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE);
740 PumpLoop(); 752 PumpLoop();
741 753
742 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 754 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
743 755
744 CallbackCounter counter; 756 CallbackCounter counter;
745 ConfigurationParams params( 757 ConfigurationParams params(
746 GetUpdatesCallerInfo::RECONFIGURATION, 758 GetUpdatesCallerInfo::RECONFIGURATION,
747 types, 759 types,
748 TypesToRoutingInfo(types), 760 TypesToRoutingInfo(types),
749 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); 761 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter)));
750 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params)); 762 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params));
751 ASSERT_EQ(0, counter.times_called()); 763 ASSERT_EQ(0, counter.times_called());
752 } 764 }
753 765
754 TEST_F(SyncSchedulerTest, ThrottlingExpires) { 766 TEST_F(SyncSchedulerTest, ThrottlingExpires) {
755 SyncShareRecords records; 767 SyncShareRecords records;
756 TimeDelta poll(TimeDelta::FromMilliseconds(15)); 768 TimeDelta poll(TimeDelta::FromMilliseconds(15));
757 TimeDelta throttle1(TimeDelta::FromMilliseconds(150)); 769 TimeDelta throttle1(TimeDelta::FromMilliseconds(150));
758 scheduler()->OnReceivedLongPollIntervalUpdate(poll); 770 scheduler()->OnReceivedLongPollIntervalUpdate(poll);
759 771
760 ::testing::InSequence seq; 772 ::testing::InSequence seq;
761 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 773 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
762 .WillOnce(WithArg<0>(sessions::test_util::SimulateThrottled(throttle1))) 774 .WillOnce(DoAll(
775 WithArg<0>(sessions::test_util::SimulateThrottled(throttle1)),
776 Return(true)))
763 .RetiresOnSaturation(); 777 .RetiresOnSaturation();
764 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 778 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
765 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess), 779 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess),
766 WithArg<0>(RecordSyncShareMultiple(&records, kMinNumSamples)))); 780 WithArg<0>(RecordSyncShareMultiple(&records, kMinNumSamples))));
767 781
768 TimeTicks optimal_start = TimeTicks::Now() + poll + throttle1; 782 TimeTicks optimal_start = TimeTicks::Now() + poll + throttle1;
769 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 783 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
770 784
771 // Run again to wait for polling. 785 // Run again to wait for polling.
772 RunLoop(); 786 RunLoop();
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 864 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
851 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), 865 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed),
852 QuitLoopNowAction())); 866 QuitLoopNowAction()));
853 EXPECT_TRUE(RunAndGetBackoff()); 867 EXPECT_TRUE(RunAndGetBackoff());
854 } 868 }
855 869
856 // Have the syncer fail during download updates and succeed on the first 870 // Have the syncer fail during download updates and succeed on the first
857 // retry. Expect that this clears the backoff state. 871 // retry. Expect that this clears the backoff state.
858 TEST_F(BackoffTriggersSyncSchedulerTest, FailDownloadOnceThenSucceed) { 872 TEST_F(BackoffTriggersSyncSchedulerTest, FailDownloadOnceThenSucceed) {
859 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 873 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
860 .WillOnce(Invoke(sessions::test_util::SimulateDownloadUpdatesFailed)) 874 .WillOnce(DoAll(
875 Invoke(sessions::test_util::SimulateDownloadUpdatesFailed),
876 Return(true)))
861 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 877 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
862 QuitLoopNowAction())); 878 QuitLoopNowAction()));
863 EXPECT_FALSE(RunAndGetBackoff()); 879 EXPECT_FALSE(RunAndGetBackoff());
864 } 880 }
865 881
866 // Have the syncer fail during commit and succeed on the first retry. Expect 882 // Have the syncer fail during commit and succeed on the first retry. Expect
867 // that this clears the backoff state. 883 // that this clears the backoff state.
868 TEST_F(BackoffTriggersSyncSchedulerTest, FailCommitOnceThenSucceed) { 884 TEST_F(BackoffTriggersSyncSchedulerTest, FailCommitOnceThenSucceed) {
869 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 885 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
870 .WillOnce(Invoke(sessions::test_util::SimulateCommitFailed)) 886 .WillOnce(DoAll(
887 Invoke(sessions::test_util::SimulateCommitFailed),
888 Return(true)))
871 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 889 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
872 QuitLoopNowAction())); 890 QuitLoopNowAction()));
873 EXPECT_FALSE(RunAndGetBackoff()); 891 EXPECT_FALSE(RunAndGetBackoff());
874 } 892 }
875 893
876 // Have the syncer fail to download updates and fail again on the retry. 894 // Have the syncer fail to download updates and fail again on the retry.
877 // Expect this will leave the scheduler in backoff. 895 // Expect this will leave the scheduler in backoff.
878 TEST_F(BackoffTriggersSyncSchedulerTest, FailDownloadTwice) { 896 TEST_F(BackoffTriggersSyncSchedulerTest, FailDownloadTwice) {
879 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 897 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
880 .WillOnce(Invoke(sessions::test_util::SimulateDownloadUpdatesFailed)) 898 .WillOnce(DoAll(
899 Invoke(sessions::test_util::SimulateDownloadUpdatesFailed),
900 Return(true)))
881 .WillRepeatedly(DoAll( 901 .WillRepeatedly(DoAll(
882 Invoke(sessions::test_util::SimulateDownloadUpdatesFailed), 902 Invoke(sessions::test_util::SimulateDownloadUpdatesFailed),
883 QuitLoopNowAction())); 903 QuitLoopNowAction()));
884 EXPECT_TRUE(RunAndGetBackoff()); 904 EXPECT_TRUE(RunAndGetBackoff());
885 } 905 }
886 906
887 // Have the syncer fail to get the encryption key yet succeed in downloading 907 // Have the syncer fail to get the encryption key yet succeed in downloading
888 // updates. Expect this will leave the scheduler in backoff. 908 // updates. Expect this will leave the scheduler in backoff.
889 TEST_F(BackoffTriggersSyncSchedulerTest, FailGetEncryptionKey) { 909 TEST_F(BackoffTriggersSyncSchedulerTest, FailGetEncryptionKey) {
890 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 910 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
891 .WillOnce(Invoke(sessions::test_util::SimulateGetEncryptionKeyFailed)) 911 .WillOnce(DoAll(
912 Invoke(sessions::test_util::SimulateGetEncryptionKeyFailed),
913 Return(true)))
892 .WillRepeatedly(DoAll( 914 .WillRepeatedly(DoAll(
893 Invoke(sessions::test_util::SimulateGetEncryptionKeyFailed), 915 Invoke(sessions::test_util::SimulateGetEncryptionKeyFailed),
894 QuitLoopNowAction())); 916 QuitLoopNowAction()));
895 EXPECT_TRUE(RunAndGetBackoff()); 917 EXPECT_TRUE(RunAndGetBackoff());
896 } 918 }
897 919
898 // Test that no polls or extraneous nudges occur when in backoff. 920 // Test that no polls or extraneous nudges occur when in backoff.
899 TEST_F(SyncSchedulerTest, BackoffDropsJobs) { 921 TEST_F(SyncSchedulerTest, BackoffDropsJobs) {
900 SyncShareRecords r; 922 SyncShareRecords r;
901 TimeDelta poll(TimeDelta::FromMilliseconds(5)); 923 TimeDelta poll(TimeDelta::FromMilliseconds(5));
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 1085
1064 // Run the successful poll. 1086 // Run the successful poll.
1065 RunLoop(); 1087 RunLoop();
1066 EXPECT_FALSE(scheduler()->IsBackingOff()); 1088 EXPECT_FALSE(scheduler()->IsBackingOff());
1067 } 1089 }
1068 1090
1069 // Test that appropriate syncer steps are requested for each job type. 1091 // Test that appropriate syncer steps are requested for each job type.
1070 TEST_F(SyncSchedulerTest, SyncerSteps) { 1092 TEST_F(SyncSchedulerTest, SyncerSteps) {
1071 // Nudges. 1093 // Nudges.
1072 EXPECT_CALL(*syncer(), SyncShare(_, SYNCER_BEGIN, SYNCER_END)) 1094 EXPECT_CALL(*syncer(), SyncShare(_, SYNCER_BEGIN, SYNCER_END))
1073 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)); 1095 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
1096 Return(true)));
1074 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 1097 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
1075 1098
1076 scheduler()->ScheduleNudgeAsync( 1099 scheduler()->ScheduleNudgeAsync(
1077 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(BOOKMARKS), FROM_HERE); 1100 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(BOOKMARKS), FROM_HERE);
1078 PumpLoop(); 1101 PumpLoop();
1079 // Pump again to run job. 1102 // Pump again to run job.
1080 PumpLoop(); 1103 PumpLoop();
1081 1104
1082 StopSyncScheduler(); 1105 StopSyncScheduler();
1083 Mock::VerifyAndClearExpectations(syncer()); 1106 Mock::VerifyAndClearExpectations(syncer());
1084 1107
1085 // Configuration. 1108 // Configuration.
1086 EXPECT_CALL(*syncer(), SyncShare(_, DOWNLOAD_UPDATES, APPLY_UPDATES)) 1109 EXPECT_CALL(*syncer(), SyncShare(_, DOWNLOAD_UPDATES, APPLY_UPDATES))
1087 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)); 1110 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
1111 Return(true)));
1088 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 1112 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
1089 1113
1090 ModelTypeSet model_types(BOOKMARKS); 1114 ModelTypeSet model_types(BOOKMARKS);
1091 CallbackCounter counter; 1115 CallbackCounter counter;
1092 ConfigurationParams params( 1116 ConfigurationParams params(
1093 GetUpdatesCallerInfo::RECONFIGURATION, 1117 GetUpdatesCallerInfo::RECONFIGURATION,
1094 model_types, 1118 model_types,
1095 TypesToRoutingInfo(model_types), 1119 TypesToRoutingInfo(model_types),
1096 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); 1120 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter)));
1097 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params)); 1121 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params));
(...skipping 20 matching lines...) Expand all
1118 StopSyncScheduler(); 1142 StopSyncScheduler();
1119 Mock::VerifyAndClearExpectations(syncer()); 1143 Mock::VerifyAndClearExpectations(syncer());
1120 } 1144 }
1121 1145
1122 // Test that starting the syncer thread without a valid connection doesn't 1146 // Test that starting the syncer thread without a valid connection doesn't
1123 // break things when a connection is detected. 1147 // break things when a connection is detected.
1124 TEST_F(SyncSchedulerTest, StartWhenNotConnected) { 1148 TEST_F(SyncSchedulerTest, StartWhenNotConnected) {
1125 connection()->SetServerNotReachable(); 1149 connection()->SetServerNotReachable();
1126 connection()->UpdateConnectionStatus(); 1150 connection()->UpdateConnectionStatus();
1127 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 1151 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
1128 .WillOnce(Invoke(sessions::test_util::SimulateConnectionFailure)) 1152 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConnectionFailure),
1129 .WillOnce(QuitLoopNowAction()); 1153 Return(true)))
1154 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
1155 QuitLoopNowAction()));
1130 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 1156 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
1131 1157
1132 scheduler()->ScheduleNudgeAsync( 1158 scheduler()->ScheduleNudgeAsync(
1133 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(BOOKMARKS), FROM_HERE); 1159 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(BOOKMARKS), FROM_HERE);
1134 // Should save the nudge for until after the server is reachable. 1160 // Should save the nudge for until after the server is reachable.
1135 MessageLoop::current()->RunAllPending(); 1161 MessageLoop::current()->RunAllPending();
1136 1162
1137 connection()->SetServerReachable(); 1163 connection()->SetServerReachable();
1138 connection()->UpdateConnectionStatus(); 1164 connection()->UpdateConnectionStatus();
1139 scheduler()->OnConnectionStatusChange(); 1165 scheduler()->OnConnectionStatusChange();
1140 MessageLoop::current()->RunAllPending(); 1166 MessageLoop::current()->RunAllPending();
1141 } 1167 }
1142 1168
1143 } // namespace syncer 1169 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698