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

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

Issue 15764010: Experimental functionize patch (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync: Expose sync functionality as functions Created 7 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
« no previous file with comments | « sync/engine/sync_scheduler_impl.cc ('k') | sync/engine/syncer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/bind.h" 5 #include "base/bind.h"
6 #include "base/callback.h" 6 #include "base/callback.h"
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/memory/weak_ptr.h" 8 #include "base/memory/weak_ptr.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/test/test_timeouts.h" 10 #include "base/test/test_timeouts.h"
(...skipping 14 matching lines...) Expand all
25 using base::TimeTicks; 25 using base::TimeTicks;
26 using testing::_; 26 using testing::_;
27 using testing::AtLeast; 27 using testing::AtLeast;
28 using testing::DoAll; 28 using testing::DoAll;
29 using testing::Eq; 29 using testing::Eq;
30 using testing::Invoke; 30 using testing::Invoke;
31 using testing::Mock; 31 using testing::Mock;
32 using testing::Not; 32 using testing::Not;
33 using testing::Return; 33 using testing::Return;
34 using testing::WithArg; 34 using testing::WithArg;
35 using testing::WithArgs;
35 36
36 namespace syncer { 37 namespace syncer {
37 using sessions::SyncSession; 38 using sessions::SyncSession;
38 using sessions::SyncSessionContext; 39 using sessions::SyncSessionContext;
39 using sessions::SyncSessionSnapshot; 40 using sessions::SyncSessionSnapshot;
40 using sync_pb::GetUpdatesCallerInfo; 41 using sync_pb::GetUpdatesCallerInfo;
41 42
42 class MockSyncer : public Syncer { 43 class MockSyncer : public Syncer {
43 public: 44 public:
44 MOCK_METHOD3(SyncShare, bool(sessions::SyncSession*, SyncerStep, 45 MOCK_METHOD3(NormalSyncShare, bool(sessions::SyncSession*,
45 SyncerStep)); 46 ModelTypeSet,
47 const sessions::NudgeTracker&));
48 MOCK_METHOD2(ConfigureSyncShare, bool(sessions::SyncSession*, ModelTypeSet));
49 MOCK_METHOD2(PollSyncShare, bool(sessions::SyncSession*, ModelTypeSet));
46 }; 50 };
47 51
48 // Used when tests want to record syncing activity to examine later. 52 // Used when tests want to record syncing activity to examine later.
49 struct SyncShareRecords { 53 struct SyncShareRecords {
50 std::vector<TimeTicks> times; 54 std::vector<TimeTicks> times;
51 std::vector<SyncSessionSnapshot> snapshots; 55 std::vector<SyncSessionSnapshot> snapshots;
52 }; 56 };
53 57
54 void QuitLoopNow() { 58 void QuitLoopNow() {
55 // We use QuitNow() instead of Quit() as the latter may get stalled 59 // We use QuitNow() instead of Quit() as the latter may get stalled
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 ACTION(QuitLoopNowAction) { 276 ACTION(QuitLoopNowAction) {
273 QuitLoopNow(); 277 QuitLoopNow();
274 return true; 278 return true;
275 } 279 }
276 280
277 // Test nudge scheduling. 281 // Test nudge scheduling.
278 TEST_F(SyncSchedulerTest, Nudge) { 282 TEST_F(SyncSchedulerTest, Nudge) {
279 SyncShareRecords records; 283 SyncShareRecords records;
280 ModelTypeSet model_types(BOOKMARKS); 284 ModelTypeSet model_types(BOOKMARKS);
281 285
282 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 286 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
283 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 287 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess),
284 WithArg<0>(RecordSyncShare(&records)))) 288 WithArg<0>(RecordSyncShare(&records))))
285 .RetiresOnSaturation(); 289 .RetiresOnSaturation();
286 290
287 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 291 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
288 292
289 scheduler()->ScheduleLocalNudge(zero(), model_types, FROM_HERE); 293 scheduler()->ScheduleLocalNudge(zero(), model_types, FROM_HERE);
290 RunLoop(); 294 RunLoop();
291 295
292 ASSERT_EQ(1U, records.snapshots.size()); 296 ASSERT_EQ(1U, records.snapshots.size());
293 EXPECT_TRUE(ModelTypeSetMatchesInvalidationMap( 297 EXPECT_TRUE(ModelTypeSetMatchesInvalidationMap(
294 model_types, 298 model_types,
295 records.snapshots[0].source().types)); 299 records.snapshots[0].source().types));
296 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, 300 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL,
297 records.snapshots[0].source().updates_source); 301 records.snapshots[0].source().updates_source);
298 302
299 Mock::VerifyAndClearExpectations(syncer()); 303 Mock::VerifyAndClearExpectations(syncer());
300 304
301 // Make sure a second, later, nudge is unaffected by first (no coalescing). 305 // Make sure a second, later, nudge is unaffected by first (no coalescing).
302 SyncShareRecords records2; 306 SyncShareRecords records2;
303 model_types.Remove(BOOKMARKS); 307 model_types.Remove(BOOKMARKS);
304 model_types.Put(AUTOFILL); 308 model_types.Put(AUTOFILL);
305 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 309 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
306 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 310 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess),
307 WithArg<0>(RecordSyncShare(&records2)))); 311 WithArg<0>(RecordSyncShare(&records2))));
308 scheduler()->ScheduleLocalNudge(zero(), model_types, FROM_HERE); 312 scheduler()->ScheduleLocalNudge(zero(), model_types, FROM_HERE);
309 RunLoop(); 313 RunLoop();
310 314
311 ASSERT_EQ(1U, records2.snapshots.size()); 315 ASSERT_EQ(1U, records2.snapshots.size());
312 EXPECT_TRUE(ModelTypeSetMatchesInvalidationMap( 316 EXPECT_TRUE(ModelTypeSetMatchesInvalidationMap(
313 model_types, 317 model_types,
314 records2.snapshots[0].source().types)); 318 records2.snapshots[0].source().types));
315 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, 319 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL,
316 records2.snapshots[0].source().updates_source); 320 records2.snapshots[0].source().updates_source);
317 } 321 }
318 322
319 // Make sure a regular config command is scheduled fine in the absence of any 323 // Make sure a regular config command is scheduled fine in the absence of any
320 // errors. 324 // errors.
321 TEST_F(SyncSchedulerTest, Config) { 325 TEST_F(SyncSchedulerTest, Config) {
322 SyncShareRecords records; 326 SyncShareRecords records;
323 const ModelTypeSet model_types(BOOKMARKS); 327 const ModelTypeSet model_types(BOOKMARKS);
324 328
325 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 329 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_))
326 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 330 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess),
327 WithArg<0>(RecordSyncShare(&records)))); 331 WithArg<0>(RecordSyncShare(&records))));
328 332
329 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 333 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
330 334
331 CallbackCounter counter; 335 CallbackCounter counter;
332 ConfigurationParams params( 336 ConfigurationParams params(
333 GetUpdatesCallerInfo::RECONFIGURATION, 337 GetUpdatesCallerInfo::RECONFIGURATION,
334 model_types, 338 model_types,
335 TypesToRoutingInfo(model_types), 339 TypesToRoutingInfo(model_types),
336 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); 340 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter)));
337 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params)); 341 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params));
338 ASSERT_EQ(1, counter.times_called()); 342 ASSERT_EQ(1, counter.times_called());
339 343
340 ASSERT_EQ(1U, records.snapshots.size()); 344 ASSERT_EQ(1U, records.snapshots.size());
341 EXPECT_TRUE(ModelTypeSetMatchesInvalidationMap( 345 EXPECT_TRUE(ModelTypeSetMatchesInvalidationMap(
342 model_types, 346 model_types,
343 records.snapshots[0].source().types)); 347 records.snapshots[0].source().types));
344 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, 348 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION,
345 records.snapshots[0].source().updates_source); 349 records.snapshots[0].source().updates_source);
346 } 350 }
347 351
348 // Simulate a failure and make sure the config request is retried. 352 // Simulate a failure and make sure the config request is retried.
349 TEST_F(SyncSchedulerTest, ConfigWithBackingOff) { 353 TEST_F(SyncSchedulerTest, ConfigWithBackingOff) {
350 UseMockDelayProvider(); 354 UseMockDelayProvider();
351 EXPECT_CALL(*delay(), GetDelay(_)) 355 EXPECT_CALL(*delay(), GetDelay(_))
352 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(1))); 356 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(1)));
353 SyncShareRecords records; 357 SyncShareRecords records;
354 const ModelTypeSet model_types(BOOKMARKS); 358 const ModelTypeSet model_types(BOOKMARKS);
355 359
356 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 360 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_))
357 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), 361 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureFailed),
358 WithArg<0>(RecordSyncShare(&records)))) 362 WithArg<0>(RecordSyncShare(&records))))
359 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 363 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess),
360 WithArg<0>(RecordSyncShare(&records)))); 364 WithArg<0>(RecordSyncShare(&records))));
361 365
362 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 366 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
363 367
364 ASSERT_EQ(0U, records.snapshots.size()); 368 ASSERT_EQ(0U, records.snapshots.size());
365 CallbackCounter counter; 369 CallbackCounter counter;
366 ConfigurationParams params( 370 ConfigurationParams params(
367 GetUpdatesCallerInfo::RECONFIGURATION, 371 GetUpdatesCallerInfo::RECONFIGURATION,
368 model_types, 372 model_types,
369 TypesToRoutingInfo(model_types), 373 TypesToRoutingInfo(model_types),
(...skipping 15 matching lines...) Expand all
385 389
386 // Issue a nudge when the config has failed. Make sure both the config and 390 // Issue a nudge when the config has failed. Make sure both the config and
387 // nudge are executed. 391 // nudge are executed.
388 TEST_F(SyncSchedulerTest, NudgeWithConfigWithBackingOff) { 392 TEST_F(SyncSchedulerTest, NudgeWithConfigWithBackingOff) {
389 const ModelTypeSet model_types(BOOKMARKS); 393 const ModelTypeSet model_types(BOOKMARKS);
390 UseMockDelayProvider(); 394 UseMockDelayProvider();
391 EXPECT_CALL(*delay(), GetDelay(_)) 395 EXPECT_CALL(*delay(), GetDelay(_))
392 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(50))); 396 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(50)));
393 SyncShareRecords records; 397 SyncShareRecords records;
394 398
395 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 399 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_))
396 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), 400 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureFailed),
397 WithArg<0>(RecordSyncShare(&records)))) 401 WithArg<0>(RecordSyncShare(&records))))
398 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), 402 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureFailed),
399 WithArg<0>(RecordSyncShare(&records)))) 403 WithArg<0>(RecordSyncShare(&records))))
400 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 404 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess),
401 WithArg<0>(RecordSyncShare(&records)))) 405 WithArg<0>(RecordSyncShare(&records))));
402 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 406
407 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
408 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess),
403 WithArg<0>(RecordSyncShare(&records)))); 409 WithArg<0>(RecordSyncShare(&records))));
404 410
405 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 411 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
406 412
407 ASSERT_EQ(0U, records.snapshots.size()); 413 ASSERT_EQ(0U, records.snapshots.size());
408 CallbackCounter counter; 414 CallbackCounter counter;
409 ConfigurationParams params( 415 ConfigurationParams params(
410 GetUpdatesCallerInfo::RECONFIGURATION, 416 GetUpdatesCallerInfo::RECONFIGURATION,
411 model_types, 417 model_types,
412 TypesToRoutingInfo(model_types), 418 TypesToRoutingInfo(model_types),
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, 453 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL,
448 records.snapshots[3].source().updates_source); 454 records.snapshots[3].source().updates_source);
449 455
450 } 456 }
451 457
452 // Test that nudges are coalesced. 458 // Test that nudges are coalesced.
453 TEST_F(SyncSchedulerTest, NudgeCoalescing) { 459 TEST_F(SyncSchedulerTest, NudgeCoalescing) {
454 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 460 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
455 461
456 SyncShareRecords r; 462 SyncShareRecords r;
457 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 463 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
458 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 464 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess),
459 WithArg<0>(RecordSyncShare(&r)))); 465 WithArg<0>(RecordSyncShare(&r))));
460 const ModelTypeSet types1(BOOKMARKS), types2(AUTOFILL), types3(THEMES); 466 const ModelTypeSet types1(BOOKMARKS), types2(AUTOFILL), types3(THEMES);
461 TimeDelta delay = zero(); 467 TimeDelta delay = zero();
462 TimeTicks optimal_time = TimeTicks::Now() + delay; 468 TimeTicks optimal_time = TimeTicks::Now() + delay;
463 scheduler()->ScheduleLocalNudge(delay, types1, FROM_HERE); 469 scheduler()->ScheduleLocalNudge(delay, types1, FROM_HERE);
464 scheduler()->ScheduleLocalNudge(zero(), types2, FROM_HERE); 470 scheduler()->ScheduleLocalNudge(zero(), types2, FROM_HERE);
465 RunLoop(); 471 RunLoop();
466 472
467 ASSERT_EQ(1U, r.snapshots.size()); 473 ASSERT_EQ(1U, r.snapshots.size());
468 EXPECT_GE(r.times[0], optimal_time); 474 EXPECT_GE(r.times[0], optimal_time);
469 EXPECT_TRUE(ModelTypeSetMatchesInvalidationMap( 475 EXPECT_TRUE(ModelTypeSetMatchesInvalidationMap(
470 Union(types1, types2), 476 Union(types1, types2),
471 r.snapshots[0].source().types)); 477 r.snapshots[0].source().types));
472 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, 478 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL,
473 r.snapshots[0].source().updates_source); 479 r.snapshots[0].source().updates_source);
474 480
475 Mock::VerifyAndClearExpectations(syncer()); 481 Mock::VerifyAndClearExpectations(syncer());
476 482
477 SyncShareRecords r2; 483 SyncShareRecords r2;
478 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 484 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
479 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 485 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess),
480 WithArg<0>(RecordSyncShare(&r2)))); 486 WithArg<0>(RecordSyncShare(&r2))));
481 scheduler()->ScheduleLocalNudge(zero(), types3, FROM_HERE); 487 scheduler()->ScheduleLocalNudge(zero(), types3, FROM_HERE);
482 RunLoop(); 488 RunLoop();
483 489
484 ASSERT_EQ(1U, r2.snapshots.size()); 490 ASSERT_EQ(1U, r2.snapshots.size());
485 EXPECT_TRUE(ModelTypeSetMatchesInvalidationMap( 491 EXPECT_TRUE(ModelTypeSetMatchesInvalidationMap(
486 types3, 492 types3,
487 r2.snapshots[0].source().types)); 493 r2.snapshots[0].source().types));
488 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, 494 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL,
489 r2.snapshots[0].source().updates_source); 495 r2.snapshots[0].source().updates_source);
490 } 496 }
491 497
492 // Test that nudges are coalesced. 498 // Test that nudges are coalesced.
493 TEST_F(SyncSchedulerTest, NudgeCoalescingWithDifferentTimings) { 499 TEST_F(SyncSchedulerTest, NudgeCoalescingWithDifferentTimings) {
494 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 500 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
495 501
496 SyncShareRecords r; 502 SyncShareRecords r;
497 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 503 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
498 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 504 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess),
499 WithArg<0>(RecordSyncShare(&r)))); 505 WithArg<0>(RecordSyncShare(&r))));
500 ModelTypeSet types1(BOOKMARKS), types2(AUTOFILL), types3; 506 ModelTypeSet types1(BOOKMARKS), types2(AUTOFILL), types3;
501 507
502 // Create a huge time delay. 508 // Create a huge time delay.
503 TimeDelta delay = TimeDelta::FromDays(1); 509 TimeDelta delay = TimeDelta::FromDays(1);
504 510
505 scheduler()->ScheduleLocalNudge(delay, types1, FROM_HERE); 511 scheduler()->ScheduleLocalNudge(delay, types1, FROM_HERE);
506 scheduler()->ScheduleLocalNudge(zero(), types2, FROM_HERE); 512 scheduler()->ScheduleLocalNudge(zero(), types2, FROM_HERE);
507 513
508 TimeTicks min_time = TimeTicks::Now(); 514 TimeTicks min_time = TimeTicks::Now();
(...skipping 14 matching lines...) Expand all
523 529
524 // Test nudge scheduling. 530 // Test nudge scheduling.
525 TEST_F(SyncSchedulerTest, NudgeWithStates) { 531 TEST_F(SyncSchedulerTest, NudgeWithStates) {
526 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 532 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
527 533
528 SyncShareRecords records; 534 SyncShareRecords records;
529 const ModelTypeSet types(BOOKMARKS); 535 const ModelTypeSet types(BOOKMARKS);
530 ModelTypeInvalidationMap invalidation_map = 536 ModelTypeInvalidationMap invalidation_map =
531 ModelTypeSetToInvalidationMap(types, "test"); 537 ModelTypeSetToInvalidationMap(types, "test");
532 538
533 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 539 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
534 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 540 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess),
535 WithArg<0>(RecordSyncShare(&records)))) 541 WithArg<0>(RecordSyncShare(&records))))
536 .RetiresOnSaturation(); 542 .RetiresOnSaturation();
537 scheduler()->ScheduleInvalidationNudge(zero(), invalidation_map, FROM_HERE); 543 scheduler()->ScheduleInvalidationNudge(zero(), invalidation_map, FROM_HERE);
538 RunLoop(); 544 RunLoop();
539 545
540 ASSERT_EQ(1U, records.snapshots.size()); 546 ASSERT_EQ(1U, records.snapshots.size());
541 EXPECT_THAT(invalidation_map, Eq(records.snapshots[0].source().types)); 547 EXPECT_THAT(invalidation_map, Eq(records.snapshots[0].source().types));
542 EXPECT_EQ(GetUpdatesCallerInfo::NOTIFICATION, 548 EXPECT_EQ(GetUpdatesCallerInfo::NOTIFICATION,
543 records.snapshots[0].source().updates_source); 549 records.snapshots[0].source().updates_source);
544 550
545 Mock::VerifyAndClearExpectations(syncer()); 551 Mock::VerifyAndClearExpectations(syncer());
546 552
547 // Make sure a second, later, nudge is unaffected by first (no coalescing). 553 // Make sure a second, later, nudge is unaffected by first (no coalescing).
548 SyncShareRecords records2; 554 SyncShareRecords records2;
549 invalidation_map.erase(BOOKMARKS); 555 invalidation_map.erase(BOOKMARKS);
550 invalidation_map[AUTOFILL].payload = "test2"; 556 invalidation_map[AUTOFILL].payload = "test2";
551 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 557 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
552 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 558 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess),
553 WithArg<0>(RecordSyncShare(&records2)))); 559 WithArg<0>(RecordSyncShare(&records2))));
554 scheduler()->ScheduleInvalidationNudge(zero(), invalidation_map, FROM_HERE); 560 scheduler()->ScheduleInvalidationNudge(zero(), invalidation_map, FROM_HERE);
555 RunLoop(); 561 RunLoop();
556 562
557 ASSERT_EQ(1U, records2.snapshots.size()); 563 ASSERT_EQ(1U, records2.snapshots.size());
558 EXPECT_THAT(invalidation_map, Eq(records2.snapshots[0].source().types)); 564 EXPECT_THAT(invalidation_map, Eq(records2.snapshots[0].source().types));
559 EXPECT_EQ(GetUpdatesCallerInfo::NOTIFICATION, 565 EXPECT_EQ(GetUpdatesCallerInfo::NOTIFICATION,
560 records2.snapshots[0].source().updates_source); 566 records2.snapshots[0].source().updates_source);
561 } 567 }
562 568
563 // Test that polling works as expected. 569 // Test that polling works as expected.
564 TEST_F(SyncSchedulerTest, Polling) { 570 TEST_F(SyncSchedulerTest, Polling) {
565 SyncShareRecords records; 571 SyncShareRecords records;
566 TimeDelta poll_interval(TimeDelta::FromMilliseconds(30)); 572 TimeDelta poll_interval(TimeDelta::FromMilliseconds(30));
567 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(AtLeast(kMinNumSamples)) 573 EXPECT_CALL(*syncer(), PollSyncShare(_,_)).Times(AtLeast(kMinNumSamples))
568 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess), 574 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulatePollSuccess),
569 WithArg<0>(RecordSyncShareMultiple(&records, kMinNumSamples)))); 575 WithArg<0>(RecordSyncShareMultiple(&records, kMinNumSamples))));
570 576
571 scheduler()->OnReceivedLongPollIntervalUpdate(poll_interval); 577 scheduler()->OnReceivedLongPollIntervalUpdate(poll_interval);
572 578
573 TimeTicks optimal_start = TimeTicks::Now() + poll_interval; 579 TimeTicks optimal_start = TimeTicks::Now() + poll_interval;
574 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 580 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
575 581
576 // Run again to wait for polling. 582 // Run again to wait for polling.
577 RunLoop(); 583 RunLoop();
578 584
579 StopSyncScheduler(); 585 StopSyncScheduler();
580 AnalyzePollRun(records, kMinNumSamples, optimal_start, poll_interval); 586 AnalyzePollRun(records, kMinNumSamples, optimal_start, poll_interval);
581 } 587 }
582 588
583 // Test that the short poll interval is used. 589 // Test that the short poll interval is used.
584 TEST_F(SyncSchedulerTest, PollNotificationsDisabled) { 590 TEST_F(SyncSchedulerTest, PollNotificationsDisabled) {
585 SyncShareRecords records; 591 SyncShareRecords records;
586 TimeDelta poll_interval(TimeDelta::FromMilliseconds(30)); 592 TimeDelta poll_interval(TimeDelta::FromMilliseconds(30));
587 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(AtLeast(kMinNumSamples)) 593 EXPECT_CALL(*syncer(), PollSyncShare(_,_)).Times(AtLeast(kMinNumSamples))
588 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess), 594 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulatePollSuccess),
589 WithArg<0>(RecordSyncShareMultiple(&records, kMinNumSamples)))); 595 WithArg<0>(RecordSyncShareMultiple(&records, kMinNumSamples))));
590 596
591 scheduler()->OnReceivedShortPollIntervalUpdate(poll_interval); 597 scheduler()->OnReceivedShortPollIntervalUpdate(poll_interval);
592 scheduler()->SetNotificationsEnabled(false); 598 scheduler()->SetNotificationsEnabled(false);
593 599
594 TimeTicks optimal_start = TimeTicks::Now() + poll_interval; 600 TimeTicks optimal_start = TimeTicks::Now() + poll_interval;
595 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 601 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
596 602
597 // Run again to wait for polling. 603 // Run again to wait for polling.
598 RunLoop(); 604 RunLoop();
599 605
600 StopSyncScheduler(); 606 StopSyncScheduler();
601 AnalyzePollRun(records, kMinNumSamples, optimal_start, poll_interval); 607 AnalyzePollRun(records, kMinNumSamples, optimal_start, poll_interval);
602 } 608 }
603 609
604 // Test that polling intervals are updated when needed. 610 // Test that polling intervals are updated when needed.
605 TEST_F(SyncSchedulerTest, PollIntervalUpdate) { 611 TEST_F(SyncSchedulerTest, PollIntervalUpdate) {
606 SyncShareRecords records; 612 SyncShareRecords records;
607 TimeDelta poll1(TimeDelta::FromMilliseconds(120)); 613 TimeDelta poll1(TimeDelta::FromMilliseconds(120));
608 TimeDelta poll2(TimeDelta::FromMilliseconds(30)); 614 TimeDelta poll2(TimeDelta::FromMilliseconds(30));
609 scheduler()->OnReceivedLongPollIntervalUpdate(poll1); 615 scheduler()->OnReceivedLongPollIntervalUpdate(poll1);
610 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(AtLeast(kMinNumSamples)) 616 EXPECT_CALL(*syncer(), PollSyncShare(_,_)).Times(AtLeast(kMinNumSamples))
611 .WillOnce(DoAll( 617 .WillOnce(DoAll(
612 WithArg<0>( 618 WithArgs<0,1>(
613 sessions::test_util::SimulatePollIntervalUpdate(poll2)), 619 sessions::test_util::SimulatePollIntervalUpdate(poll2)),
614 Return(true))) 620 Return(true)))
615 .WillRepeatedly( 621 .WillRepeatedly(
616 DoAll(Invoke(sessions::test_util::SimulateSuccess), 622 DoAll(Invoke(sessions::test_util::SimulatePollSuccess),
617 WithArg<0>( 623 WithArg<0>(
618 RecordSyncShareMultiple(&records, kMinNumSamples)))); 624 RecordSyncShareMultiple(&records, kMinNumSamples))));
619 625
620 TimeTicks optimal_start = TimeTicks::Now() + poll1 + poll2; 626 TimeTicks optimal_start = TimeTicks::Now() + poll1 + poll2;
621 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 627 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
622 628
623 // Run again to wait for polling. 629 // Run again to wait for polling.
624 RunLoop(); 630 RunLoop();
625 631
626 StopSyncScheduler(); 632 StopSyncScheduler();
627 AnalyzePollRun(records, kMinNumSamples, optimal_start, poll2); 633 AnalyzePollRun(records, kMinNumSamples, optimal_start, poll2);
628 } 634 }
629 635
630 // Test that the sessions commit delay is updated when needed. 636 // Test that the sessions commit delay is updated when needed.
631 TEST_F(SyncSchedulerTest, SessionsCommitDelay) { 637 TEST_F(SyncSchedulerTest, SessionsCommitDelay) {
632 SyncShareRecords records; 638 SyncShareRecords records;
633 TimeDelta delay1(TimeDelta::FromMilliseconds(120)); 639 TimeDelta delay1(TimeDelta::FromMilliseconds(120));
634 TimeDelta delay2(TimeDelta::FromMilliseconds(30)); 640 TimeDelta delay2(TimeDelta::FromMilliseconds(30));
635 scheduler()->OnReceivedSessionsCommitDelay(delay1); 641 scheduler()->OnReceivedSessionsCommitDelay(delay1);
636 642
637 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 643 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
638 .WillOnce( 644 .WillOnce(
639 DoAll( 645 DoAll(
640 WithArg<0>( 646 WithArgs<0,1,2>(
641 sessions::test_util::SimulateSessionsCommitDelayUpdate( 647 sessions::test_util::SimulateSessionsCommitDelayUpdate(
642 delay2)), 648 delay2)),
643 Invoke(sessions::test_util::SimulateSuccess), 649 Invoke(sessions::test_util::SimulateNormalSuccess),
644 QuitLoopNowAction())); 650 QuitLoopNowAction()));
645 651
646 EXPECT_EQ(delay1, scheduler()->GetSessionsCommitDelay()); 652 EXPECT_EQ(delay1, scheduler()->GetSessionsCommitDelay());
647 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 653 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
648 654
649 EXPECT_EQ(delay1, scheduler()->GetSessionsCommitDelay()); 655 EXPECT_EQ(delay1, scheduler()->GetSessionsCommitDelay());
650 const ModelTypeSet model_types(BOOKMARKS); 656 const ModelTypeSet model_types(BOOKMARKS);
651 scheduler()->ScheduleLocalNudge(zero(), model_types, FROM_HERE); 657 scheduler()->ScheduleLocalNudge(zero(), model_types, FROM_HERE);
652 RunLoop(); 658 RunLoop();
653 659
654 EXPECT_EQ(delay2, scheduler()->GetSessionsCommitDelay()); 660 EXPECT_EQ(delay2, scheduler()->GetSessionsCommitDelay());
655 StopSyncScheduler(); 661 StopSyncScheduler();
656 } 662 }
657 663
658 // Test that no syncing occurs when throttled. 664 // Test that no syncing occurs when throttled.
659 TEST_F(SyncSchedulerTest, ThrottlingDoesThrottle) { 665 TEST_F(SyncSchedulerTest, ThrottlingDoesThrottle) {
660 const ModelTypeSet types(BOOKMARKS); 666 const ModelTypeSet types(BOOKMARKS);
661 TimeDelta poll(TimeDelta::FromMilliseconds(5)); 667 TimeDelta poll(TimeDelta::FromMilliseconds(5));
662 TimeDelta throttle(TimeDelta::FromMinutes(10)); 668 TimeDelta throttle(TimeDelta::FromMinutes(10));
663 scheduler()->OnReceivedLongPollIntervalUpdate(poll); 669 scheduler()->OnReceivedLongPollIntervalUpdate(poll);
664 670
665 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 671 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_))
666 .WillOnce(DoAll( 672 .WillOnce(DoAll(
667 WithArg<0>(sessions::test_util::SimulateThrottled(throttle)), 673 WithArg<0>(sessions::test_util::SimulateThrottled(throttle)),
668 Return(true))) 674 Return(true)))
669 .WillRepeatedly(AddFailureAndQuitLoopNow()); 675 .WillRepeatedly(AddFailureAndQuitLoopNow());
670 676
671 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 677 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
672 678
673 scheduler()->ScheduleLocalNudge( 679 scheduler()->ScheduleLocalNudge(
674 TimeDelta::FromMicroseconds(1), types, FROM_HERE); 680 TimeDelta::FromMicroseconds(1), types, FROM_HERE);
675 PumpLoop(); 681 PumpLoop();
(...skipping 10 matching lines...) Expand all
686 ASSERT_EQ(0, counter.times_called()); 692 ASSERT_EQ(0, counter.times_called());
687 } 693 }
688 694
689 TEST_F(SyncSchedulerTest, ThrottlingExpiresFromPoll) { 695 TEST_F(SyncSchedulerTest, ThrottlingExpiresFromPoll) {
690 SyncShareRecords records; 696 SyncShareRecords records;
691 TimeDelta poll(TimeDelta::FromMilliseconds(15)); 697 TimeDelta poll(TimeDelta::FromMilliseconds(15));
692 TimeDelta throttle1(TimeDelta::FromMilliseconds(150)); 698 TimeDelta throttle1(TimeDelta::FromMilliseconds(150));
693 scheduler()->OnReceivedLongPollIntervalUpdate(poll); 699 scheduler()->OnReceivedLongPollIntervalUpdate(poll);
694 700
695 ::testing::InSequence seq; 701 ::testing::InSequence seq;
696 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 702 EXPECT_CALL(*syncer(), PollSyncShare(_,_))
697 .WillOnce(DoAll( 703 .WillOnce(DoAll(
698 WithArg<0>(sessions::test_util::SimulateThrottled(throttle1)), 704 WithArg<0>(sessions::test_util::SimulateThrottled(throttle1)),
699 Return(true))) 705 Return(true)))
700 .RetiresOnSaturation(); 706 .RetiresOnSaturation();
701 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 707 EXPECT_CALL(*syncer(), PollSyncShare(_,_))
702 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess), 708 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulatePollSuccess),
703 WithArg<0>(RecordSyncShareMultiple(&records, kMinNumSamples)))); 709 WithArg<0>(RecordSyncShareMultiple(&records, kMinNumSamples))));
704 710
705 TimeTicks optimal_start = TimeTicks::Now() + poll + throttle1; 711 TimeTicks optimal_start = TimeTicks::Now() + poll + throttle1;
706 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 712 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
707 713
708 // Run again to wait for polling. 714 // Run again to wait for polling.
709 RunLoop(); 715 RunLoop();
710 716
711 StopSyncScheduler(); 717 StopSyncScheduler();
712 AnalyzePollRun(records, kMinNumSamples, optimal_start, poll); 718 AnalyzePollRun(records, kMinNumSamples, optimal_start, poll);
713 } 719 }
714 720
715 TEST_F(SyncSchedulerTest, ThrottlingExpiresFromNudge) { 721 TEST_F(SyncSchedulerTest, ThrottlingExpiresFromNudge) {
716 SyncShareRecords records; 722 SyncShareRecords records;
717 TimeDelta poll(TimeDelta::FromDays(1)); 723 TimeDelta poll(TimeDelta::FromDays(1));
718 TimeDelta throttle1(TimeDelta::FromMilliseconds(150)); 724 TimeDelta throttle1(TimeDelta::FromMilliseconds(150));
719 scheduler()->OnReceivedLongPollIntervalUpdate(poll); 725 scheduler()->OnReceivedLongPollIntervalUpdate(poll);
720 726
721 ::testing::InSequence seq; 727 ::testing::InSequence seq;
722 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 728 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
723 .WillOnce(DoAll( 729 .WillOnce(DoAll(
724 WithArg<0>(sessions::test_util::SimulateThrottled(throttle1)), 730 WithArg<0>(sessions::test_util::SimulateThrottled(throttle1)),
725 Return(true))) 731 Return(true)))
726 .RetiresOnSaturation(); 732 .RetiresOnSaturation();
727 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 733 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
728 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 734 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess),
729 QuitLoopNowAction())); 735 QuitLoopNowAction()));
730 736
731 const ModelTypeSet types(BOOKMARKS); 737 const ModelTypeSet types(BOOKMARKS);
732 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 738 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
733 scheduler()->ScheduleLocalNudge(zero(), types, FROM_HERE); 739 scheduler()->ScheduleLocalNudge(zero(), types, FROM_HERE);
734 740
735 PumpLoop(); 741 PumpLoop();
736 EXPECT_TRUE(scheduler()->IsCurrentlyThrottled()); 742 EXPECT_TRUE(scheduler()->IsCurrentlyThrottled());
737 RunLoop(); 743 RunLoop();
738 EXPECT_FALSE(scheduler()->IsCurrentlyThrottled()); 744 EXPECT_FALSE(scheduler()->IsCurrentlyThrottled());
739 745
740 StopSyncScheduler(); 746 StopSyncScheduler();
741 } 747 }
742 748
743 TEST_F(SyncSchedulerTest, ThrottlingExpiresFromConfigure) { 749 TEST_F(SyncSchedulerTest, ThrottlingExpiresFromConfigure) {
744 SyncShareRecords records; 750 SyncShareRecords records;
745 TimeDelta poll(TimeDelta::FromDays(1)); 751 TimeDelta poll(TimeDelta::FromDays(1));
746 TimeDelta throttle1(TimeDelta::FromMilliseconds(150)); 752 TimeDelta throttle1(TimeDelta::FromMilliseconds(150));
747 scheduler()->OnReceivedLongPollIntervalUpdate(poll); 753 scheduler()->OnReceivedLongPollIntervalUpdate(poll);
748 754
749 ::testing::InSequence seq; 755 ::testing::InSequence seq;
750 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 756 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_))
751 .WillOnce(DoAll( 757 .WillOnce(DoAll(
752 WithArg<0>(sessions::test_util::SimulateThrottled(throttle1)), 758 WithArg<0>(sessions::test_util::SimulateThrottled(throttle1)),
753 Return(true))) 759 Return(true)))
754 .RetiresOnSaturation(); 760 .RetiresOnSaturation();
755 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 761 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_))
756 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 762 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess),
757 QuitLoopNowAction())); 763 QuitLoopNowAction()));
758 764
759 const ModelTypeSet types(BOOKMARKS); 765 const ModelTypeSet types(BOOKMARKS);
760 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 766 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
761 767
762 CallbackCounter counter; 768 CallbackCounter counter;
763 ConfigurationParams params( 769 ConfigurationParams params(
764 GetUpdatesCallerInfo::RECONFIGURATION, 770 GetUpdatesCallerInfo::RECONFIGURATION,
765 types, 771 types,
766 TypesToRoutingInfo(types), 772 TypesToRoutingInfo(types),
(...skipping 13 matching lines...) Expand all
780 EXPECT_CALL(*delay(), GetDelay(_)) 786 EXPECT_CALL(*delay(), GetDelay(_))
781 .WillRepeatedly(Return(zero())); 787 .WillRepeatedly(Return(zero()));
782 788
783 TimeDelta poll(TimeDelta::FromDays(1)); 789 TimeDelta poll(TimeDelta::FromDays(1));
784 TimeDelta throttle1(TimeDelta::FromSeconds(60)); 790 TimeDelta throttle1(TimeDelta::FromSeconds(60));
785 scheduler()->OnReceivedLongPollIntervalUpdate(poll); 791 scheduler()->OnReceivedLongPollIntervalUpdate(poll);
786 792
787 const ModelTypeSet types(BOOKMARKS); 793 const ModelTypeSet types(BOOKMARKS);
788 794
789 ::testing::InSequence seq; 795 ::testing::InSequence seq;
790 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 796 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
791 .WillOnce(DoAll( 797 .WillOnce(DoAll(
792 WithArg<0>( 798 WithArg<0>(
793 sessions::test_util::SimulateTypesThrottled(types, throttle1)), 799 sessions::test_util::SimulateTypesThrottled(types, throttle1)),
794 Return(true))) 800 Return(true)))
795 .RetiresOnSaturation(); 801 .RetiresOnSaturation();
796 802
797 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 803 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
798 scheduler()->ScheduleLocalNudge(zero(), types, FROM_HERE); 804 scheduler()->ScheduleLocalNudge(zero(), types, FROM_HERE);
799 PumpLoop(); 805 PumpLoop();
800 EXPECT_TRUE(GetThrottledTypes().HasAll(types)); 806 EXPECT_TRUE(GetThrottledTypes().HasAll(types));
(...skipping 12 matching lines...) Expand all
813 819
814 SyncShareRecords records; 820 SyncShareRecords records;
815 TimeDelta poll(TimeDelta::FromDays(1)); 821 TimeDelta poll(TimeDelta::FromDays(1));
816 TimeDelta throttle1(TimeDelta::FromSeconds(60)); 822 TimeDelta throttle1(TimeDelta::FromSeconds(60));
817 scheduler()->OnReceivedLongPollIntervalUpdate(poll); 823 scheduler()->OnReceivedLongPollIntervalUpdate(poll);
818 824
819 const ModelTypeSet throttled_types(BOOKMARKS); 825 const ModelTypeSet throttled_types(BOOKMARKS);
820 const ModelTypeSet unthrottled_types(PREFERENCES); 826 const ModelTypeSet unthrottled_types(PREFERENCES);
821 827
822 ::testing::InSequence seq; 828 ::testing::InSequence seq;
823 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 829 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
824 .WillOnce(DoAll( 830 .WillOnce(DoAll(
825 WithArg<0>( 831 WithArg<0>(
826 sessions::test_util::SimulateTypesThrottled( 832 sessions::test_util::SimulateTypesThrottled(
827 throttled_types, throttle1)), 833 throttled_types, throttle1)),
828 Return(true))) 834 Return(true)))
829 .RetiresOnSaturation(); 835 .RetiresOnSaturation();
830 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 836 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
831 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess), 837 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess),
832 WithArg<0>(RecordSyncShare(&records)))); 838 WithArg<0>(RecordSyncShare(&records))));
833 839
834 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 840 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
835 scheduler()->ScheduleLocalNudge(zero(), throttled_types, FROM_HERE); 841 scheduler()->ScheduleLocalNudge(zero(), throttled_types, FROM_HERE);
836 PumpLoop(); 842 PumpLoop();
837 EXPECT_EQ(0U, records.snapshots.size()); 843 EXPECT_EQ(0U, records.snapshots.size());
838 EXPECT_TRUE(GetThrottledTypes().HasAll(throttled_types)); 844 EXPECT_TRUE(GetThrottledTypes().HasAll(throttled_types));
839 845
840 // Ignore invalidations for throttled types. 846 // Ignore invalidations for throttled types.
841 ModelTypeInvalidationMap invalidation_map = 847 ModelTypeInvalidationMap invalidation_map =
(...skipping 13 matching lines...) Expand all
855 EXPECT_EQ(1U, records.snapshots.size()); 861 EXPECT_EQ(1U, records.snapshots.size());
856 862
857 StopSyncScheduler(); 863 StopSyncScheduler();
858 } 864 }
859 865
860 // Test nudges / polls don't run in config mode and config tasks do. 866 // Test nudges / polls don't run in config mode and config tasks do.
861 TEST_F(SyncSchedulerTest, ConfigurationMode) { 867 TEST_F(SyncSchedulerTest, ConfigurationMode) {
862 TimeDelta poll(TimeDelta::FromMilliseconds(15)); 868 TimeDelta poll(TimeDelta::FromMilliseconds(15));
863 SyncShareRecords records; 869 SyncShareRecords records;
864 scheduler()->OnReceivedLongPollIntervalUpdate(poll); 870 scheduler()->OnReceivedLongPollIntervalUpdate(poll);
865 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 871 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_))
866 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 872 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess),
867 WithArg<0>(RecordSyncShare(&records)))) 873 WithArg<0>(RecordSyncShare(&records))))
868 .RetiresOnSaturation(); 874 .RetiresOnSaturation();
869 875
870 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 876 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
871 877
872 const ModelTypeSet nudge_types(AUTOFILL); 878 const ModelTypeSet nudge_types(AUTOFILL);
873 scheduler()->ScheduleLocalNudge(zero(), nudge_types, FROM_HERE); 879 scheduler()->ScheduleLocalNudge(zero(), nudge_types, FROM_HERE);
874 scheduler()->ScheduleLocalNudge(zero(), nudge_types, FROM_HERE); 880 scheduler()->ScheduleLocalNudge(zero(), nudge_types, FROM_HERE);
875 881
876 const ModelTypeSet config_types(BOOKMARKS); 882 const ModelTypeSet config_types(BOOKMARKS);
(...skipping 10 matching lines...) Expand all
887 ASSERT_EQ(1U, records.snapshots.size()); 893 ASSERT_EQ(1U, records.snapshots.size());
888 EXPECT_TRUE(ModelTypeSetMatchesInvalidationMap( 894 EXPECT_TRUE(ModelTypeSetMatchesInvalidationMap(
889 config_types, 895 config_types,
890 records.snapshots[0].source().types)); 896 records.snapshots[0].source().types));
891 897
892 // Switch to NORMAL_MODE to ensure NUDGES were properly saved and run. 898 // Switch to NORMAL_MODE to ensure NUDGES were properly saved and run.
893 // SyncSchedulerWhiteboxTest also provides coverage for this, but much 899 // SyncSchedulerWhiteboxTest also provides coverage for this, but much
894 // more targeted ('whitebox' style). 900 // more targeted ('whitebox' style).
895 scheduler()->OnReceivedLongPollIntervalUpdate(TimeDelta::FromDays(1)); 901 scheduler()->OnReceivedLongPollIntervalUpdate(TimeDelta::FromDays(1));
896 SyncShareRecords records2; 902 SyncShareRecords records2;
897 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 903 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
898 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 904 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess),
899 WithArg<0>(RecordSyncShare(&records2)))); 905 WithArg<0>(RecordSyncShare(&records2))));
900 906
901 // TODO(tim): Figure out how to remove this dangerous need to reset 907 // TODO(tim): Figure out how to remove this dangerous need to reset
902 // routing info between mode switches. 908 // routing info between mode switches.
903 context()->set_routing_info(routing_info()); 909 context()->set_routing_info(routing_info());
904 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 910 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
905 911
906 ASSERT_EQ(1U, records2.snapshots.size()); 912 ASSERT_EQ(1U, records2.snapshots.size());
907 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, 913 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL,
908 records2.snapshots[0].source().updates_source); 914 records2.snapshots[0].source().updates_source);
(...skipping 13 matching lines...) Expand all
922 928
923 virtual void TearDown() { 929 virtual void TearDown() {
924 StopSyncScheduler(); 930 StopSyncScheduler();
925 SyncSchedulerTest::TearDown(); 931 SyncSchedulerTest::TearDown();
926 } 932 }
927 }; 933 };
928 934
929 // Have the sycner fail during commit. Expect that the scheduler enters 935 // Have the sycner fail during commit. Expect that the scheduler enters
930 // backoff. 936 // backoff.
931 TEST_F(BackoffTriggersSyncSchedulerTest, FailCommitOnce) { 937 TEST_F(BackoffTriggersSyncSchedulerTest, FailCommitOnce) {
932 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 938 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
933 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), 939 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed),
934 QuitLoopNowAction())); 940 QuitLoopNowAction()));
935 EXPECT_TRUE(RunAndGetBackoff()); 941 EXPECT_TRUE(RunAndGetBackoff());
936 } 942 }
937 943
938 // Have the syncer fail during download updates and succeed on the first 944 // Have the syncer fail during download updates and succeed on the first
939 // retry. Expect that this clears the backoff state. 945 // retry. Expect that this clears the backoff state.
940 TEST_F(BackoffTriggersSyncSchedulerTest, FailDownloadOnceThenSucceed) { 946 TEST_F(BackoffTriggersSyncSchedulerTest, FailDownloadOnceThenSucceed) {
941 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 947 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
942 .WillOnce(DoAll( 948 .WillOnce(DoAll(
943 Invoke(sessions::test_util::SimulateDownloadUpdatesFailed), 949 Invoke(sessions::test_util::SimulateDownloadUpdatesFailed),
944 Return(true))) 950 Return(true)))
945 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 951 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess),
946 QuitLoopNowAction())); 952 QuitLoopNowAction()));
947 EXPECT_FALSE(RunAndGetBackoff()); 953 EXPECT_FALSE(RunAndGetBackoff());
948 } 954 }
949 955
950 // Have the syncer fail during commit and succeed on the first retry. Expect 956 // Have the syncer fail during commit and succeed on the first retry. Expect
951 // that this clears the backoff state. 957 // that this clears the backoff state.
952 TEST_F(BackoffTriggersSyncSchedulerTest, FailCommitOnceThenSucceed) { 958 TEST_F(BackoffTriggersSyncSchedulerTest, FailCommitOnceThenSucceed) {
953 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 959 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
954 .WillOnce(DoAll( 960 .WillOnce(DoAll(
955 Invoke(sessions::test_util::SimulateCommitFailed), 961 Invoke(sessions::test_util::SimulateCommitFailed),
956 Return(true))) 962 Return(true)))
957 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 963 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess),
958 QuitLoopNowAction())); 964 QuitLoopNowAction()));
959 EXPECT_FALSE(RunAndGetBackoff()); 965 EXPECT_FALSE(RunAndGetBackoff());
960 } 966 }
961 967
962 // Have the syncer fail to download updates and fail again on the retry. 968 // Have the syncer fail to download updates and fail again on the retry.
963 // Expect this will leave the scheduler in backoff. 969 // Expect this will leave the scheduler in backoff.
964 TEST_F(BackoffTriggersSyncSchedulerTest, FailDownloadTwice) { 970 TEST_F(BackoffTriggersSyncSchedulerTest, FailDownloadTwice) {
965 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 971 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
966 .WillOnce(DoAll( 972 .WillOnce(DoAll(
967 Invoke(sessions::test_util::SimulateDownloadUpdatesFailed), 973 Invoke(sessions::test_util::SimulateDownloadUpdatesFailed),
968 Return(true))) 974 Return(true)))
969 .WillRepeatedly(DoAll( 975 .WillRepeatedly(DoAll(
970 Invoke(sessions::test_util::SimulateDownloadUpdatesFailed), 976 Invoke(sessions::test_util::SimulateDownloadUpdatesFailed),
971 QuitLoopNowAction())); 977 QuitLoopNowAction()));
972 EXPECT_TRUE(RunAndGetBackoff()); 978 EXPECT_TRUE(RunAndGetBackoff());
973 } 979 }
974 980
975 // Have the syncer fail to get the encryption key yet succeed in downloading 981 // Have the syncer fail to get the encryption key yet succeed in downloading
976 // updates. Expect this will leave the scheduler in backoff. 982 // updates. Expect this will leave the scheduler in backoff.
977 TEST_F(BackoffTriggersSyncSchedulerTest, FailGetEncryptionKey) { 983 TEST_F(BackoffTriggersSyncSchedulerTest, FailGetEncryptionKey) {
978 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 984 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_))
979 .WillOnce(DoAll( 985 .WillOnce(DoAll(
980 Invoke(sessions::test_util::SimulateGetEncryptionKeyFailed), 986 Invoke(sessions::test_util::SimulateGetEncryptionKeyFailed),
981 Return(true))) 987 Return(true)))
982 .WillRepeatedly(DoAll( 988 .WillRepeatedly(DoAll(
983 Invoke(sessions::test_util::SimulateGetEncryptionKeyFailed), 989 Invoke(sessions::test_util::SimulateGetEncryptionKeyFailed),
984 QuitLoopNowAction())); 990 QuitLoopNowAction()));
985 EXPECT_TRUE(RunAndGetBackoff()); 991 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
992
993 ModelTypeSet types(BOOKMARKS);
994 CallbackCounter counter;
995 ConfigurationParams params(
996 GetUpdatesCallerInfo::RECONFIGURATION,
997 types,
998 TypesToRoutingInfo(types),
999 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter)));
1000 scheduler()->ScheduleConfiguration(params);
1001 RunLoop();
1002
1003 EXPECT_TRUE(scheduler()->IsBackingOff());
986 } 1004 }
987 1005
988 // Test that no polls or extraneous nudges occur when in backoff. 1006 // Test that no polls or extraneous nudges occur when in backoff.
989 TEST_F(SyncSchedulerTest, BackoffDropsJobs) { 1007 TEST_F(SyncSchedulerTest, BackoffDropsJobs) {
990 SyncShareRecords r; 1008 SyncShareRecords r;
991 TimeDelta poll(TimeDelta::FromMilliseconds(5)); 1009 TimeDelta poll(TimeDelta::FromMilliseconds(5));
992 const ModelTypeSet types(BOOKMARKS); 1010 const ModelTypeSet types(BOOKMARKS);
993 scheduler()->OnReceivedLongPollIntervalUpdate(poll); 1011 scheduler()->OnReceivedLongPollIntervalUpdate(poll);
994 UseMockDelayProvider(); 1012 UseMockDelayProvider();
995 1013
996 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 1014 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
997 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), 1015 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateCommitFailed),
998 RecordSyncShareMultiple(&r, 1U))); 1016 RecordSyncShareMultiple(&r, 1U)));
999 EXPECT_CALL(*delay(), GetDelay(_)). 1017 EXPECT_CALL(*delay(), GetDelay(_)).
1000 WillRepeatedly(Return(TimeDelta::FromDays(1))); 1018 WillRepeatedly(Return(TimeDelta::FromDays(1)));
1001 1019
1002 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 1020 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
1003 1021
1004 // This nudge should fail and put us into backoff. Thanks to our mock 1022 // This nudge should fail and put us into backoff. Thanks to our mock
1005 // GetDelay() setup above, this will be a long backoff. 1023 // GetDelay() setup above, this will be a long backoff.
1006 scheduler()->ScheduleLocalNudge(zero(), types, FROM_HERE); 1024 scheduler()->ScheduleLocalNudge(zero(), types, FROM_HERE);
(...skipping 30 matching lines...) Expand all
1037 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); 1055 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter)));
1038 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params)); 1056 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params));
1039 ASSERT_EQ(0, counter.times_called()); 1057 ASSERT_EQ(0, counter.times_called());
1040 } 1058 }
1041 1059
1042 // Test that backoff is shaping traffic properly with consecutive errors. 1060 // Test that backoff is shaping traffic properly with consecutive errors.
1043 TEST_F(SyncSchedulerTest, BackoffElevation) { 1061 TEST_F(SyncSchedulerTest, BackoffElevation) {
1044 SyncShareRecords r; 1062 SyncShareRecords r;
1045 UseMockDelayProvider(); 1063 UseMockDelayProvider();
1046 1064
1047 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(kMinNumSamples) 1065 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)).Times(kMinNumSamples)
1048 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), 1066 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateCommitFailed),
1049 RecordSyncShareMultiple(&r, kMinNumSamples))); 1067 RecordSyncShareMultiple(&r, kMinNumSamples)));
1050 1068
1051 const TimeDelta first = TimeDelta::FromSeconds(kInitialBackoffRetrySeconds); 1069 const TimeDelta first = TimeDelta::FromSeconds(kInitialBackoffRetrySeconds);
1052 const TimeDelta second = TimeDelta::FromMilliseconds(2); 1070 const TimeDelta second = TimeDelta::FromMilliseconds(2);
1053 const TimeDelta third = TimeDelta::FromMilliseconds(3); 1071 const TimeDelta third = TimeDelta::FromMilliseconds(3);
1054 const TimeDelta fourth = TimeDelta::FromMilliseconds(4); 1072 const TimeDelta fourth = TimeDelta::FromMilliseconds(4);
1055 const TimeDelta fifth = TimeDelta::FromMilliseconds(5); 1073 const TimeDelta fifth = TimeDelta::FromMilliseconds(5);
1056 const TimeDelta sixth = TimeDelta::FromDays(1); 1074 const TimeDelta sixth = TimeDelta::FromDays(1);
1057 1075
(...skipping 22 matching lines...) Expand all
1080 1098
1081 // Test that things go back to normal once a retry makes forward progress. 1099 // Test that things go back to normal once a retry makes forward progress.
1082 TEST_F(SyncSchedulerTest, BackoffRelief) { 1100 TEST_F(SyncSchedulerTest, BackoffRelief) {
1083 SyncShareRecords r; 1101 SyncShareRecords r;
1084 const TimeDelta poll(TimeDelta::FromMilliseconds(10)); 1102 const TimeDelta poll(TimeDelta::FromMilliseconds(10));
1085 scheduler()->OnReceivedLongPollIntervalUpdate(poll); 1103 scheduler()->OnReceivedLongPollIntervalUpdate(poll);
1086 UseMockDelayProvider(); 1104 UseMockDelayProvider();
1087 1105
1088 const TimeDelta backoff = TimeDelta::FromMilliseconds(5); 1106 const TimeDelta backoff = TimeDelta::FromMilliseconds(5);
1089 1107
1090 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 1108 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
1091 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), 1109 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed),
1092 RecordSyncShareMultiple(&r, kMinNumSamples))) 1110 RecordSyncShareMultiple(&r, kMinNumSamples)))
1093 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess), 1111 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess),
1112 RecordSyncShareMultiple(&r, kMinNumSamples)));
1113 EXPECT_CALL(*syncer(), PollSyncShare(_,_))
1114 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulatePollSuccess),
1094 RecordSyncShareMultiple(&r, kMinNumSamples))); 1115 RecordSyncShareMultiple(&r, kMinNumSamples)));
1095 EXPECT_CALL(*delay(), GetDelay(_)).WillOnce(Return(backoff)); 1116 EXPECT_CALL(*delay(), GetDelay(_)).WillOnce(Return(backoff));
1096 1117
1097 // Optimal start for the post-backoff poll party. 1118 // Optimal start for the post-backoff poll party.
1098 TimeTicks optimal_start = TimeTicks::Now(); 1119 TimeTicks optimal_start = TimeTicks::Now();
1099 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 1120 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
1100 1121
1101 // Run again to wait for polling. 1122 // Run again to wait for polling.
1102 scheduler()->ScheduleLocalNudge(zero(), ModelTypeSet(BOOKMARKS), FROM_HERE); 1123 scheduler()->ScheduleLocalNudge(zero(), ModelTypeSet(BOOKMARKS), FROM_HERE);
1103 RunLoop(); 1124 RunLoop();
(...skipping 24 matching lines...) Expand all
1128 } 1149 }
1129 1150
1130 // Test that poll failures are ignored. They should have no effect on 1151 // Test that poll failures are ignored. They should have no effect on
1131 // subsequent poll attempts, nor should they trigger a backoff/retry. 1152 // subsequent poll attempts, nor should they trigger a backoff/retry.
1132 TEST_F(SyncSchedulerTest, TransientPollFailure) { 1153 TEST_F(SyncSchedulerTest, TransientPollFailure) {
1133 SyncShareRecords r; 1154 SyncShareRecords r;
1134 const TimeDelta poll_interval(TimeDelta::FromMilliseconds(1)); 1155 const TimeDelta poll_interval(TimeDelta::FromMilliseconds(1));
1135 scheduler()->OnReceivedLongPollIntervalUpdate(poll_interval); 1156 scheduler()->OnReceivedLongPollIntervalUpdate(poll_interval);
1136 UseMockDelayProvider(); // Will cause test failure if backoff is initiated. 1157 UseMockDelayProvider(); // Will cause test failure if backoff is initiated.
1137 1158
1138 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 1159 EXPECT_CALL(*syncer(), PollSyncShare(_,_))
1139 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), 1160 .WillOnce(DoAll(Invoke(sessions::test_util::SimulatePollFailed),
1140 RecordSyncShare(&r))) 1161 RecordSyncShare(&r)))
1141 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 1162 .WillOnce(DoAll(Invoke(sessions::test_util::SimulatePollSuccess),
1142 RecordSyncShare(&r))); 1163 RecordSyncShare(&r)));
1143 1164
1144 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 1165 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
1145 1166
1146 // Run the unsucessful poll. The failed poll should not trigger backoff. 1167 // Run the unsucessful poll. The failed poll should not trigger backoff.
1147 RunLoop(); 1168 RunLoop();
1148 EXPECT_FALSE(scheduler()->IsBackingOff()); 1169 EXPECT_FALSE(scheduler()->IsBackingOff());
1149 1170
1150 // Run the successful poll. 1171 // Run the successful poll.
1151 RunLoop(); 1172 RunLoop();
1152 EXPECT_FALSE(scheduler()->IsBackingOff()); 1173 EXPECT_FALSE(scheduler()->IsBackingOff());
1153 } 1174 }
1154 1175
1155 // Test that appropriate syncer steps are requested for each job type.
1156 TEST_F(SyncSchedulerTest, SyncerSteps) {
1157 // Nudges.
1158 EXPECT_CALL(*syncer(), SyncShare(_, SYNCER_BEGIN, SYNCER_END))
1159 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
1160 Return(true)));
1161 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
1162
1163 scheduler()->ScheduleLocalNudge(zero(), ModelTypeSet(BOOKMARKS), FROM_HERE);
1164 PumpLoop();
1165 // Pump again to run job.
1166 PumpLoop();
1167
1168 StopSyncScheduler();
1169 Mock::VerifyAndClearExpectations(syncer());
1170
1171 // Configuration.
1172 EXPECT_CALL(*syncer(), SyncShare(_, DOWNLOAD_UPDATES, APPLY_UPDATES))
1173 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
1174 Return(true)));
1175 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
1176
1177 ModelTypeSet model_types(BOOKMARKS);
1178 CallbackCounter counter;
1179 ConfigurationParams params(
1180 GetUpdatesCallerInfo::RECONFIGURATION,
1181 model_types,
1182 TypesToRoutingInfo(model_types),
1183 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter)));
1184 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params));
1185 ASSERT_EQ(1, counter.times_called());
1186 // Runs directly so no need to pump the loop.
1187 StopSyncScheduler();
1188 Mock::VerifyAndClearExpectations(syncer());
1189
1190 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
1191
1192 // Poll.
1193 EXPECT_CALL(*syncer(), SyncShare(_, DOWNLOAD_UPDATES, APPLY_UPDATES))
1194 .Times(AtLeast(1))
1195 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess),
1196 QuitLoopNowAction()));
1197 const TimeDelta poll(TimeDelta::FromMilliseconds(10));
1198 scheduler()->OnReceivedLongPollIntervalUpdate(poll);
1199
1200 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
1201
1202 // Run again to wait for polling.
1203 RunLoop();
1204
1205 StopSyncScheduler();
1206 Mock::VerifyAndClearExpectations(syncer());
1207 }
1208
1209 // Test that starting the syncer thread without a valid connection doesn't 1176 // Test that starting the syncer thread without a valid connection doesn't
1210 // break things when a connection is detected. 1177 // break things when a connection is detected.
1211 TEST_F(SyncSchedulerTest, StartWhenNotConnected) { 1178 TEST_F(SyncSchedulerTest, StartWhenNotConnected) {
1212 connection()->SetServerNotReachable(); 1179 connection()->SetServerNotReachable();
1213 connection()->UpdateConnectionStatus(); 1180 connection()->UpdateConnectionStatus();
1214 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 1181 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
1215 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConnectionFailure), 1182 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConnectionFailure),
1216 Return(true))) 1183 Return(true)))
1217 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 1184 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess),
1218 Return(true))); 1185 Return(true)));
1219 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 1186 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
1220 1187
1221 scheduler()->ScheduleLocalNudge(zero(), ModelTypeSet(BOOKMARKS), FROM_HERE); 1188 scheduler()->ScheduleLocalNudge(zero(), ModelTypeSet(BOOKMARKS), FROM_HERE);
1222 // Should save the nudge for until after the server is reachable. 1189 // Should save the nudge for until after the server is reachable.
1223 base::MessageLoop::current()->RunUntilIdle(); 1190 base::MessageLoop::current()->RunUntilIdle();
1224 1191
1225 scheduler()->OnConnectionStatusChange(); 1192 scheduler()->OnConnectionStatusChange();
1226 connection()->SetServerReachable(); 1193 connection()->SetServerReachable();
1227 connection()->UpdateConnectionStatus(); 1194 connection()->UpdateConnectionStatus();
1228 base::MessageLoop::current()->RunUntilIdle(); 1195 base::MessageLoop::current()->RunUntilIdle();
1229 } 1196 }
1230 1197
1231 TEST_F(SyncSchedulerTest, ServerConnectionChangeDuringBackoff) { 1198 TEST_F(SyncSchedulerTest, ServerConnectionChangeDuringBackoff) {
1232 UseMockDelayProvider(); 1199 UseMockDelayProvider();
1233 EXPECT_CALL(*delay(), GetDelay(_)) 1200 EXPECT_CALL(*delay(), GetDelay(_))
1234 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(0))); 1201 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(0)));
1235 1202
1236 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 1203 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
1237 connection()->SetServerNotReachable(); 1204 connection()->SetServerNotReachable();
1238 connection()->UpdateConnectionStatus(); 1205 connection()->UpdateConnectionStatus();
1239 1206
1240 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 1207 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
1241 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConnectionFailure), 1208 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConnectionFailure),
1242 Return(true))) 1209 Return(true)))
1243 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 1210 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess),
1244 Return(true))); 1211 Return(true)));
1245 1212
1246 scheduler()->ScheduleLocalNudge(zero(), ModelTypeSet(BOOKMARKS), FROM_HERE); 1213 scheduler()->ScheduleLocalNudge(zero(), ModelTypeSet(BOOKMARKS), FROM_HERE);
1247 1214
1248 PumpLoop(); // Run the nudge, that will fail and schedule a quick retry. 1215 PumpLoop(); // Run the nudge, that will fail and schedule a quick retry.
1249 ASSERT_TRUE(scheduler()->IsBackingOff()); 1216 ASSERT_TRUE(scheduler()->IsBackingOff());
1250 1217
1251 // Before we run the scheduled canary, trigger a server connection change. 1218 // Before we run the scheduled canary, trigger a server connection change.
1252 scheduler()->OnConnectionStatusChange(); 1219 scheduler()->OnConnectionStatusChange();
1253 connection()->SetServerReachable(); 1220 connection()->SetServerReachable();
1254 connection()->UpdateConnectionStatus(); 1221 connection()->UpdateConnectionStatus();
1255 base::MessageLoop::current()->RunUntilIdle(); 1222 base::MessageLoop::current()->RunUntilIdle();
1256 } 1223 }
1257 1224
1258 // This was supposed to test the scenario where we receive a nudge while a 1225 // This was supposed to test the scenario where we receive a nudge while a
1259 // connection change canary is scheduled, but has not run yet. Since we've made 1226 // connection change canary is scheduled, but has not run yet. Since we've made
1260 // the connection change canary synchronous, this is no longer possible. 1227 // the connection change canary synchronous, this is no longer possible.
1261 TEST_F(SyncSchedulerTest, ConnectionChangeCanaryPreemptedByNudge) { 1228 TEST_F(SyncSchedulerTest, ConnectionChangeCanaryPreemptedByNudge) {
1262 UseMockDelayProvider(); 1229 UseMockDelayProvider();
1263 EXPECT_CALL(*delay(), GetDelay(_)) 1230 EXPECT_CALL(*delay(), GetDelay(_))
1264 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(0))); 1231 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(0)));
1265 1232
1266 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 1233 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
1267 connection()->SetServerNotReachable(); 1234 connection()->SetServerNotReachable();
1268 connection()->UpdateConnectionStatus(); 1235 connection()->UpdateConnectionStatus();
1269 1236
1270 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 1237 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
1271 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConnectionFailure), 1238 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConnectionFailure),
1272 Return(true))) 1239 Return(true)))
1273 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 1240 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess),
1274 Return(true))) 1241 Return(true)))
1275 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 1242 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess),
1276 QuitLoopNowAction())); 1243 QuitLoopNowAction()));
1277 1244
1278 scheduler()->ScheduleLocalNudge(zero(), ModelTypeSet(BOOKMARKS), FROM_HERE); 1245 scheduler()->ScheduleLocalNudge(zero(), ModelTypeSet(BOOKMARKS), FROM_HERE);
1279 1246
1280 PumpLoop(); // Run the nudge, that will fail and schedule a quick retry. 1247 PumpLoop(); // Run the nudge, that will fail and schedule a quick retry.
1281 ASSERT_TRUE(scheduler()->IsBackingOff()); 1248 ASSERT_TRUE(scheduler()->IsBackingOff());
1282 1249
1283 // Before we run the scheduled canary, trigger a server connection change. 1250 // Before we run the scheduled canary, trigger a server connection change.
1284 scheduler()->OnConnectionStatusChange(); 1251 scheduler()->OnConnectionStatusChange();
1285 connection()->SetServerReachable(); 1252 connection()->SetServerReachable();
1286 connection()->UpdateConnectionStatus(); 1253 connection()->UpdateConnectionStatus();
1287 scheduler()->ScheduleLocalNudge(zero(), ModelTypeSet(BOOKMARKS), FROM_HERE); 1254 scheduler()->ScheduleLocalNudge(zero(), ModelTypeSet(BOOKMARKS), FROM_HERE);
1288 base::MessageLoop::current()->RunUntilIdle(); 1255 base::MessageLoop::current()->RunUntilIdle();
1289 } 1256 }
1290 1257
1291 // Tests that we don't crash trying to run two canaries at once if we receive 1258 // Tests that we don't crash trying to run two canaries at once if we receive
1292 // extra connection status change notifications. See crbug.com/190085. 1259 // extra connection status change notifications. See crbug.com/190085.
1293 TEST_F(SyncSchedulerTest, DoubleCanaryInConfigure) { 1260 TEST_F(SyncSchedulerTest, DoubleCanaryInConfigure) {
1294 EXPECT_CALL(*syncer(), SyncShare(_, DOWNLOAD_UPDATES, APPLY_UPDATES)) 1261 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_))
1295 .WillRepeatedly(DoAll( 1262 .WillRepeatedly(DoAll(
1296 Invoke(sessions::test_util::SimulateConnectionFailure), 1263 Invoke(sessions::test_util::SimulateConfigureConnectionFailure),
1297 Return(true))); 1264 Return(true)));
1298 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 1265 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
1299 connection()->SetServerNotReachable(); 1266 connection()->SetServerNotReachable();
1300 connection()->UpdateConnectionStatus(); 1267 connection()->UpdateConnectionStatus();
1301 1268
1302 ModelTypeSet model_types(BOOKMARKS); 1269 ModelTypeSet model_types(BOOKMARKS);
1303 CallbackCounter counter; 1270 CallbackCounter counter;
1304 ConfigurationParams params( 1271 ConfigurationParams params(
1305 GetUpdatesCallerInfo::RECONFIGURATION, 1272 GetUpdatesCallerInfo::RECONFIGURATION,
1306 model_types, 1273 model_types,
1307 TypesToRoutingInfo(model_types), 1274 TypesToRoutingInfo(model_types),
1308 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); 1275 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter)));
1309 scheduler()->ScheduleConfiguration(params); 1276 scheduler()->ScheduleConfiguration(params);
1310 1277
1311 scheduler()->OnConnectionStatusChange(); 1278 scheduler()->OnConnectionStatusChange();
1312 scheduler()->OnConnectionStatusChange(); 1279 scheduler()->OnConnectionStatusChange();
1313 1280
1314 PumpLoop(); // Run the nudge, that will fail and schedule a quick retry. 1281 PumpLoop(); // Run the nudge, that will fail and schedule a quick retry.
1315 } 1282 }
1316 1283
1317 } // namespace syncer 1284 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/engine/sync_scheduler_impl.cc ('k') | sync/engine/syncer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698