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

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

Issue 10791002: Finish commit 146665. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 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.cc ('k') | sync/engine/sync_scheduler_whitebox_unittest.cc » ('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.h" 9 #include "base/message_loop.h"
10 #include "base/test/test_timeouts.h" 10 #include "base/test/test_timeouts.h"
11 #include "sync/engine/sync_scheduler.h" 11 #include "sync/engine/sync_scheduler.h"
12 #include "sync/engine/syncer.h" 12 #include "sync/engine/syncer.h"
13 #include "sync/engine/throttled_data_type_tracker.h" 13 #include "sync/engine/throttled_data_type_tracker.h"
14 #include "sync/sessions/test_util.h" 14 #include "sync/sessions/test_util.h"
15 #include "sync/test/callback_counter.h"
15 #include "sync/test/engine/fake_model_worker.h" 16 #include "sync/test/engine/fake_model_worker.h"
16 #include "sync/test/engine/mock_connection_manager.h" 17 #include "sync/test/engine/mock_connection_manager.h"
17 #include "sync/test/engine/test_directory_setter_upper.h" 18 #include "sync/test/engine/test_directory_setter_upper.h"
18 #include "sync/test/fake_extensions_activity_monitor.h" 19 #include "sync/test/fake_extensions_activity_monitor.h"
19 #include "testing/gmock/include/gmock/gmock.h" 20 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
21 22
22 using base::TimeDelta; 23 using base::TimeDelta;
23 using base::TimeTicks; 24 using base::TimeTicks;
24 using testing::_; 25 using testing::_;
25 using testing::AtLeast; 26 using testing::AtLeast;
26 using testing::DoAll; 27 using testing::DoAll;
27 using testing::Eq; 28 using testing::Eq;
28 using testing::Invoke; 29 using testing::Invoke;
29 using testing::Mock; 30 using testing::Mock;
31 using testing::Not;
30 using testing::Return; 32 using testing::Return;
31 using testing::WithArg; 33 using testing::WithArg;
32 34
33 namespace syncer { 35 namespace syncer {
34 using sessions::SyncSession; 36 using sessions::SyncSession;
35 using sessions::SyncSessionContext; 37 using sessions::SyncSessionContext;
36 using sessions::SyncSessionSnapshot; 38 using sessions::SyncSessionSnapshot;
37 using sync_pb::GetUpdatesCallerInfo; 39 using sync_pb::GetUpdatesCallerInfo;
38 40
39 class MockSyncer : public Syncer { 41 class MockSyncer : public Syncer {
(...skipping 21 matching lines...) Expand all
61 } 63 }
62 64
63 void PumpLoop() { 65 void PumpLoop() {
64 // Do it this way instead of RunAllPending to pump loop exactly once 66 // Do it this way instead of RunAllPending to pump loop exactly once
65 // (necessary in the presence of timers; see comment in 67 // (necessary in the presence of timers; see comment in
66 // QuitLoopNow). 68 // QuitLoopNow).
67 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(&QuitLoopNow)); 69 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(&QuitLoopNow));
68 RunLoop(); 70 RunLoop();
69 } 71 }
70 72
73 ModelSafeRoutingInfo TypesToRoutingInfo(const ModelTypeSet& types) {
74 ModelSafeRoutingInfo routes;
75 for (ModelTypeSet::Iterator iter = types.First(); iter.Good(); iter.Inc()) {
76 routes[iter.Get()] = GROUP_PASSIVE;
77 }
78 return routes;
79 }
80
71 // Convenient to use in tests wishing to analyze SyncShare calls over time. 81 // Convenient to use in tests wishing to analyze SyncShare calls over time.
72 static const size_t kMinNumSamples = 5; 82 static const size_t kMinNumSamples = 5;
73 class SyncSchedulerTest : public testing::Test { 83 class SyncSchedulerTest : public testing::Test {
74 public: 84 public:
75 SyncSchedulerTest() 85 SyncSchedulerTest()
76 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 86 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
77 context_(NULL), 87 context_(NULL),
78 syncer_(NULL), 88 syncer_(NULL),
79 delay_(NULL) {} 89 delay_(NULL) {}
80 90
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 EXPECT_EQ(GetUpdatesCallerInfo::PERIODIC, 154 EXPECT_EQ(GetUpdatesCallerInfo::PERIODIC,
145 records.snapshots[i].source().updates_source); 155 records.snapshots[i].source().updates_source);
146 } 156 }
147 } 157 }
148 158
149 void DoQuitLoopNow() { 159 void DoQuitLoopNow() {
150 QuitLoopNow(); 160 QuitLoopNow();
151 } 161 }
152 162
153 void StartSyncScheduler(SyncScheduler::Mode mode) { 163 void StartSyncScheduler(SyncScheduler::Mode mode) {
154 scheduler()->Start(mode, base::Closure()); 164 scheduler()->Start(mode);
155 } 165 }
156 166
157 // This stops the scheduler synchronously. 167 // This stops the scheduler synchronously.
158 void StopSyncScheduler() { 168 void StopSyncScheduler() {
159 scheduler()->RequestStop(base::Bind(&SyncSchedulerTest::DoQuitLoopNow, 169 scheduler()->RequestStop(base::Bind(&SyncSchedulerTest::DoQuitLoopNow,
160 weak_ptr_factory_.GetWeakPtr())); 170 weak_ptr_factory_.GetWeakPtr()));
161 RunLoop(); 171 RunLoop();
162 } 172 }
163 173
164 bool RunAndGetBackoff() { 174 bool RunAndGetBackoff() {
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, 293 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL,
284 records2.snapshots[0].source().updates_source); 294 records2.snapshots[0].source().updates_source);
285 } 295 }
286 296
287 // Make sure a regular config command is scheduled fine in the absence of any 297 // Make sure a regular config command is scheduled fine in the absence of any
288 // errors. 298 // errors.
289 TEST_F(SyncSchedulerTest, Config) { 299 TEST_F(SyncSchedulerTest, Config) {
290 SyncShareRecords records; 300 SyncShareRecords records;
291 const ModelTypeSet model_types(syncer::BOOKMARKS); 301 const ModelTypeSet model_types(syncer::BOOKMARKS);
292 302
293 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 303 EXPECT_CALL(*syncer(),
304 SyncShare(_,_,_))
305 .WillOnce(Invoke(sessions::test_util::SimulateSuccess))
294 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 306 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
295 WithArg<0>(RecordSyncShare(&records)))); 307 WithArg<0>(RecordSyncShare(&records))));
296 308
297 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 309 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
298 310
299 scheduler()->ScheduleConfiguration( 311 CallbackCounter counter;
300 model_types, GetUpdatesCallerInfo::RECONFIGURATION); 312 ConfigurationParams params(
313 GetUpdatesCallerInfo::RECONFIGURATION,
314 model_types,
315 TypesToRoutingInfo(model_types),
316 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY,
317 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter)));
318 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params));
319 ASSERT_EQ(1, counter.times_called());
301 320
302 ASSERT_EQ(1U, records.snapshots.size()); 321 ASSERT_EQ(1U, records.snapshots.size());
303 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types, 322 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types,
304 records.snapshots[0].source().types)); 323 records.snapshots[0].source().types));
305 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, 324 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION,
306 records.snapshots[0].source().updates_source); 325 records.snapshots[0].source().updates_source);
307 } 326 }
308 327
309 // Simulate a failure and make sure the config request is retried. 328 // Simulate a failure and make sure the config request is retried.
310 TEST_F(SyncSchedulerTest, ConfigWithBackingOff) { 329 TEST_F(SyncSchedulerTest, ConfigWithBackingOff) {
311 UseMockDelayProvider(); 330 UseMockDelayProvider();
312 EXPECT_CALL(*delay(), GetDelay(_)) 331 EXPECT_CALL(*delay(), GetDelay(_))
313 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(1))); 332 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(1)));
314 SyncShareRecords records; 333 SyncShareRecords records;
315 const ModelTypeSet model_types(syncer::BOOKMARKS); 334 const ModelTypeSet model_types(syncer::BOOKMARKS);
316 335
317 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 336 EXPECT_CALL(*syncer(),
337 SyncShare(_,_,_))
338 .WillOnce(Invoke(sessions::test_util::SimulateSuccess))
318 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), 339 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed),
319 WithArg<0>(RecordSyncShare(&records)))) 340 WithArg<0>(RecordSyncShare(&records))))
320 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 341 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
321 WithArg<0>(RecordSyncShare(&records)))); 342 WithArg<0>(RecordSyncShare(&records))));
322 343
323 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 344 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
324 345
325 ASSERT_EQ(0U, records.snapshots.size()); 346 ASSERT_EQ(0U, records.snapshots.size());
326 scheduler()->ScheduleConfiguration( 347 CallbackCounter counter;
327 model_types, GetUpdatesCallerInfo::RECONFIGURATION); 348 ConfigurationParams params(
349 GetUpdatesCallerInfo::RECONFIGURATION,
350 model_types,
351 TypesToRoutingInfo(model_types),
352 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY,
353 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter)));
354 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params));
355 ASSERT_EQ(0, counter.times_called());
328 356
329 ASSERT_EQ(1U, records.snapshots.size()); 357 ASSERT_EQ(1U, records.snapshots.size());
330 RunLoop(); 358 RunLoop();
331 359
332 ASSERT_EQ(2U, records.snapshots.size()); 360 ASSERT_EQ(2U, records.snapshots.size());
361 ASSERT_EQ(1, counter.times_called());
333 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types, 362 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types,
334 records.snapshots[1].source().types)); 363 records.snapshots[1].source().types));
335 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, 364 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION,
336 records.snapshots[1].source().updates_source); 365 records.snapshots[1].source().updates_source);
337 } 366 }
338 367
339 // Issue 2 config commands. Second one right after the first has failed
340 // and make sure LATEST is executed.
341 TEST_F(SyncSchedulerTest, MultipleConfigWithBackingOff) {
342 const ModelTypeSet
343 model_types1(syncer::BOOKMARKS),
344 model_types2(syncer::AUTOFILL);
345 UseMockDelayProvider();
346 EXPECT_CALL(*delay(), GetDelay(_))
347 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(30)));
348 SyncShareRecords records;
349
350 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
351 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed),
352 WithArg<0>(RecordSyncShare(&records))))
353 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed),
354 WithArg<0>(RecordSyncShare(&records))))
355 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
356 WithArg<0>(RecordSyncShare(&records))));
357
358 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
359
360 ASSERT_EQ(0U, records.snapshots.size());
361 scheduler()->ScheduleConfiguration(
362 model_types1, GetUpdatesCallerInfo::RECONFIGURATION);
363
364 ASSERT_EQ(1U, records.snapshots.size());
365 scheduler()->ScheduleConfiguration(
366 model_types2, GetUpdatesCallerInfo::RECONFIGURATION);
367
368 // A canary job gets posted when we go into exponential backoff.
369 RunLoop();
370
371 ASSERT_EQ(2U, records.snapshots.size());
372 RunLoop();
373
374 ASSERT_EQ(3U, records.snapshots.size());
375 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types2,
376 records.snapshots[2].source().types));
377 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION,
378 records.snapshots[2].source().updates_source);
379 }
380
381 // Issue a nudge when the config has failed. Make sure both the config and 368 // Issue a nudge when the config has failed. Make sure both the config and
382 // nudge are executed. 369 // nudge are executed.
383 TEST_F(SyncSchedulerTest, NudgeWithConfigWithBackingOff) { 370 TEST_F(SyncSchedulerTest, NudgeWithConfigWithBackingOff) {
384 const ModelTypeSet model_types(syncer::BOOKMARKS); 371 const ModelTypeSet model_types(syncer::BOOKMARKS);
385 UseMockDelayProvider(); 372 UseMockDelayProvider();
386 EXPECT_CALL(*delay(), GetDelay(_)) 373 EXPECT_CALL(*delay(), GetDelay(_))
387 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(50))); 374 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(50)));
388 SyncShareRecords records; 375 SyncShareRecords records;
389 376
390 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 377 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
391 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), 378 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed),
392 WithArg<0>(RecordSyncShare(&records)))) 379 WithArg<0>(RecordSyncShare(&records))))
393 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), 380 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed),
394 WithArg<0>(RecordSyncShare(&records)))) 381 WithArg<0>(RecordSyncShare(&records))))
395 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 382 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
396 WithArg<0>(RecordSyncShare(&records)))) 383 WithArg<0>(RecordSyncShare(&records))))
397 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 384 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
398 WithArg<0>(RecordSyncShare(&records)))); 385 WithArg<0>(RecordSyncShare(&records))));
399 386
400 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 387 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
401 388
402 ASSERT_EQ(0U, records.snapshots.size()); 389 ASSERT_EQ(0U, records.snapshots.size());
403 scheduler()->ScheduleConfiguration( 390 CallbackCounter counter;
404 model_types, GetUpdatesCallerInfo::RECONFIGURATION); 391 ConfigurationParams params(
392 GetUpdatesCallerInfo::RECONFIGURATION,
393 model_types,
394 TypesToRoutingInfo(model_types),
395 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY,
396 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter)));
397 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params));
398 ASSERT_EQ(0, counter.times_called());
399 ASSERT_EQ(1U, records.snapshots.size());
405 400
406 ASSERT_EQ(1U, records.snapshots.size());
407 scheduler()->ScheduleNudgeAsync( 401 scheduler()->ScheduleNudgeAsync(
408 zero(), NUDGE_SOURCE_LOCAL, model_types, FROM_HERE); 402 zero(), NUDGE_SOURCE_LOCAL, model_types, FROM_HERE);
409 RunLoop(); 403 RunLoop();
404 ASSERT_EQ(2U, records.snapshots.size());
405 ASSERT_EQ(0, counter.times_called());
410 406
411 ASSERT_EQ(2U, records.snapshots.size());
412 RunLoop(); 407 RunLoop();
408 ASSERT_EQ(3U, records.snapshots.size());
409 ASSERT_EQ(1, counter.times_called());
413 410
414 // Now change the mode so nudge can execute. 411 // Now change the mode so nudge can execute.
415 ASSERT_EQ(3U, records.snapshots.size());
416 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 412 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
417 413
418 ASSERT_EQ(4U, records.snapshots.size()); 414 ASSERT_EQ(4U, records.snapshots.size());
419 415
420 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types, 416 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types,
421 records.snapshots[2].source().types)); 417 records.snapshots[2].source().types));
422 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, 418 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION,
423 records.snapshots[2].source().updates_source); 419 records.snapshots[2].source().updates_source);
424 420
425 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types, 421 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types,
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 QuitLoopNowAction())); 706 QuitLoopNowAction()));
711 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 707 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
712 708
713 scheduler()->ScheduleNudgeAsync( 709 scheduler()->ScheduleNudgeAsync(
714 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(), FROM_HERE); 710 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(), FROM_HERE);
715 711
716 // We should detect the failure on the second sync share, and go into backoff. 712 // We should detect the failure on the second sync share, and go into backoff.
717 EXPECT_TRUE(RunAndGetBackoff()); 713 EXPECT_TRUE(RunAndGetBackoff());
718 } 714 }
719 715
720 // Test that no syncing occurs when throttled. 716 // Test that no syncing occurs when throttled (although CleanupDisabledTypes
717 // is allowed).
721 TEST_F(SyncSchedulerTest, ThrottlingDoesThrottle) { 718 TEST_F(SyncSchedulerTest, ThrottlingDoesThrottle) {
722 const ModelTypeSet types(syncer::BOOKMARKS); 719 const ModelTypeSet types(syncer::BOOKMARKS);
723 TimeDelta poll(TimeDelta::FromMilliseconds(5)); 720 TimeDelta poll(TimeDelta::FromMilliseconds(5));
724 TimeDelta throttle(TimeDelta::FromMinutes(10)); 721 TimeDelta throttle(TimeDelta::FromMinutes(10));
725 scheduler()->OnReceivedLongPollIntervalUpdate(poll); 722 scheduler()->OnReceivedLongPollIntervalUpdate(poll);
726 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 723
724 EXPECT_CALL(*syncer(),
725 SyncShare(_, CLEANUP_DISABLED_TYPES, CLEANUP_DISABLED_TYPES))
726 .WillOnce(Invoke(sessions::test_util::SimulateSuccess));
727 EXPECT_CALL(*syncer(), SyncShare(_,Not(CLEANUP_DISABLED_TYPES),
728 Not(CLEANUP_DISABLED_TYPES)))
727 .WillOnce(WithArg<0>(sessions::test_util::SimulateThrottled(throttle))) 729 .WillOnce(WithArg<0>(sessions::test_util::SimulateThrottled(throttle)))
728 .WillRepeatedly(AddFailureAndQuitLoopNow()); 730 .WillRepeatedly(AddFailureAndQuitLoopNow());
729 731
730 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 732 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
731 733
732 scheduler()->ScheduleNudgeAsync( 734 scheduler()->ScheduleNudgeAsync(
733 zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE); 735 zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE);
734 PumpLoop(); 736 PumpLoop();
735 737
736 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 738 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
737 739
738 scheduler()->ScheduleConfiguration( 740 CallbackCounter counter;
739 types, GetUpdatesCallerInfo::RECONFIGURATION); 741 ConfigurationParams params(
742 GetUpdatesCallerInfo::RECONFIGURATION,
743 types,
744 TypesToRoutingInfo(types),
745 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY,
746 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter)));
747 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params));
748 ASSERT_EQ(0, counter.times_called());
740 } 749 }
741 750
742 TEST_F(SyncSchedulerTest, ThrottlingExpires) { 751 TEST_F(SyncSchedulerTest, ThrottlingExpires) {
743 SyncShareRecords records; 752 SyncShareRecords records;
744 TimeDelta poll(TimeDelta::FromMilliseconds(15)); 753 TimeDelta poll(TimeDelta::FromMilliseconds(15));
745 TimeDelta throttle1(TimeDelta::FromMilliseconds(150)); 754 TimeDelta throttle1(TimeDelta::FromMilliseconds(150));
746 scheduler()->OnReceivedLongPollIntervalUpdate(poll); 755 scheduler()->OnReceivedLongPollIntervalUpdate(poll);
747 756
748 ::testing::InSequence seq; 757 ::testing::InSequence seq;
749 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 758 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
(...skipping 12 matching lines...) Expand all
762 StopSyncScheduler(); 771 StopSyncScheduler();
763 AnalyzePollRun(records, kMinNumSamples, optimal_start, poll); 772 AnalyzePollRun(records, kMinNumSamples, optimal_start, poll);
764 } 773 }
765 774
766 // Test nudges / polls don't run in config mode and config tasks do. 775 // Test nudges / polls don't run in config mode and config tasks do.
767 TEST_F(SyncSchedulerTest, ConfigurationMode) { 776 TEST_F(SyncSchedulerTest, ConfigurationMode) {
768 TimeDelta poll(TimeDelta::FromMilliseconds(15)); 777 TimeDelta poll(TimeDelta::FromMilliseconds(15));
769 SyncShareRecords records; 778 SyncShareRecords records;
770 scheduler()->OnReceivedLongPollIntervalUpdate(poll); 779 scheduler()->OnReceivedLongPollIntervalUpdate(poll);
771 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 780 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
781 .WillOnce(Invoke(sessions::test_util::SimulateSuccess))
772 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 782 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
773 WithArg<0>(RecordSyncShare(&records)))); 783 WithArg<0>(RecordSyncShare(&records))));
774 784
775 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 785 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
776 786
777 const ModelTypeSet nudge_types(syncer::AUTOFILL); 787 const ModelTypeSet nudge_types(syncer::AUTOFILL);
778 scheduler()->ScheduleNudgeAsync( 788 scheduler()->ScheduleNudgeAsync(
779 zero(), NUDGE_SOURCE_LOCAL, nudge_types, FROM_HERE); 789 zero(), NUDGE_SOURCE_LOCAL, nudge_types, FROM_HERE);
780 scheduler()->ScheduleNudgeAsync( 790 scheduler()->ScheduleNudgeAsync(
781 zero(), NUDGE_SOURCE_LOCAL, nudge_types, FROM_HERE); 791 zero(), NUDGE_SOURCE_LOCAL, nudge_types, FROM_HERE);
782 792
783 const ModelTypeSet config_types(syncer::BOOKMARKS); 793 const ModelTypeSet config_types(syncer::BOOKMARKS);
784 794
785 scheduler()->ScheduleConfiguration( 795 CallbackCounter counter;
786 config_types, GetUpdatesCallerInfo::RECONFIGURATION); 796 ConfigurationParams params(
797 GetUpdatesCallerInfo::RECONFIGURATION,
798 config_types,
799 TypesToRoutingInfo(config_types),
800 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY,
801 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter)));
802 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params));
803 ASSERT_EQ(1, counter.times_called());
787 804
788 ASSERT_EQ(1U, records.snapshots.size()); 805 ASSERT_EQ(1U, records.snapshots.size());
789 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(config_types, 806 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(config_types,
790 records.snapshots[0].source().types)); 807 records.snapshots[0].source().types));
791 } 808 }
792 809
793 class BackoffTriggersSyncSchedulerTest : public SyncSchedulerTest { 810 class BackoffTriggersSyncSchedulerTest : public SyncSchedulerTest {
794 void SetUp() { 811 void SetUp() {
795 SyncSchedulerTest::SetUp(); 812 SyncSchedulerTest::SetUp();
796 UseMockDelayProvider(); 813 UseMockDelayProvider();
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
845 } 862 }
846 863
847 // Test that no polls or extraneous nudges occur when in backoff. 864 // Test that no polls or extraneous nudges occur when in backoff.
848 TEST_F(SyncSchedulerTest, BackoffDropsJobs) { 865 TEST_F(SyncSchedulerTest, BackoffDropsJobs) {
849 SyncShareRecords r; 866 SyncShareRecords r;
850 TimeDelta poll(TimeDelta::FromMilliseconds(5)); 867 TimeDelta poll(TimeDelta::FromMilliseconds(5));
851 const ModelTypeSet types(syncer::BOOKMARKS); 868 const ModelTypeSet types(syncer::BOOKMARKS);
852 scheduler()->OnReceivedLongPollIntervalUpdate(poll); 869 scheduler()->OnReceivedLongPollIntervalUpdate(poll);
853 UseMockDelayProvider(); 870 UseMockDelayProvider();
854 871
855 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(1) 872 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
856 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), 873 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateCommitFailed),
857 RecordSyncShareMultiple(&r, 1U))); 874 RecordSyncShareMultiple(&r, 1U)));
858 EXPECT_CALL(*delay(), GetDelay(_)). 875 EXPECT_CALL(*delay(), GetDelay(_)).
859 WillRepeatedly(Return(TimeDelta::FromDays(1))); 876 WillRepeatedly(Return(TimeDelta::FromDays(1)));
860 877
861 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 878 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
862 879
863 // This nudge should fail and put us into backoff. Thanks to our mock 880 // This nudge should fail and put us into backoff. Thanks to our mock
864 // GetDelay() setup above, this will be a long backoff. 881 // GetDelay() setup above, this will be a long backoff.
865 scheduler()->ScheduleNudgeAsync(zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE); 882 scheduler()->ScheduleNudgeAsync(zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE);
(...skipping 21 matching lines...) Expand all
887 r.snapshots[1].source().updates_source); 904 r.snapshots[1].source().updates_source);
888 905
889 // Cleanup is not affected by backoff, but it should not relieve it either. 906 // Cleanup is not affected by backoff, but it should not relieve it either.
890 EXPECT_CALL(*syncer(), 907 EXPECT_CALL(*syncer(),
891 SyncShare(_, CLEANUP_DISABLED_TYPES, CLEANUP_DISABLED_TYPES)) 908 SyncShare(_, CLEANUP_DISABLED_TYPES, CLEANUP_DISABLED_TYPES))
892 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)); 909 .WillOnce(Invoke(sessions::test_util::SimulateSuccess));
893 EXPECT_CALL(*delay(), GetDelay(_)).Times(0); 910 EXPECT_CALL(*delay(), GetDelay(_)).Times(0);
894 911
895 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 912 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
896 913
897 scheduler()->CleanupDisabledTypes(); 914 CallbackCounter counter;
898 scheduler()->ScheduleConfiguration( 915 ConfigurationParams params(
899 types, GetUpdatesCallerInfo::RECONFIGURATION); 916 GetUpdatesCallerInfo::RECONFIGURATION,
917 types,
918 TypesToRoutingInfo(types),
919 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY,
920 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter)));
921 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params));
922 ASSERT_EQ(0, counter.times_called());
900 923
901 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 924 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
902 925
903 scheduler()->ScheduleNudgeAsync( 926 scheduler()->ScheduleNudgeAsync(
904 zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE); 927 zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE);
905 scheduler()->ScheduleNudgeAsync( 928 scheduler()->ScheduleNudgeAsync(
906 zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE); 929 zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE);
907 PumpLoop(); 930 PumpLoop();
908 } 931 }
909 932
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
1048 1071
1049 scheduler()->ScheduleNudgeAsync( 1072 scheduler()->ScheduleNudgeAsync(
1050 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(), FROM_HERE); 1073 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(), FROM_HERE);
1051 PumpLoop(); 1074 PumpLoop();
1052 // Pump again to run job. 1075 // Pump again to run job.
1053 PumpLoop(); 1076 PumpLoop();
1054 1077
1055 StopSyncScheduler(); 1078 StopSyncScheduler();
1056 Mock::VerifyAndClearExpectations(syncer()); 1079 Mock::VerifyAndClearExpectations(syncer());
1057 1080
1081 // Configuration (always includes a cleanup disabled types).
1082 EXPECT_CALL(*syncer(),
1083 SyncShare(_, CLEANUP_DISABLED_TYPES, CLEANUP_DISABLED_TYPES))
1084 .WillOnce(Invoke(sessions::test_util::SimulateSuccess));
1058 EXPECT_CALL(*syncer(), SyncShare(_, DOWNLOAD_UPDATES, APPLY_UPDATES)) 1085 EXPECT_CALL(*syncer(), SyncShare(_, DOWNLOAD_UPDATES, APPLY_UPDATES))
1059 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)); 1086 .WillOnce(Invoke(sessions::test_util::SimulateSuccess));
1060 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 1087 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
1061 1088
1062 scheduler()->ScheduleConfiguration( 1089 syncer::ModelTypeSet model_types(syncer::BOOKMARKS);
1063 ModelTypeSet(), GetUpdatesCallerInfo::RECONFIGURATION); 1090 CallbackCounter counter;
1064 1091 ConfigurationParams params(
1092 GetUpdatesCallerInfo::RECONFIGURATION,
1093 model_types,
1094 TypesToRoutingInfo(model_types),
1095 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY,
1096 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter)));
1097 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params));
1098 ASSERT_EQ(1, counter.times_called());
1099 // Runs directly so no need to pump the loop.
1065 StopSyncScheduler(); 1100 StopSyncScheduler();
1066 Mock::VerifyAndClearExpectations(syncer()); 1101 Mock::VerifyAndClearExpectations(syncer());
1067 1102
1068 // Cleanup disabled types. 1103 // Cleanup disabled types. Because no types are being configured, we just
1104 // perform the cleanup.
1069 EXPECT_CALL(*syncer(), 1105 EXPECT_CALL(*syncer(),
1070 SyncShare(_, CLEANUP_DISABLED_TYPES, CLEANUP_DISABLED_TYPES)) 1106 SyncShare(_, CLEANUP_DISABLED_TYPES, CLEANUP_DISABLED_TYPES)).
1071 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)); 1107 WillOnce(Invoke(sessions::test_util::SimulateSuccess));
1072 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 1108 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
1073 1109
1074 scheduler()->CleanupDisabledTypes(); 1110 CallbackCounter counter2;
1075 1111 ConfigurationParams params2(
1112 GetUpdatesCallerInfo::RECONFIGURATION,
1113 ModelTypeSet(),
1114 ModelSafeRoutingInfo(),
1115 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY,
1116 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter2)));
1117 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params2));
1118 ASSERT_EQ(1, counter2.times_called());
1076 StopSyncScheduler(); 1119 StopSyncScheduler();
1077 Mock::VerifyAndClearExpectations(syncer()); 1120 Mock::VerifyAndClearExpectations(syncer());
1078 1121
1122 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
1123
1079 // Poll. 1124 // Poll.
1080 EXPECT_CALL(*syncer(), SyncShare(_, SYNCER_BEGIN, SYNCER_END)) 1125 EXPECT_CALL(*syncer(), SyncShare(_, SYNCER_BEGIN, SYNCER_END))
1081 .Times(AtLeast(1)) 1126 .Times(AtLeast(1))
1082 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess), 1127 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess),
1083 QuitLoopNowAction())); 1128 QuitLoopNowAction()));
1084 const TimeDelta poll(TimeDelta::FromMilliseconds(10)); 1129 const TimeDelta poll(TimeDelta::FromMilliseconds(10));
1085 scheduler()->OnReceivedLongPollIntervalUpdate(poll); 1130 scheduler()->OnReceivedLongPollIntervalUpdate(poll);
1086 1131
1087 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 1132 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
1088 1133
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1133 PumpLoop(); 1178 PumpLoop();
1134 // Pump again to run job. 1179 // Pump again to run job.
1135 PumpLoop(); 1180 PumpLoop();
1136 1181
1137 StopSyncScheduler(); 1182 StopSyncScheduler();
1138 1183
1139 EXPECT_TRUE(expected == context()->previous_session_routing_info()); 1184 EXPECT_TRUE(expected == context()->previous_session_routing_info());
1140 } 1185 }
1141 1186
1142 } // namespace syncer 1187 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/engine/sync_scheduler.cc ('k') | sync/engine/sync_scheduler_whitebox_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698