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

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

Issue 322333004: sync: Inject sync/'s dependency on invalidations (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 5 months 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
« no previous file with comments | « sync/engine/sync_scheduler_impl.cc ('k') | sync/internal_api/public/base/invalidation.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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"
11 #include "sync/engine/backoff_delay_provider.h" 11 #include "sync/engine/backoff_delay_provider.h"
12 #include "sync/engine/sync_scheduler_impl.h" 12 #include "sync/engine/sync_scheduler_impl.h"
13 #include "sync/engine/syncer.h" 13 #include "sync/engine/syncer.h"
14 #include "sync/internal_api/public/base/cancelation_signal.h" 14 #include "sync/internal_api/public/base/cancelation_signal.h"
15 #include "sync/internal_api/public/base/model_type_test_util.h" 15 #include "sync/internal_api/public/base/model_type_test_util.h"
16 #include "sync/notifier/invalidation_util.h" 16 #include "sync/notifier/invalidation_util.h"
17 #include "sync/notifier/object_id_invalidation_map.h" 17 #include "sync/notifier/object_id_invalidation_map.h"
18 #include "sync/sessions/test_util.h" 18 #include "sync/sessions/test_util.h"
19 #include "sync/test/callback_counter.h" 19 #include "sync/test/callback_counter.h"
20 #include "sync/test/engine/fake_model_worker.h" 20 #include "sync/test/engine/fake_model_worker.h"
21 #include "sync/test/engine/mock_connection_manager.h" 21 #include "sync/test/engine/mock_connection_manager.h"
22 #include "sync/test/engine/test_directory_setter_upper.h" 22 #include "sync/test/engine/test_directory_setter_upper.h"
23 #include "sync/test/mock_invalidation.h"
23 #include "sync/util/extensions_activity.h" 24 #include "sync/util/extensions_activity.h"
24 #include "testing/gmock/include/gmock/gmock.h" 25 #include "testing/gmock/include/gmock/gmock.h"
25 #include "testing/gtest/include/gtest/gtest.h" 26 #include "testing/gtest/include/gtest/gtest.h"
26 27
27 using base::TimeDelta; 28 using base::TimeDelta;
28 using base::TimeTicks; 29 using base::TimeTicks;
29 using testing::_; 30 using testing::_;
30 using testing::AtLeast; 31 using testing::AtLeast;
31 using testing::DoAll; 32 using testing::DoAll;
32 using testing::Invoke; 33 using testing::Invoke;
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 214
214 ModelTypeSet GetThrottledTypes() { 215 ModelTypeSet GetThrottledTypes() {
215 return scheduler_->nudge_tracker_.GetThrottledTypes(); 216 return scheduler_->nudge_tracker_.GetThrottledTypes();
216 } 217 }
217 218
218 base::TimeDelta GetRetryTimerDelay() { 219 base::TimeDelta GetRetryTimerDelay() {
219 EXPECT_TRUE(scheduler_->retry_timer_.IsRunning()); 220 EXPECT_TRUE(scheduler_->retry_timer_.IsRunning());
220 return scheduler_->retry_timer_.GetCurrentDelay(); 221 return scheduler_->retry_timer_.GetCurrentDelay();
221 } 222 }
222 223
224 static scoped_ptr<InvalidationInterface> BuildInvalidation(
225 int64 version,
226 const std::string& payload) {
227 return MockInvalidation::Build(version, payload)
228 .PassAs<InvalidationInterface>();
229 }
230
223 private: 231 private:
224 syncable::Directory* directory() { 232 syncable::Directory* directory() {
225 return dir_maker_.directory(); 233 return dir_maker_.directory();
226 } 234 }
227 235
228 base::MessageLoop loop_; 236 base::MessageLoop loop_;
229 TestDirectorySetterUpper dir_maker_; 237 TestDirectorySetterUpper dir_maker_;
230 CancelationSignal cancelation_signal_; 238 CancelationSignal cancelation_signal_;
231 scoped_ptr<MockConnectionManager> connection_; 239 scoped_ptr<MockConnectionManager> connection_;
232 scoped_ptr<ModelTypeRegistry> model_type_registry_; 240 scoped_ptr<ModelTypeRegistry> model_type_registry_;
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 ASSERT_EQ(1U, times.size()); 524 ASSERT_EQ(1U, times.size());
517 EXPECT_GE(times[0], min_time); 525 EXPECT_GE(times[0], min_time);
518 EXPECT_LE(times[0], max_time); 526 EXPECT_LE(times[0], max_time);
519 } 527 }
520 528
521 // Test nudge scheduling. 529 // Test nudge scheduling.
522 TEST_F(SyncSchedulerTest, NudgeWithStates) { 530 TEST_F(SyncSchedulerTest, NudgeWithStates) {
523 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 531 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
524 532
525 SyncShareTimes times1; 533 SyncShareTimes times1;
526 ObjectIdInvalidationMap invalidations1 =
527 BuildInvalidationMap(BOOKMARKS, 10, "test");
528 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) 534 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
529 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), 535 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess),
530 RecordSyncShare(&times1))) 536 RecordSyncShare(&times1)))
531 .RetiresOnSaturation(); 537 .RetiresOnSaturation();
532 scheduler()->ScheduleInvalidationNudge(zero(), invalidations1, FROM_HERE); 538 scheduler()->ScheduleInvalidationNudge(
539 zero(), BOOKMARKS, BuildInvalidation(10, "test"), FROM_HERE);
533 RunLoop(); 540 RunLoop();
534 541
535 Mock::VerifyAndClearExpectations(syncer()); 542 Mock::VerifyAndClearExpectations(syncer());
536 543
537 // Make sure a second, later, nudge is unaffected by first (no coalescing). 544 // Make sure a second, later, nudge is unaffected by first (no coalescing).
538 SyncShareTimes times2; 545 SyncShareTimes times2;
539 ObjectIdInvalidationMap invalidations2 =
540 BuildInvalidationMap(AUTOFILL, 10, "test2");
541 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) 546 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
542 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), 547 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess),
543 RecordSyncShare(&times2))); 548 RecordSyncShare(&times2)));
544 scheduler()->ScheduleInvalidationNudge(zero(), invalidations2, FROM_HERE); 549 scheduler()->ScheduleInvalidationNudge(
550 zero(), AUTOFILL, BuildInvalidation(10, "test2"), FROM_HERE);
545 RunLoop(); 551 RunLoop();
546 } 552 }
547 553
548 // Test that polling works as expected. 554 // Test that polling works as expected.
549 TEST_F(SyncSchedulerTest, Polling) { 555 TEST_F(SyncSchedulerTest, Polling) {
550 SyncShareTimes times; 556 SyncShareTimes times;
551 TimeDelta poll_interval(TimeDelta::FromMilliseconds(30)); 557 TimeDelta poll_interval(TimeDelta::FromMilliseconds(30));
552 EXPECT_CALL(*syncer(), PollSyncShare(_,_)).Times(AtLeast(kMinNumSamples)) 558 EXPECT_CALL(*syncer(), PollSyncShare(_,_)).Times(AtLeast(kMinNumSamples))
553 .WillRepeatedly( 559 .WillRepeatedly(
554 DoAll(Invoke(sessions::test_util::SimulatePollSuccess), 560 DoAll(Invoke(sessions::test_util::SimulatePollSuccess),
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
827 Return(true))) 833 Return(true)))
828 .RetiresOnSaturation(); 834 .RetiresOnSaturation();
829 835
830 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 836 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
831 scheduler()->ScheduleLocalNudge(zero(), throttled_types, FROM_HERE); 837 scheduler()->ScheduleLocalNudge(zero(), throttled_types, FROM_HERE);
832 PumpLoop(); // To get PerformDelayedNudge called. 838 PumpLoop(); // To get PerformDelayedNudge called.
833 PumpLoop(); // To get TrySyncSessionJob called 839 PumpLoop(); // To get TrySyncSessionJob called
834 EXPECT_TRUE(GetThrottledTypes().HasAll(throttled_types)); 840 EXPECT_TRUE(GetThrottledTypes().HasAll(throttled_types));
835 841
836 // Ignore invalidations for throttled types. 842 // Ignore invalidations for throttled types.
837 ObjectIdInvalidationMap invalidations = 843 scheduler()->ScheduleInvalidationNudge(
838 BuildInvalidationMap(BOOKMARKS, 10, "test"); 844 zero(), BOOKMARKS, BuildInvalidation(10, "test"), FROM_HERE);
839 scheduler()->ScheduleInvalidationNudge(zero(), invalidations, FROM_HERE);
840 PumpLoop(); 845 PumpLoop();
841 846
842 // Ignore refresh requests for throttled types. 847 // Ignore refresh requests for throttled types.
843 scheduler()->ScheduleLocalRefreshRequest(zero(), throttled_types, FROM_HERE); 848 scheduler()->ScheduleLocalRefreshRequest(zero(), throttled_types, FROM_HERE);
844 PumpLoop(); 849 PumpLoop();
845 850
846 Mock::VerifyAndClearExpectations(syncer()); 851 Mock::VerifyAndClearExpectations(syncer());
847 852
848 // Local nudges for non-throttled types will trigger a sync. 853 // Local nudges for non-throttled types will trigger a sync.
849 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) 854 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
(...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after
1384 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), 1389 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess),
1385 RecordSyncShare(&times))); 1390 RecordSyncShare(&times)));
1386 1391
1387 // Run to wait for retrying. 1392 // Run to wait for retrying.
1388 RunLoop(); 1393 RunLoop();
1389 1394
1390 StopSyncScheduler(); 1395 StopSyncScheduler();
1391 } 1396 }
1392 1397
1393 } // namespace syncer 1398 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/engine/sync_scheduler_impl.cc ('k') | sync/internal_api/public/base/invalidation.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698