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

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

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

Powered by Google App Engine
This is Rietveld 408576698