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

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: Rebase 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/engine/fake_model_worker.h" 14 #include "sync/test/engine/fake_model_worker.h"
15 #include "sync/test/engine/mock_connection_manager.h" 15 #include "sync/test/engine/mock_connection_manager.h"
16 #include "sync/test/engine/test_directory_setter_upper.h" 16 #include "sync/test/engine/test_directory_setter_upper.h"
17 #include "sync/test/fake_extensions_activity_monitor.h" 17 #include "sync/test/fake_extensions_activity_monitor.h"
18 #include "testing/gmock/include/gmock/gmock.h" 18 #include "testing/gmock/include/gmock/gmock.h"
19 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
20 20
21 using base::TimeDelta; 21 using base::TimeDelta;
22 using base::TimeTicks; 22 using base::TimeTicks;
23 using testing::_; 23 using testing::_;
24 using testing::AtLeast; 24 using testing::AtLeast;
25 using testing::DoAll; 25 using testing::DoAll;
26 using testing::Eq; 26 using testing::Eq;
27 using testing::Invoke; 27 using testing::Invoke;
28 using testing::Mock; 28 using testing::Mock;
29 using testing::Not;
29 using testing::Return; 30 using testing::Return;
30 using testing::WithArg; 31 using testing::WithArg;
31 32
32 namespace browser_sync { 33 namespace browser_sync {
33 using sessions::SyncSession; 34 using sessions::SyncSession;
34 using sessions::SyncSessionContext; 35 using sessions::SyncSessionContext;
35 using sessions::SyncSessionSnapshot; 36 using sessions::SyncSessionSnapshot;
36 using syncable::ModelTypeSet; 37 using syncable::ModelTypeSet;
37 using sync_pb::GetUpdatesCallerInfo; 38 using sync_pb::GetUpdatesCallerInfo;
38 39
(...skipping 22 matching lines...) Expand all
61 } 62 }
62 63
63 void PumpLoop() { 64 void PumpLoop() {
64 // Do it this way instead of RunAllPending to pump loop exactly once 65 // Do it this way instead of RunAllPending to pump loop exactly once
65 // (necessary in the presence of timers; see comment in 66 // (necessary in the presence of timers; see comment in
66 // QuitLoopNow). 67 // QuitLoopNow).
67 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(&QuitLoopNow)); 68 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(&QuitLoopNow));
68 RunLoop(); 69 RunLoop();
69 } 70 }
70 71
72 void SetBool(bool* flag) {
rlarocque 2012/06/09 01:44:35 Could you do this with mocks instead? This looks
Nicolas Zea 2012/06/11 23:05:20 Given that we pass in a callback, not an object, I
rlarocque 2012/06/12 17:45:13 You have a point that the mock framework is probab
Nicolas Zea 2012/06/12 20:44:44 Done.
73 *flag = true;
74 }
75
76 ModelSafeRoutingInfo TypesToRoutingInfo(const ModelTypeSet& types) {
77 ModelSafeRoutingInfo routes;
78 for (ModelTypeSet::Iterator iter = types.First(); iter.Good(); iter.Inc()) {
79 routes[iter.Get()] = GROUP_PASSIVE;
80 }
81 return routes;
82 }
83
71 // Convenient to use in tests wishing to analyze SyncShare calls over time. 84 // Convenient to use in tests wishing to analyze SyncShare calls over time.
72 static const size_t kMinNumSamples = 5; 85 static const size_t kMinNumSamples = 5;
73 class SyncSchedulerTest : public testing::Test { 86 class SyncSchedulerTest : public testing::Test {
74 public: 87 public:
75 SyncSchedulerTest() 88 SyncSchedulerTest()
76 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 89 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
77 context_(NULL), 90 context_(NULL),
78 syncer_(NULL), 91 syncer_(NULL),
79 delay_(NULL) {} 92 delay_(NULL) {}
80 93
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 EXPECT_EQ(GetUpdatesCallerInfo::PERIODIC, 156 EXPECT_EQ(GetUpdatesCallerInfo::PERIODIC,
144 records.snapshots[i].source().updates_source); 157 records.snapshots[i].source().updates_source);
145 } 158 }
146 } 159 }
147 160
148 void DoQuitLoopNow() { 161 void DoQuitLoopNow() {
149 QuitLoopNow(); 162 QuitLoopNow();
150 } 163 }
151 164
152 void StartSyncScheduler(SyncScheduler::Mode mode) { 165 void StartSyncScheduler(SyncScheduler::Mode mode) {
153 scheduler()->Start(mode, base::Closure()); 166 scheduler()->Start(mode);
154 } 167 }
155 168
156 // This stops the scheduler synchronously. 169 // This stops the scheduler synchronously.
157 void StopSyncScheduler() { 170 void StopSyncScheduler() {
158 scheduler()->RequestStop(base::Bind(&SyncSchedulerTest::DoQuitLoopNow, 171 scheduler()->RequestStop(base::Bind(&SyncSchedulerTest::DoQuitLoopNow,
159 weak_ptr_factory_.GetWeakPtr())); 172 weak_ptr_factory_.GetWeakPtr()));
160 RunLoop(); 173 RunLoop();
161 } 174 }
162 175
163 bool RunAndGetBackoff() { 176 bool RunAndGetBackoff() {
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, 294 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL,
282 records2.snapshots[0].source().updates_source); 295 records2.snapshots[0].source().updates_source);
283 } 296 }
284 297
285 // Make sure a regular config command is scheduled fine in the absence of any 298 // Make sure a regular config command is scheduled fine in the absence of any
286 // errors. 299 // errors.
287 TEST_F(SyncSchedulerTest, Config) { 300 TEST_F(SyncSchedulerTest, Config) {
288 SyncShareRecords records; 301 SyncShareRecords records;
289 const ModelTypeSet model_types(syncable::BOOKMARKS); 302 const ModelTypeSet model_types(syncable::BOOKMARKS);
290 303
291 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 304 EXPECT_CALL(*syncer(),
305 SyncShare(_,_,_))
306 .WillOnce(Invoke(sessions::test_util::SimulateSuccess))
292 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 307 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
293 WithArg<0>(RecordSyncShare(&records)))); 308 WithArg<0>(RecordSyncShare(&records))));
294 309
295 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 310 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
296 311
297 scheduler()->Configure( 312 bool callback_called = false;
298 model_types, GetUpdatesCallerInfo::RECONFIGURATION); 313 ConfigureParams params(
314 GetUpdatesCallerInfo::RECONFIGURATION,
315 model_types,
316 TypesToRoutingInfo(model_types),
317 false,
318 base::Bind(&SetBool, &callback_called));
319 ASSERT_TRUE(scheduler()->Configure(params));
320 ASSERT_TRUE(callback_called);
299 321
300 ASSERT_EQ(1U, records.snapshots.size()); 322 ASSERT_EQ(1U, records.snapshots.size());
301 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types, 323 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types,
302 records.snapshots[0].source().types)); 324 records.snapshots[0].source().types));
303 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, 325 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION,
304 records.snapshots[0].source().updates_source); 326 records.snapshots[0].source().updates_source);
305 } 327 }
306 328
307 // Simulate a failure and make sure the config request is retried. 329 // Simulate a failure and make sure the config request is retried.
308 TEST_F(SyncSchedulerTest, ConfigWithBackingOff) { 330 TEST_F(SyncSchedulerTest, ConfigWithBackingOff) {
309 UseMockDelayProvider(); 331 UseMockDelayProvider();
310 EXPECT_CALL(*delay(), GetDelay(_)) 332 EXPECT_CALL(*delay(), GetDelay(_))
311 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(1))); 333 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(1)));
312 SyncShareRecords records; 334 SyncShareRecords records;
313 const ModelTypeSet model_types(syncable::BOOKMARKS); 335 const ModelTypeSet model_types(syncable::BOOKMARKS);
314 336
315 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 337 EXPECT_CALL(*syncer(),
338 SyncShare(_,_,_))
339 .WillOnce(Invoke(sessions::test_util::SimulateSuccess))
316 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), 340 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed),
rlarocque 2012/06/09 01:44:35 I disagree with the use of SimulateCommitFailed he
Nicolas Zea 2012/06/11 23:05:20 This change is large enough, I'd rather leave it a
317 WithArg<0>(RecordSyncShare(&records)))) 341 WithArg<0>(RecordSyncShare(&records))))
318 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 342 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
319 WithArg<0>(RecordSyncShare(&records)))); 343 WithArg<0>(RecordSyncShare(&records))));
320 344
321 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 345 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
322 346
323 ASSERT_EQ(0U, records.snapshots.size()); 347 ASSERT_EQ(0U, records.snapshots.size());
324 scheduler()->Configure( 348 bool callback_called = false;
325 model_types, GetUpdatesCallerInfo::RECONFIGURATION); 349 ConfigureParams params(
350 GetUpdatesCallerInfo::RECONFIGURATION,
351 model_types,
352 TypesToRoutingInfo(model_types),
353 false,
354 base::Bind(&SetBool, &callback_called));
355 ASSERT_FALSE(scheduler()->Configure(params));
326 356
rlarocque 2012/06/09 01:44:35 ASSERT_FALSE(callback_called) here? See also the
Nicolas Zea 2012/06/11 23:05:20 Done.
327 ASSERT_EQ(1U, records.snapshots.size()); 357 ASSERT_EQ(1U, records.snapshots.size());
328 RunLoop(); 358 RunLoop();
329 359
330 ASSERT_EQ(2U, records.snapshots.size()); 360 ASSERT_EQ(2U, records.snapshots.size());
361 ASSERT_TRUE(callback_called);
331 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types, 362 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types,
332 records.snapshots[1].source().types)); 363 records.snapshots[1].source().types));
333 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, 364 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION,
334 records.snapshots[1].source().updates_source); 365 records.snapshots[1].source().updates_source);
335 } 366 }
336 367
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()->Configure(
360 model_types1, GetUpdatesCallerInfo::RECONFIGURATION);
361
362 ASSERT_EQ(1U, records.snapshots.size());
363 scheduler()->Configure(
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 368 // Issue a nudge when the config has failed. Make sure both the config and
380 // nudge are executed. 369 // nudge are executed.
381 TEST_F(SyncSchedulerTest, NudgeWithConfigWithBackingOff) { 370 TEST_F(SyncSchedulerTest, NudgeWithConfigWithBackingOff) {
382 const ModelTypeSet model_types(syncable::BOOKMARKS); 371 const ModelTypeSet model_types(syncable::BOOKMARKS);
383 UseMockDelayProvider(); 372 UseMockDelayProvider();
384 EXPECT_CALL(*delay(), GetDelay(_)) 373 EXPECT_CALL(*delay(), GetDelay(_))
385 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(50))); 374 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(50)));
386 SyncShareRecords records; 375 SyncShareRecords records;
387 376
388 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 377 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
389 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), 378 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed),
390 WithArg<0>(RecordSyncShare(&records)))) 379 WithArg<0>(RecordSyncShare(&records))))
391 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), 380 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed),
392 WithArg<0>(RecordSyncShare(&records)))) 381 WithArg<0>(RecordSyncShare(&records))))
393 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 382 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
394 WithArg<0>(RecordSyncShare(&records)))) 383 WithArg<0>(RecordSyncShare(&records))))
395 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 384 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
396 WithArg<0>(RecordSyncShare(&records)))); 385 WithArg<0>(RecordSyncShare(&records))));
397 386
398 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 387 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
399 388
400 ASSERT_EQ(0U, records.snapshots.size()); 389 ASSERT_EQ(0U, records.snapshots.size());
401 scheduler()->Configure( 390 bool callback_called = false;
402 model_types, GetUpdatesCallerInfo::RECONFIGURATION); 391 ConfigureParams params(
392 GetUpdatesCallerInfo::RECONFIGURATION,
393 model_types,
394 TypesToRoutingInfo(model_types),
395 false,
396 base::Bind(&SetBool, &callback_called));
397 ASSERT_FALSE(scheduler()->Configure(params));
403 398
404 ASSERT_EQ(1U, records.snapshots.size()); 399 ASSERT_EQ(1U, records.snapshots.size());
405 scheduler()->ScheduleNudge( 400 scheduler()->ScheduleNudge(
406 zero(), NUDGE_SOURCE_LOCAL, model_types, FROM_HERE); 401 zero(), NUDGE_SOURCE_LOCAL, model_types, FROM_HERE);
407 RunLoop(); 402 RunLoop();
408 403
409 ASSERT_EQ(2U, records.snapshots.size()); 404 ASSERT_EQ(2U, records.snapshots.size());
rlarocque 2012/06/09 01:44:35 Could you ASSERT_FALSE(callback_called) here? I t
Nicolas Zea 2012/06/11 23:05:20 Done. I think the snapshot size is still a useful
410 RunLoop(); 405 RunLoop();
411 406
412 // Now change the mode so nudge can execute. 407 // Now change the mode so nudge can execute.
408 ASSERT_TRUE(callback_called);
413 ASSERT_EQ(3U, records.snapshots.size()); 409 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
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 TimeDelta poll_interval(TimeDelta::FromMilliseconds(30)); 593 TimeDelta poll_interval(TimeDelta::FromMilliseconds(30));
598 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(AtLeast(kMinNumSamples)) 594 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(AtLeast(kMinNumSamples))
599 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess), 595 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess),
600 WithArg<0>(RecordSyncShareMultiple(&records, kMinNumSamples)))); 596 WithArg<0>(RecordSyncShareMultiple(&records, kMinNumSamples))));
601 597
602 scheduler()->OnReceivedLongPollIntervalUpdate(poll_interval); 598 scheduler()->OnReceivedLongPollIntervalUpdate(poll_interval);
603 599
604 TimeTicks optimal_start = TimeTicks::Now() + poll_interval; 600 TimeTicks optimal_start = TimeTicks::Now() + poll_interval;
605 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 601 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
606 602
607 // Run again to wait for polling. 603 // Runn again to wait for polling.
rlarocque 2012/06/09 01:44:35 typo.
Nicolas Zea 2012/06/11 23:05:20 Done.
608 RunLoop(); 604 RunLoop();
609 605
610 StopSyncScheduler(); 606 StopSyncScheduler();
611 AnalyzePollRun(records, kMinNumSamples, optimal_start, poll_interval); 607 AnalyzePollRun(records, kMinNumSamples, optimal_start, poll_interval);
612 } 608 }
613 609
614 // Test that the short poll interval is used. 610 // Test that the short poll interval is used.
615 TEST_F(SyncSchedulerTest, PollNotificationsDisabled) { 611 TEST_F(SyncSchedulerTest, PollNotificationsDisabled) {
616 SyncShareRecords records; 612 SyncShareRecords records;
617 TimeDelta poll_interval(TimeDelta::FromMilliseconds(30)); 613 TimeDelta poll_interval(TimeDelta::FromMilliseconds(30));
(...skipping 90 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()->ScheduleNudge( 707 scheduler()->ScheduleNudge(
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()->ScheduleNudge( 732 scheduler()->ScheduleNudge(
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()->Configure( 738 bool callback_called = false;
737 types, GetUpdatesCallerInfo::RECONFIGURATION); 739 ConfigureParams params(
740 GetUpdatesCallerInfo::RECONFIGURATION,
741 types,
742 TypesToRoutingInfo(types),
743 false,
744 base::Bind(&SetBool, &callback_called));
745 ASSERT_FALSE(scheduler()->Configure(params));
746 ASSERT_FALSE(callback_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(_,_,_))
748 .WillOnce(WithArg<0>(sessions::test_util::SimulateThrottled(throttle1))) 757 .WillOnce(WithArg<0>(sessions::test_util::SimulateThrottled(throttle1)))
749 .RetiresOnSaturation(); 758 .RetiresOnSaturation();
750 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 759 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
751 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess), 760 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess),
752 WithArg<0>(RecordSyncShareMultiple(&records, kMinNumSamples)))); 761 WithArg<0>(RecordSyncShareMultiple(&records, kMinNumSamples))));
753 762
754 TimeTicks optimal_start = TimeTicks::Now() + poll + throttle1; 763 TimeTicks optimal_start = TimeTicks::Now() + poll + throttle1;
755 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 764 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
756 765
757 // Run again to wait for polling. 766 // Runn again to wait for polling.
rlarocque 2012/06/09 01:44:35 typo.
Nicolas Zea 2012/06/11 23:05:20 Done.
758 RunLoop(); 767 RunLoop();
759 768
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))
rlarocque 2012/06/09 01:44:35 Why make the first invocation of SyncShare special
Nicolas Zea 2012/06/11 23:05:20 This is getting removed altogether in a later patc
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()->ScheduleNudge( 786 scheduler()->ScheduleNudge(
777 zero(), NUDGE_SOURCE_LOCAL, nudge_types, FROM_HERE); 787 zero(), NUDGE_SOURCE_LOCAL, nudge_types, FROM_HERE);
778 scheduler()->ScheduleNudge( 788 scheduler()->ScheduleNudge(
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()->Configure( 793 bool callback_called = false;
784 config_types, GetUpdatesCallerInfo::RECONFIGURATION); 794 ConfigureParams params(
795 GetUpdatesCallerInfo::RECONFIGURATION,
796 config_types,
797 TypesToRoutingInfo(config_types),
798 false,
799 base::Bind(&SetBool, &callback_called));
800 ASSERT_TRUE(scheduler()->Configure(params));
801 ASSERT_TRUE(callback_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(),
rlarocque 2012/06/09 01:44:35 This indentation looks strange. Could you move th
Nicolas Zea 2012/06/11 23:05:20 Done.
871 SyncShare(_,_,_))
854 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), 872 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateCommitFailed),
855 RecordSyncShareMultiple(&r, 1U))); 873 RecordSyncShareMultiple(&r, 1U)));
856 EXPECT_CALL(*delay(), GetDelay(_)). 874 EXPECT_CALL(*delay(), GetDelay(_)).
857 WillRepeatedly(Return(TimeDelta::FromDays(1))); 875 WillRepeatedly(Return(TimeDelta::FromDays(1)));
858 876
859 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 877 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
860 878
861 // This nudge should fail and put us into backoff. Thanks to our mock 879 // This nudge should fail and put us into backoff. Thanks to our mock
862 // GetDelay() setup above, this will be a long backoff. 880 // GetDelay() setup above, this will be a long backoff.
863 scheduler()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE); 881 scheduler()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE);
(...skipping 20 matching lines...) Expand all
884 r.snapshots[1].source().updates_source); 902 r.snapshots[1].source().updates_source);
885 903
886 // 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.
887 EXPECT_CALL(*syncer(), 905 EXPECT_CALL(*syncer(),
888 SyncShare(_, CLEANUP_DISABLED_TYPES, CLEANUP_DISABLED_TYPES)) 906 SyncShare(_, CLEANUP_DISABLED_TYPES, CLEANUP_DISABLED_TYPES))
889 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)); 907 .WillOnce(Invoke(sessions::test_util::SimulateSuccess));
890 EXPECT_CALL(*delay(), GetDelay(_)).Times(0); 908 EXPECT_CALL(*delay(), GetDelay(_)).Times(0);
891 909
892 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 910 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
893 911
894 scheduler()->CleanupDisabledTypes(); 912 bool callback_called = false;
895 scheduler()->Configure( 913 ConfigureParams params(
896 types, GetUpdatesCallerInfo::RECONFIGURATION); 914 GetUpdatesCallerInfo::RECONFIGURATION,
915 types,
916 TypesToRoutingInfo(types),
917 false,
918 base::Bind(&SetBool, &callback_called));
919 ASSERT_FALSE(scheduler()->Configure(params));
920 ASSERT_FALSE(callback_called);
897 921
898 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 922 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
899 923
900 scheduler()->ScheduleNudge( 924 scheduler()->ScheduleNudge(
901 zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE); 925 zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE);
902 scheduler()->ScheduleNudge( 926 scheduler()->ScheduleNudge(
903 zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE); 927 zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE);
904 PumpLoop(); 928 PumpLoop();
905 } 929 }
906 930
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
1055 // ClearUserData. 1079 // ClearUserData.
1056 EXPECT_CALL(*syncer(), SyncShare(_, CLEAR_PRIVATE_DATA, CLEAR_PRIVATE_DATA)) 1080 EXPECT_CALL(*syncer(), SyncShare(_, CLEAR_PRIVATE_DATA, CLEAR_PRIVATE_DATA))
1057 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)); 1081 .WillOnce(Invoke(sessions::test_util::SimulateSuccess));
1058 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 1082 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
1059 1083
1060 scheduler()->ClearUserData(); 1084 scheduler()->ClearUserData();
1061 1085
1062 StopSyncScheduler(); 1086 StopSyncScheduler();
1063 Mock::VerifyAndClearExpectations(syncer()); 1087 Mock::VerifyAndClearExpectations(syncer());
1064 1088
1065 // 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));
1066 EXPECT_CALL(*syncer(), SyncShare(_, DOWNLOAD_UPDATES, APPLY_UPDATES)) 1093 EXPECT_CALL(*syncer(), SyncShare(_, DOWNLOAD_UPDATES, APPLY_UPDATES))
1067 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)); 1094 .WillOnce(Invoke(sessions::test_util::SimulateSuccess));
1068 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 1095 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
1069 1096
1070 scheduler()->Configure( 1097 syncable::ModelTypeSet model_types(syncable::BOOKMARKS);
1071 ModelTypeSet(), GetUpdatesCallerInfo::RECONFIGURATION); 1098 bool callback_called = false;
1072 1099 ConfigureParams params(
1100 GetUpdatesCallerInfo::RECONFIGURATION,
1101 model_types,
1102 TypesToRoutingInfo(model_types),
1103 false,
1104 base::Bind(&SetBool, &callback_called));
1105 ASSERT_TRUE(scheduler()->Configure(params));
1106 // Runs directly so no need to pump the loop.
1073 StopSyncScheduler(); 1107 StopSyncScheduler();
1074 Mock::VerifyAndClearExpectations(syncer()); 1108 Mock::VerifyAndClearExpectations(syncer());
1109 ASSERT_TRUE(callback_called);
1075 1110
1076 // Cleanup disabled types. 1111 // Cleanup disabled types. Because no types are being configured, we just
1112 // perform the cleanup.
1077 EXPECT_CALL(*syncer(), 1113 EXPECT_CALL(*syncer(),
1078 SyncShare(_, CLEANUP_DISABLED_TYPES, CLEANUP_DISABLED_TYPES)) 1114 SyncShare(_, CLEANUP_DISABLED_TYPES, CLEANUP_DISABLED_TYPES)).
1079 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)); 1115 WillOnce(Invoke(sessions::test_util::SimulateSuccess));
1080 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 1116 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
1081 1117
1082 scheduler()->CleanupDisabledTypes(); 1118 bool callback2_called = false;
1083 1119 ConfigureParams params2(
1120 GetUpdatesCallerInfo::RECONFIGURATION,
1121 ModelTypeSet(),
1122 ModelSafeRoutingInfo(),
1123 false,
1124 base::Bind(&SetBool, &callback2_called));
1125 ASSERT_TRUE(scheduler()->Configure(params2));
1084 StopSyncScheduler(); 1126 StopSyncScheduler();
1085 Mock::VerifyAndClearExpectations(syncer()); 1127 Mock::VerifyAndClearExpectations(syncer());
1128 ASSERT_TRUE(callback2_called);
1129
1130 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
1086 1131
1087 // Poll. 1132 // Poll.
1088 EXPECT_CALL(*syncer(), SyncShare(_, SYNCER_BEGIN, SYNCER_END)) 1133 EXPECT_CALL(*syncer(), SyncShare(_, SYNCER_BEGIN, SYNCER_END))
1089 .Times(AtLeast(1)) 1134 .Times(AtLeast(1))
1090 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess), 1135 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess),
1091 QuitLoopNowAction())); 1136 QuitLoopNowAction()));
1092 const TimeDelta poll(TimeDelta::FromMilliseconds(10)); 1137 const TimeDelta poll(TimeDelta::FromMilliseconds(10));
1093 scheduler()->OnReceivedLongPollIntervalUpdate(poll); 1138 scheduler()->OnReceivedLongPollIntervalUpdate(poll);
1094 1139
1095 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 1140 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1141 PumpLoop(); 1186 PumpLoop();
1142 // Pump again to run job. 1187 // Pump again to run job.
1143 PumpLoop(); 1188 PumpLoop();
1144 1189
1145 StopSyncScheduler(); 1190 StopSyncScheduler();
1146 1191
1147 EXPECT_TRUE(expected == context()->previous_session_routing_info()); 1192 EXPECT_TRUE(expected == context()->previous_session_routing_info());
1148 } 1193 }
1149 1194
1150 } // namespace browser_sync 1195 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698