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

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

Issue 14963002: sync: Report GetUpdate triggers to the server (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update tests Created 7 years, 7 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
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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 } 81 }
82 82
83 ModelSafeRoutingInfo TypesToRoutingInfo(ModelTypeSet types) { 83 ModelSafeRoutingInfo TypesToRoutingInfo(ModelTypeSet types) {
84 ModelSafeRoutingInfo routes; 84 ModelSafeRoutingInfo routes;
85 for (ModelTypeSet::Iterator iter = types.First(); iter.Good(); iter.Inc()) { 85 for (ModelTypeSet::Iterator iter = types.First(); iter.Good(); iter.Inc()) {
86 routes[iter.Get()] = GROUP_PASSIVE; 86 routes[iter.Get()] = GROUP_PASSIVE;
87 } 87 }
88 return routes; 88 return routes;
89 } 89 }
90 90
91 // Compare a ModelTypeSet to a ModelTypeInvalidationMap, ignoring
92 // state values.
93 testing::AssertionResult ModelTypeSetMatchesInvalidationMap(
94 ModelTypeSet lhs, const ModelTypeInvalidationMap& rhs) {
95 ModelTypeSet rhs_set = ModelTypeInvalidationMapToSet(rhs);
96
97 if (!rhs_set.Equals(rhs_set)) {
98 return testing::AssertionFailure()
99 << "ModelTypeSet: " << ModelTypeSetToString(lhs)
100 << " does not match ModelTypeInvalidationMap: "
101 << ModelTypeSetToString(rhs_set);
102 } else {
103 return testing::AssertionSuccess();
104 }
105 }
106
91 // Convenient to use in tests wishing to analyze SyncShare calls over time. 107 // Convenient to use in tests wishing to analyze SyncShare calls over time.
92 static const size_t kMinNumSamples = 5; 108 static const size_t kMinNumSamples = 5;
93 class SyncSchedulerTest : public testing::Test { 109 class SyncSchedulerTest : public testing::Test {
94 public: 110 public:
95 SyncSchedulerTest() 111 SyncSchedulerTest()
96 : weak_ptr_factory_(this), 112 : weak_ptr_factory_(this),
97 context_(NULL), 113 context_(NULL),
98 syncer_(NULL), 114 syncer_(NULL),
99 delay_(NULL) {} 115 delay_(NULL) {}
100 116
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 void StopSyncScheduler() { 206 void StopSyncScheduler() {
191 scheduler()->RequestStop(base::Bind(&SyncSchedulerTest::DoQuitLoopNow, 207 scheduler()->RequestStop(base::Bind(&SyncSchedulerTest::DoQuitLoopNow,
192 weak_ptr_factory_.GetWeakPtr())); 208 weak_ptr_factory_.GetWeakPtr()));
193 RunLoop(); 209 RunLoop();
194 } 210 }
195 211
196 bool RunAndGetBackoff() { 212 bool RunAndGetBackoff() {
197 ModelTypeSet nudge_types(BOOKMARKS); 213 ModelTypeSet nudge_types(BOOKMARKS);
198 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 214 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
199 215
200 scheduler()->ScheduleNudgeAsync( 216 scheduler()->ScheduleLocalNudge(zero(), nudge_types, FROM_HERE);
201 zero(), NUDGE_SOURCE_LOCAL, nudge_types, FROM_HERE);
202 RunLoop(); 217 RunLoop();
203 218
204 return scheduler()->IsBackingOff(); 219 return scheduler()->IsBackingOff();
205 } 220 }
206 221
207 void UseMockDelayProvider() { 222 void UseMockDelayProvider() {
208 delay_ = new MockDelayProvider(); 223 delay_ = new MockDelayProvider();
209 scheduler_->delay_provider_.reset(delay_); 224 scheduler_->delay_provider_.reset(delay_);
210 } 225 }
211 226
212 // Compare a ModelTypeSet to a ModelTypeInvalidationMap, ignoring
213 // state values.
214 bool CompareModelTypeSetToModelTypeInvalidationMap(
215 ModelTypeSet lhs,
216 const ModelTypeInvalidationMap& rhs) {
217 size_t count = 0;
218 for (ModelTypeInvalidationMap::const_iterator i = rhs.begin();
219 i != rhs.end(); ++i, ++count) {
220 if (!lhs.Has(i->first))
221 return false;
222 }
223 if (lhs.Size() != count)
224 return false;
225 return true;
226 }
227
228 SyncSessionContext* context() { return context_.get(); } 227 SyncSessionContext* context() { return context_.get(); }
229 228
230 private: 229 private:
231 syncable::Directory* directory() { 230 syncable::Directory* directory() {
232 return dir_maker_.directory(); 231 return dir_maker_.directory();
233 } 232 }
234 233
235 base::WeakPtrFactory<SyncSchedulerTest> weak_ptr_factory_; 234 base::WeakPtrFactory<SyncSchedulerTest> weak_ptr_factory_;
236 MessageLoop message_loop_; 235 MessageLoop message_loop_;
237 TestDirectorySetterUpper dir_maker_; 236 TestDirectorySetterUpper dir_maker_;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 SyncShareRecords records; 283 SyncShareRecords records;
285 ModelTypeSet model_types(BOOKMARKS); 284 ModelTypeSet model_types(BOOKMARKS);
286 285
287 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 286 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
288 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 287 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
289 WithArg<0>(RecordSyncShare(&records)))) 288 WithArg<0>(RecordSyncShare(&records))))
290 .RetiresOnSaturation(); 289 .RetiresOnSaturation();
291 290
292 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 291 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
293 292
294 scheduler()->ScheduleNudgeAsync( 293 scheduler()->ScheduleLocalNudge(zero(), model_types, FROM_HERE);
295 zero(), NUDGE_SOURCE_LOCAL, model_types, FROM_HERE);
296 RunLoop(); 294 RunLoop();
297 295
298 ASSERT_EQ(1U, records.snapshots.size()); 296 ASSERT_EQ(1U, records.snapshots.size());
299 EXPECT_TRUE(CompareModelTypeSetToModelTypeInvalidationMap(model_types, 297 EXPECT_TRUE(ModelTypeSetMatchesInvalidationMap(
300 records.snapshots[0].source().types)); 298 model_types,
299 records.snapshots[0].source().types));
301 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, 300 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL,
302 records.snapshots[0].source().updates_source); 301 records.snapshots[0].source().updates_source);
303 302
304 Mock::VerifyAndClearExpectations(syncer()); 303 Mock::VerifyAndClearExpectations(syncer());
305 304
306 // 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).
307 SyncShareRecords records2; 306 SyncShareRecords records2;
308 model_types.Remove(BOOKMARKS); 307 model_types.Remove(BOOKMARKS);
309 model_types.Put(AUTOFILL); 308 model_types.Put(AUTOFILL);
310 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 309 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
311 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 310 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
312 WithArg<0>(RecordSyncShare(&records2)))); 311 WithArg<0>(RecordSyncShare(&records2))));
313 scheduler()->ScheduleNudgeAsync( 312 scheduler()->ScheduleLocalNudge(zero(), model_types, FROM_HERE);
314 zero(), NUDGE_SOURCE_LOCAL, model_types, FROM_HERE);
315 RunLoop(); 313 RunLoop();
316 314
317 ASSERT_EQ(1U, records2.snapshots.size()); 315 ASSERT_EQ(1U, records2.snapshots.size());
318 EXPECT_TRUE(CompareModelTypeSetToModelTypeInvalidationMap(model_types, 316 EXPECT_TRUE(ModelTypeSetMatchesInvalidationMap(
319 records2.snapshots[0].source().types)); 317 model_types,
318 records2.snapshots[0].source().types));
320 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, 319 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL,
321 records2.snapshots[0].source().updates_source); 320 records2.snapshots[0].source().updates_source);
322 } 321 }
323 322
324 // 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
325 // errors. 324 // errors.
326 TEST_F(SyncSchedulerTest, Config) { 325 TEST_F(SyncSchedulerTest, Config) {
327 SyncShareRecords records; 326 SyncShareRecords records;
328 const ModelTypeSet model_types(BOOKMARKS); 327 const ModelTypeSet model_types(BOOKMARKS);
329 328
330 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 329 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
331 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 330 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
332 WithArg<0>(RecordSyncShare(&records)))); 331 WithArg<0>(RecordSyncShare(&records))));
333 332
334 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 333 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
335 334
336 CallbackCounter counter; 335 CallbackCounter counter;
337 ConfigurationParams params( 336 ConfigurationParams params(
338 GetUpdatesCallerInfo::RECONFIGURATION, 337 GetUpdatesCallerInfo::RECONFIGURATION,
339 model_types, 338 model_types,
340 TypesToRoutingInfo(model_types), 339 TypesToRoutingInfo(model_types),
341 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); 340 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter)));
342 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params)); 341 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params));
343 ASSERT_EQ(1, counter.times_called()); 342 ASSERT_EQ(1, counter.times_called());
344 343
345 ASSERT_EQ(1U, records.snapshots.size()); 344 ASSERT_EQ(1U, records.snapshots.size());
346 EXPECT_TRUE(CompareModelTypeSetToModelTypeInvalidationMap(model_types, 345 EXPECT_TRUE(ModelTypeSetMatchesInvalidationMap(
347 records.snapshots[0].source().types)); 346 model_types,
347 records.snapshots[0].source().types));
348 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, 348 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION,
349 records.snapshots[0].source().updates_source); 349 records.snapshots[0].source().updates_source);
350 } 350 }
351 351
352 // Simulate a failure and make sure the config request is retried. 352 // Simulate a failure and make sure the config request is retried.
353 TEST_F(SyncSchedulerTest, ConfigWithBackingOff) { 353 TEST_F(SyncSchedulerTest, ConfigWithBackingOff) {
354 UseMockDelayProvider(); 354 UseMockDelayProvider();
355 EXPECT_CALL(*delay(), GetDelay(_)) 355 EXPECT_CALL(*delay(), GetDelay(_))
356 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(1))); 356 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(1)));
357 SyncShareRecords records; 357 SyncShareRecords records;
(...skipping 15 matching lines...) Expand all
373 TypesToRoutingInfo(model_types), 373 TypesToRoutingInfo(model_types),
374 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); 374 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter)));
375 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params)); 375 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params));
376 ASSERT_EQ(0, counter.times_called()); 376 ASSERT_EQ(0, counter.times_called());
377 377
378 ASSERT_EQ(1U, records.snapshots.size()); 378 ASSERT_EQ(1U, records.snapshots.size());
379 RunLoop(); 379 RunLoop();
380 380
381 ASSERT_EQ(2U, records.snapshots.size()); 381 ASSERT_EQ(2U, records.snapshots.size());
382 ASSERT_EQ(1, counter.times_called()); 382 ASSERT_EQ(1, counter.times_called());
383 EXPECT_TRUE(CompareModelTypeSetToModelTypeInvalidationMap(model_types, 383 EXPECT_TRUE(ModelTypeSetMatchesInvalidationMap(
384 records.snapshots[1].source().types)); 384 model_types,
385 records.snapshots[1].source().types));
385 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, 386 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION,
386 records.snapshots[1].source().updates_source); 387 records.snapshots[1].source().updates_source);
387 } 388 }
388 389
389 // 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
390 // nudge are executed. 391 // nudge are executed.
391 TEST_F(SyncSchedulerTest, NudgeWithConfigWithBackingOff) { 392 TEST_F(SyncSchedulerTest, NudgeWithConfigWithBackingOff) {
392 const ModelTypeSet model_types(BOOKMARKS); 393 const ModelTypeSet model_types(BOOKMARKS);
393 UseMockDelayProvider(); 394 UseMockDelayProvider();
394 EXPECT_CALL(*delay(), GetDelay(_)) 395 EXPECT_CALL(*delay(), GetDelay(_))
(...skipping 16 matching lines...) Expand all
411 CallbackCounter counter; 412 CallbackCounter counter;
412 ConfigurationParams params( 413 ConfigurationParams params(
413 GetUpdatesCallerInfo::RECONFIGURATION, 414 GetUpdatesCallerInfo::RECONFIGURATION,
414 model_types, 415 model_types,
415 TypesToRoutingInfo(model_types), 416 TypesToRoutingInfo(model_types),
416 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); 417 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter)));
417 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params)); 418 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params));
418 ASSERT_EQ(0, counter.times_called()); 419 ASSERT_EQ(0, counter.times_called());
419 ASSERT_EQ(1U, records.snapshots.size()); 420 ASSERT_EQ(1U, records.snapshots.size());
420 421
421 scheduler()->ScheduleNudgeAsync( 422 scheduler()->ScheduleLocalNudge(zero(), model_types, FROM_HERE);
422 zero(), NUDGE_SOURCE_LOCAL, model_types, FROM_HERE);
423 RunLoop(); 423 RunLoop();
424 // Note that we're not RunLoop()ing for the NUDGE we just scheduled, but 424 // Note that we're not RunLoop()ing for the NUDGE we just scheduled, but
425 // for the first retry attempt from the config job (after 425 // for the first retry attempt from the config job (after
426 // waiting ~+/- 50ms). 426 // waiting ~+/- 50ms).
427 ASSERT_EQ(2U, records.snapshots.size()); 427 ASSERT_EQ(2U, records.snapshots.size());
428 ASSERT_EQ(0, counter.times_called()); 428 ASSERT_EQ(0, counter.times_called());
429 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, 429 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION,
430 records.snapshots[1].source().updates_source); 430 records.snapshots[1].source().updates_source);
431 431
432 RunLoop(); 432 RunLoop();
433 // This is the 3rd attempt, which we've set up to SimulateSuccess. 433 // This is the 3rd attempt, which we've set up to SimulateSuccess.
434 ASSERT_EQ(3U, records.snapshots.size()); 434 ASSERT_EQ(3U, records.snapshots.size());
435 ASSERT_EQ(1, counter.times_called()); 435 ASSERT_EQ(1, counter.times_called());
436 436
437 // Now change the mode so nudge can execute. 437 // Now change the mode so nudge can execute.
438 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 438 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
439 439
440 ASSERT_EQ(4U, records.snapshots.size()); 440 ASSERT_EQ(4U, records.snapshots.size());
441 441
442 EXPECT_TRUE(CompareModelTypeSetToModelTypeInvalidationMap(model_types, 442 EXPECT_TRUE(ModelTypeSetMatchesInvalidationMap(
443 records.snapshots[2].source().types)); 443 model_types,
444 records.snapshots[2].source().types));
444 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, 445 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION,
445 records.snapshots[2].source().updates_source); 446 records.snapshots[2].source().updates_source);
446 447
447 EXPECT_TRUE(CompareModelTypeSetToModelTypeInvalidationMap(model_types, 448 EXPECT_TRUE(ModelTypeSetMatchesInvalidationMap(
448 records.snapshots[3].source().types)); 449 model_types,
450 records.snapshots[3].source().types));
449 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, 451 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL,
450 records.snapshots[3].source().updates_source); 452 records.snapshots[3].source().updates_source);
451 453
452 } 454 }
453 455
454 // Test that nudges are coalesced. 456 // Test that nudges are coalesced.
455 TEST_F(SyncSchedulerTest, NudgeCoalescing) { 457 TEST_F(SyncSchedulerTest, NudgeCoalescing) {
456 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 458 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
457 459
458 SyncShareRecords r; 460 SyncShareRecords r;
459 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 461 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
460 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 462 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
461 WithArg<0>(RecordSyncShare(&r)))); 463 WithArg<0>(RecordSyncShare(&r))));
462 const ModelTypeSet types1(BOOKMARKS), types2(AUTOFILL), types3(THEMES); 464 const ModelTypeSet types1(BOOKMARKS), types2(AUTOFILL), types3(THEMES);
463 TimeDelta delay = zero(); 465 TimeDelta delay = zero();
464 TimeTicks optimal_time = TimeTicks::Now() + delay; 466 TimeTicks optimal_time = TimeTicks::Now() + delay;
465 scheduler()->ScheduleNudgeAsync( 467 scheduler()->ScheduleLocalNudge(delay, types1, FROM_HERE);
466 delay, NUDGE_SOURCE_UNKNOWN, types1, FROM_HERE); 468 scheduler()->ScheduleLocalNudge(zero(), types2, FROM_HERE);
467 scheduler()->ScheduleNudgeAsync(
468 zero(), NUDGE_SOURCE_LOCAL, types2, FROM_HERE);
469 RunLoop(); 469 RunLoop();
470 470
471 ASSERT_EQ(1U, r.snapshots.size()); 471 ASSERT_EQ(1U, r.snapshots.size());
472 EXPECT_GE(r.times[0], optimal_time); 472 EXPECT_GE(r.times[0], optimal_time);
473 EXPECT_TRUE(CompareModelTypeSetToModelTypeInvalidationMap( 473 EXPECT_TRUE(ModelTypeSetMatchesInvalidationMap(
474 Union(types1, types2), r.snapshots[0].source().types)); 474 Union(types1, types2),
475 r.snapshots[0].source().types));
475 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, 476 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL,
476 r.snapshots[0].source().updates_source); 477 r.snapshots[0].source().updates_source);
477 478
478 Mock::VerifyAndClearExpectations(syncer()); 479 Mock::VerifyAndClearExpectations(syncer());
479 480
480 SyncShareRecords r2; 481 SyncShareRecords r2;
481 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 482 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
482 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 483 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
483 WithArg<0>(RecordSyncShare(&r2)))); 484 WithArg<0>(RecordSyncShare(&r2))));
484 scheduler()->ScheduleNudgeAsync( 485 scheduler()->ScheduleLocalNudge(zero(), types3, FROM_HERE);
485 zero(), NUDGE_SOURCE_NOTIFICATION, types3, FROM_HERE);
486 RunLoop(); 486 RunLoop();
487 487
488 ASSERT_EQ(1U, r2.snapshots.size()); 488 ASSERT_EQ(1U, r2.snapshots.size());
489 EXPECT_TRUE(CompareModelTypeSetToModelTypeInvalidationMap(types3, 489 EXPECT_TRUE(ModelTypeSetMatchesInvalidationMap(
490 r2.snapshots[0].source().types)); 490 types3,
491 EXPECT_EQ(GetUpdatesCallerInfo::NOTIFICATION, 491 r2.snapshots[0].source().types));
492 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL,
492 r2.snapshots[0].source().updates_source); 493 r2.snapshots[0].source().updates_source);
493 } 494 }
494 495
495 // Test that nudges are coalesced. 496 // Test that nudges are coalesced.
496 TEST_F(SyncSchedulerTest, NudgeCoalescingWithDifferentTimings) { 497 TEST_F(SyncSchedulerTest, NudgeCoalescingWithDifferentTimings) {
497 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 498 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
498 499
499 SyncShareRecords r; 500 SyncShareRecords r;
500 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 501 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
501 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 502 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
502 WithArg<0>(RecordSyncShare(&r)))); 503 WithArg<0>(RecordSyncShare(&r))));
503 ModelTypeSet types1(BOOKMARKS), types2(AUTOFILL), types3; 504 ModelTypeSet types1(BOOKMARKS), types2(AUTOFILL), types3;
504 505
505 // Create a huge time delay. 506 // Create a huge time delay.
506 TimeDelta delay = TimeDelta::FromDays(1); 507 TimeDelta delay = TimeDelta::FromDays(1);
507 508
508 scheduler()->ScheduleNudgeAsync( 509 scheduler()->ScheduleLocalNudge(delay, types1, FROM_HERE);
509 delay, NUDGE_SOURCE_UNKNOWN, types1, FROM_HERE); 510 scheduler()->ScheduleLocalNudge(zero(), types2, FROM_HERE);
510
511 scheduler()->ScheduleNudgeAsync(
512 zero(), NUDGE_SOURCE_UNKNOWN, types2, FROM_HERE);
513 511
514 TimeTicks min_time = TimeTicks::Now(); 512 TimeTicks min_time = TimeTicks::Now();
515 TimeTicks max_time = TimeTicks::Now() + delay; 513 TimeTicks max_time = TimeTicks::Now() + delay;
516 514
517 RunLoop(); 515 RunLoop();
518 516
519 // Make sure the sync has happened. 517 // Make sure the sync has happened.
520 ASSERT_EQ(1U, r.snapshots.size()); 518 ASSERT_EQ(1U, r.snapshots.size());
521 EXPECT_TRUE(CompareModelTypeSetToModelTypeInvalidationMap( 519 EXPECT_TRUE(ModelTypeSetMatchesInvalidationMap(
522 Union(types1, types2), r.snapshots[0].source().types)); 520 Union(types1, types2),
521 r.snapshots[0].source().types));
523 522
524 // Make sure the sync happened at the right time. 523 // Make sure the sync happened at the right time.
525 EXPECT_GE(r.times[0], min_time); 524 EXPECT_GE(r.times[0], min_time);
526 EXPECT_LE(r.times[0], max_time); 525 EXPECT_LE(r.times[0], max_time);
527 } 526 }
528 527
529 // Test nudge scheduling. 528 // Test nudge scheduling.
530 TEST_F(SyncSchedulerTest, NudgeWithStates) { 529 TEST_F(SyncSchedulerTest, NudgeWithStates) {
531 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 530 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
532 531
533 SyncShareRecords records; 532 SyncShareRecords records;
534 const ModelTypeSet types(BOOKMARKS); 533 const ModelTypeSet types(BOOKMARKS);
535 ModelTypeInvalidationMap invalidation_map = 534 ModelTypeInvalidationMap invalidation_map =
536 ModelTypeSetToInvalidationMap(types, "test"); 535 ModelTypeSetToInvalidationMap(types, "test");
537 536
538 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 537 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
539 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 538 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
540 WithArg<0>(RecordSyncShare(&records)))) 539 WithArg<0>(RecordSyncShare(&records))))
541 .RetiresOnSaturation(); 540 .RetiresOnSaturation();
542 scheduler()->ScheduleNudgeWithStatesAsync( 541 scheduler()->ScheduleInvalidation(zero(), invalidation_map, FROM_HERE);
543 zero(), NUDGE_SOURCE_LOCAL, invalidation_map, FROM_HERE);
544 RunLoop(); 542 RunLoop();
545 543
546 ASSERT_EQ(1U, records.snapshots.size()); 544 ASSERT_EQ(1U, records.snapshots.size());
547 EXPECT_THAT(invalidation_map, Eq(records.snapshots[0].source().types)); 545 EXPECT_THAT(invalidation_map, Eq(records.snapshots[0].source().types));
548 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, 546 EXPECT_EQ(GetUpdatesCallerInfo::NOTIFICATION,
549 records.snapshots[0].source().updates_source); 547 records.snapshots[0].source().updates_source);
550 548
551 Mock::VerifyAndClearExpectations(syncer()); 549 Mock::VerifyAndClearExpectations(syncer());
552 550
553 // Make sure a second, later, nudge is unaffected by first (no coalescing). 551 // Make sure a second, later, nudge is unaffected by first (no coalescing).
554 SyncShareRecords records2; 552 SyncShareRecords records2;
555 invalidation_map.erase(BOOKMARKS); 553 invalidation_map.erase(BOOKMARKS);
556 invalidation_map[AUTOFILL].payload = "test2"; 554 invalidation_map[AUTOFILL].payload = "test2";
557 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 555 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
558 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 556 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
559 WithArg<0>(RecordSyncShare(&records2)))); 557 WithArg<0>(RecordSyncShare(&records2))));
560 scheduler()->ScheduleNudgeWithStatesAsync( 558 scheduler()->ScheduleInvalidation(zero(), invalidation_map, FROM_HERE);
561 zero(), NUDGE_SOURCE_LOCAL, invalidation_map, FROM_HERE);
562 RunLoop(); 559 RunLoop();
563 560
564 ASSERT_EQ(1U, records2.snapshots.size()); 561 ASSERT_EQ(1U, records2.snapshots.size());
565 EXPECT_THAT(invalidation_map, Eq(records2.snapshots[0].source().types)); 562 EXPECT_THAT(invalidation_map, Eq(records2.snapshots[0].source().types));
566 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, 563 EXPECT_EQ(GetUpdatesCallerInfo::NOTIFICATION,
567 records2.snapshots[0].source().updates_source); 564 records2.snapshots[0].source().updates_source);
568 } 565 }
569 566
570 // Test that nudges are coalesced.
571 TEST_F(SyncSchedulerTest, NudgeWithStatesCoalescing) {
572 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
573
574 SyncShareRecords r;
575 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
576 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
577 WithArg<0>(RecordSyncShare(&r))));
578 ModelTypeInvalidationMap types1, types2, types3;
579 types1[BOOKMARKS].payload = "test1";
580 types2[AUTOFILL].payload = "test2";
581 types3[THEMES].payload = "test3";
582 TimeDelta delay = zero();
583 TimeTicks optimal_time = TimeTicks::Now() + delay;
584 scheduler()->ScheduleNudgeWithStatesAsync(
585 delay, NUDGE_SOURCE_UNKNOWN, types1, FROM_HERE);
586 scheduler()->ScheduleNudgeWithStatesAsync(
587 zero(), NUDGE_SOURCE_LOCAL, types2, FROM_HERE);
588 RunLoop();
589
590 ASSERT_EQ(1U, r.snapshots.size());
591 EXPECT_GE(r.times[0], optimal_time);
592 ModelTypeInvalidationMap coalesced_types;
593 CoalesceStates(types1, &coalesced_types);
594 CoalesceStates(types2, &coalesced_types);
595 EXPECT_THAT(coalesced_types, Eq(r.snapshots[0].source().types));
596 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL,
597 r.snapshots[0].source().updates_source);
598
599 Mock::VerifyAndClearExpectations(syncer());
600
601 SyncShareRecords r2;
602 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
603 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
604 WithArg<0>(RecordSyncShare(&r2))));
605 scheduler()->ScheduleNudgeWithStatesAsync(
606 zero(), NUDGE_SOURCE_NOTIFICATION, types3, FROM_HERE);
607 RunLoop();
608
609 ASSERT_EQ(1U, r2.snapshots.size());
610 EXPECT_THAT(types3, Eq(r2.snapshots[0].source().types));
611 EXPECT_EQ(GetUpdatesCallerInfo::NOTIFICATION,
612 r2.snapshots[0].source().updates_source);
613 }
614
615 // Test that polling works as expected. 567 // Test that polling works as expected.
616 TEST_F(SyncSchedulerTest, Polling) { 568 TEST_F(SyncSchedulerTest, Polling) {
617 SyncShareRecords records; 569 SyncShareRecords records;
618 TimeDelta poll_interval(TimeDelta::FromMilliseconds(30)); 570 TimeDelta poll_interval(TimeDelta::FromMilliseconds(30));
619 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(AtLeast(kMinNumSamples)) 571 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(AtLeast(kMinNumSamples))
620 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess), 572 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess),
621 WithArg<0>(RecordSyncShareMultiple(&records, kMinNumSamples)))); 573 WithArg<0>(RecordSyncShareMultiple(&records, kMinNumSamples))));
622 574
623 scheduler()->OnReceivedLongPollIntervalUpdate(poll_interval); 575 scheduler()->OnReceivedLongPollIntervalUpdate(poll_interval);
624 576
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 sessions::test_util::SimulateSessionsCommitDelayUpdate( 645 sessions::test_util::SimulateSessionsCommitDelayUpdate(
694 delay2)), 646 delay2)),
695 Invoke(sessions::test_util::SimulateSuccess), 647 Invoke(sessions::test_util::SimulateSuccess),
696 QuitLoopNowAction())); 648 QuitLoopNowAction()));
697 649
698 EXPECT_EQ(delay1, scheduler()->GetSessionsCommitDelay()); 650 EXPECT_EQ(delay1, scheduler()->GetSessionsCommitDelay());
699 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 651 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
700 652
701 EXPECT_EQ(delay1, scheduler()->GetSessionsCommitDelay()); 653 EXPECT_EQ(delay1, scheduler()->GetSessionsCommitDelay());
702 const ModelTypeSet model_types(BOOKMARKS); 654 const ModelTypeSet model_types(BOOKMARKS);
703 scheduler()->ScheduleNudgeAsync( 655 scheduler()->ScheduleLocalNudge(zero(), model_types, FROM_HERE);
704 zero(), NUDGE_SOURCE_LOCAL, model_types, FROM_HERE);
705 RunLoop(); 656 RunLoop();
706 657
707 EXPECT_EQ(delay2, scheduler()->GetSessionsCommitDelay()); 658 EXPECT_EQ(delay2, scheduler()->GetSessionsCommitDelay());
708 StopSyncScheduler(); 659 StopSyncScheduler();
709 } 660 }
710 661
711 // Test that no syncing occurs when throttled. 662 // Test that no syncing occurs when throttled.
712 TEST_F(SyncSchedulerTest, ThrottlingDoesThrottle) { 663 TEST_F(SyncSchedulerTest, ThrottlingDoesThrottle) {
713 const ModelTypeSet types(BOOKMARKS); 664 const ModelTypeSet types(BOOKMARKS);
714 TimeDelta poll(TimeDelta::FromMilliseconds(5)); 665 TimeDelta poll(TimeDelta::FromMilliseconds(5));
715 TimeDelta throttle(TimeDelta::FromMinutes(10)); 666 TimeDelta throttle(TimeDelta::FromMinutes(10));
716 scheduler()->OnReceivedLongPollIntervalUpdate(poll); 667 scheduler()->OnReceivedLongPollIntervalUpdate(poll);
717 668
718 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 669 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
719 .WillOnce(DoAll( 670 .WillOnce(DoAll(
720 WithArg<0>(sessions::test_util::SimulateThrottled(throttle)), 671 WithArg<0>(sessions::test_util::SimulateThrottled(throttle)),
721 Return(true))) 672 Return(true)))
722 .WillRepeatedly(AddFailureAndQuitLoopNow()); 673 .WillRepeatedly(AddFailureAndQuitLoopNow());
723 674
724 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 675 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
725 676
726 scheduler()->ScheduleNudgeAsync( 677 scheduler()->ScheduleLocalNudge(
727 TimeDelta::FromMicroseconds(1), NUDGE_SOURCE_LOCAL, types, FROM_HERE); 678 TimeDelta::FromMicroseconds(1), types, FROM_HERE);
728 PumpLoop(); 679 PumpLoop();
729 680
730 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 681 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
731 682
732 CallbackCounter counter; 683 CallbackCounter counter;
733 ConfigurationParams params( 684 ConfigurationParams params(
734 GetUpdatesCallerInfo::RECONFIGURATION, 685 GetUpdatesCallerInfo::RECONFIGURATION,
735 types, 686 types,
736 TypesToRoutingInfo(types), 687 TypesToRoutingInfo(types),
737 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); 688 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter)));
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 .WillOnce(DoAll( 727 .WillOnce(DoAll(
777 WithArg<0>(sessions::test_util::SimulateThrottled(throttle1)), 728 WithArg<0>(sessions::test_util::SimulateThrottled(throttle1)),
778 Return(true))) 729 Return(true)))
779 .RetiresOnSaturation(); 730 .RetiresOnSaturation();
780 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 731 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
781 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 732 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
782 QuitLoopNowAction())); 733 QuitLoopNowAction()));
783 734
784 const ModelTypeSet types(BOOKMARKS); 735 const ModelTypeSet types(BOOKMARKS);
785 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 736 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
786 scheduler()->ScheduleNudgeAsync( 737 scheduler()->ScheduleLocalNudge(zero(), types, FROM_HERE);
787 zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE);
788 738
789 PumpLoop(); 739 PumpLoop();
790 EXPECT_TRUE(scheduler()->IsSyncingCurrentlySilenced()); 740 EXPECT_TRUE(scheduler()->IsSyncingCurrentlySilenced());
791 RunLoop(); 741 RunLoop();
792 EXPECT_FALSE(scheduler()->IsSyncingCurrentlySilenced()); 742 EXPECT_FALSE(scheduler()->IsSyncingCurrentlySilenced());
793 743
794 StopSyncScheduler(); 744 StopSyncScheduler();
795 } 745 }
796 746
797 TEST_F(SyncSchedulerTest, ThrottlingExpiresFromConfigure) { 747 TEST_F(SyncSchedulerTest, ThrottlingExpiresFromConfigure) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
835 SyncShareRecords records; 785 SyncShareRecords records;
836 scheduler()->OnReceivedLongPollIntervalUpdate(poll); 786 scheduler()->OnReceivedLongPollIntervalUpdate(poll);
837 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 787 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
838 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 788 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
839 WithArg<0>(RecordSyncShare(&records)))) 789 WithArg<0>(RecordSyncShare(&records))))
840 .RetiresOnSaturation(); 790 .RetiresOnSaturation();
841 791
842 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 792 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
843 793
844 const ModelTypeSet nudge_types(AUTOFILL); 794 const ModelTypeSet nudge_types(AUTOFILL);
845 scheduler()->ScheduleNudgeAsync( 795 scheduler()->ScheduleLocalNudge(zero(), nudge_types, FROM_HERE);
846 zero(), NUDGE_SOURCE_LOCAL, nudge_types, FROM_HERE); 796 scheduler()->ScheduleLocalNudge(zero(), nudge_types, FROM_HERE);
847 scheduler()->ScheduleNudgeAsync(
848 zero(), NUDGE_SOURCE_LOCAL, nudge_types, FROM_HERE);
849 797
850 const ModelTypeSet config_types(BOOKMARKS); 798 const ModelTypeSet config_types(BOOKMARKS);
851 799
852 CallbackCounter counter; 800 CallbackCounter counter;
853 ConfigurationParams params( 801 ConfigurationParams params(
854 GetUpdatesCallerInfo::RECONFIGURATION, 802 GetUpdatesCallerInfo::RECONFIGURATION,
855 config_types, 803 config_types,
856 TypesToRoutingInfo(config_types), 804 TypesToRoutingInfo(config_types),
857 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); 805 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter)));
858 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params)); 806 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params));
859 ASSERT_EQ(1, counter.times_called()); 807 ASSERT_EQ(1, counter.times_called());
860 808
861 ASSERT_EQ(1U, records.snapshots.size()); 809 ASSERT_EQ(1U, records.snapshots.size());
862 EXPECT_TRUE(CompareModelTypeSetToModelTypeInvalidationMap(config_types, 810 EXPECT_TRUE(ModelTypeSetMatchesInvalidationMap(
863 records.snapshots[0].source().types)); 811 config_types,
812 records.snapshots[0].source().types));
864 813
865 // Switch to NORMAL_MODE to ensure NUDGES were properly saved and run. 814 // Switch to NORMAL_MODE to ensure NUDGES were properly saved and run.
866 // SyncSchedulerWhiteboxTest also provides coverage for this, but much 815 // SyncSchedulerWhiteboxTest also provides coverage for this, but much
867 // more targeted ('whitebox' style). 816 // more targeted ('whitebox' style).
868 scheduler()->OnReceivedLongPollIntervalUpdate(TimeDelta::FromDays(1)); 817 scheduler()->OnReceivedLongPollIntervalUpdate(TimeDelta::FromDays(1));
869 SyncShareRecords records2; 818 SyncShareRecords records2;
870 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 819 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
871 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 820 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
872 WithArg<0>(RecordSyncShare(&records2)))); 821 WithArg<0>(RecordSyncShare(&records2))));
873 822
874 // TODO(tim): Figure out how to remove this dangerous need to reset 823 // TODO(tim): Figure out how to remove this dangerous need to reset
875 // routing info between mode switches. 824 // routing info between mode switches.
876 context()->set_routing_info(routing_info()); 825 context()->set_routing_info(routing_info());
877 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 826 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
878 827
879 ASSERT_EQ(1U, records2.snapshots.size()); 828 ASSERT_EQ(1U, records2.snapshots.size());
880 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, 829 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL,
881 records2.snapshots[0].source().updates_source); 830 records2.snapshots[0].source().updates_source);
882 EXPECT_TRUE(CompareModelTypeSetToModelTypeInvalidationMap(nudge_types, 831 EXPECT_TRUE(ModelTypeSetMatchesInvalidationMap(
883 records2.snapshots[0].source().types)); 832 nudge_types,
833 records2.snapshots[0].source().types));
884 PumpLoop(); 834 PumpLoop();
885 } 835 }
886 836
887 class BackoffTriggersSyncSchedulerTest : public SyncSchedulerTest { 837 class BackoffTriggersSyncSchedulerTest : public SyncSchedulerTest {
888 virtual void SetUp() { 838 virtual void SetUp() {
889 SyncSchedulerTest::SetUp(); 839 SyncSchedulerTest::SetUp();
890 UseMockDelayProvider(); 840 UseMockDelayProvider();
891 EXPECT_CALL(*delay(), GetDelay(_)) 841 EXPECT_CALL(*delay(), GetDelay(_))
892 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(1))); 842 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(1)));
893 } 843 }
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
968 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 918 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
969 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), 919 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateCommitFailed),
970 RecordSyncShareMultiple(&r, 1U))); 920 RecordSyncShareMultiple(&r, 1U)));
971 EXPECT_CALL(*delay(), GetDelay(_)). 921 EXPECT_CALL(*delay(), GetDelay(_)).
972 WillRepeatedly(Return(TimeDelta::FromDays(1))); 922 WillRepeatedly(Return(TimeDelta::FromDays(1)));
973 923
974 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 924 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
975 925
976 // This nudge should fail and put us into backoff. Thanks to our mock 926 // This nudge should fail and put us into backoff. Thanks to our mock
977 // GetDelay() setup above, this will be a long backoff. 927 // GetDelay() setup above, this will be a long backoff.
978 scheduler()->ScheduleNudgeAsync(zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE); 928 scheduler()->ScheduleLocalNudge(zero(), types, FROM_HERE);
979 RunLoop(); 929 RunLoop();
980 930
981 Mock::VerifyAndClearExpectations(syncer()); 931 Mock::VerifyAndClearExpectations(syncer());
982 ASSERT_EQ(1U, r.snapshots.size()); 932 ASSERT_EQ(1U, r.snapshots.size());
983 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, 933 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL,
984 r.snapshots[0].source().updates_source); 934 r.snapshots[0].source().updates_source);
985 935
986 // Wait a while (10x poll interval) so a few poll jobs will be attempted. 936 // Wait a while (10x poll interval) so a few poll jobs will be attempted.
987 PumpLoopFor(poll * 10); 937 PumpLoopFor(poll * 10);
988 938
989 // Try (and fail) to schedule a nudge. 939 // Try (and fail) to schedule a nudge.
990 scheduler()->ScheduleNudgeAsync( 940 scheduler()->ScheduleLocalNudge(
991 base::TimeDelta::FromMilliseconds(1), 941 base::TimeDelta::FromMilliseconds(1),
992 NUDGE_SOURCE_LOCAL,
993 types, 942 types,
994 FROM_HERE); 943 FROM_HERE);
995 944
996 Mock::VerifyAndClearExpectations(syncer()); 945 Mock::VerifyAndClearExpectations(syncer());
997 Mock::VerifyAndClearExpectations(delay()); 946 Mock::VerifyAndClearExpectations(delay());
998 947
999 ASSERT_EQ(1U, r.snapshots.size()); 948 ASSERT_EQ(1U, r.snapshots.size());
1000 949
1001 EXPECT_CALL(*delay(), GetDelay(_)).Times(0); 950 EXPECT_CALL(*delay(), GetDelay(_)).Times(0);
1002 951
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1034 .RetiresOnSaturation(); 983 .RetiresOnSaturation();
1035 EXPECT_CALL(*delay(), GetDelay(third)).WillOnce(Return(fourth)) 984 EXPECT_CALL(*delay(), GetDelay(third)).WillOnce(Return(fourth))
1036 .RetiresOnSaturation(); 985 .RetiresOnSaturation();
1037 EXPECT_CALL(*delay(), GetDelay(fourth)).WillOnce(Return(fifth)) 986 EXPECT_CALL(*delay(), GetDelay(fourth)).WillOnce(Return(fifth))
1038 .RetiresOnSaturation(); 987 .RetiresOnSaturation();
1039 EXPECT_CALL(*delay(), GetDelay(fifth)).WillOnce(Return(sixth)); 988 EXPECT_CALL(*delay(), GetDelay(fifth)).WillOnce(Return(sixth));
1040 989
1041 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 990 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
1042 991
1043 // Run again with a nudge. 992 // Run again with a nudge.
1044 scheduler()->ScheduleNudgeAsync( 993 scheduler()->ScheduleLocalNudge(zero(), ModelTypeSet(BOOKMARKS), FROM_HERE);
1045 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(BOOKMARKS), FROM_HERE);
1046 RunLoop(); 994 RunLoop();
1047 995
1048 ASSERT_EQ(kMinNumSamples, r.snapshots.size()); 996 ASSERT_EQ(kMinNumSamples, r.snapshots.size());
1049 EXPECT_GE(r.times[1] - r.times[0], second); 997 EXPECT_GE(r.times[1] - r.times[0], second);
1050 EXPECT_GE(r.times[2] - r.times[1], third); 998 EXPECT_GE(r.times[2] - r.times[1], third);
1051 EXPECT_GE(r.times[3] - r.times[2], fourth); 999 EXPECT_GE(r.times[3] - r.times[2], fourth);
1052 EXPECT_GE(r.times[4] - r.times[3], fifth); 1000 EXPECT_GE(r.times[4] - r.times[3], fifth);
1053 } 1001 }
1054 1002
1055 // Test that things go back to normal once a retry makes forward progress. 1003 // Test that things go back to normal once a retry makes forward progress.
(...skipping 10 matching lines...) Expand all
1066 RecordSyncShareMultiple(&r, kMinNumSamples))) 1014 RecordSyncShareMultiple(&r, kMinNumSamples)))
1067 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess), 1015 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess),
1068 RecordSyncShareMultiple(&r, kMinNumSamples))); 1016 RecordSyncShareMultiple(&r, kMinNumSamples)));
1069 EXPECT_CALL(*delay(), GetDelay(_)).WillOnce(Return(backoff)); 1017 EXPECT_CALL(*delay(), GetDelay(_)).WillOnce(Return(backoff));
1070 1018
1071 // Optimal start for the post-backoff poll party. 1019 // Optimal start for the post-backoff poll party.
1072 TimeTicks optimal_start = TimeTicks::Now(); 1020 TimeTicks optimal_start = TimeTicks::Now();
1073 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 1021 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
1074 1022
1075 // Run again to wait for polling. 1023 // Run again to wait for polling.
1076 scheduler()->ScheduleNudgeAsync(zero(), NUDGE_SOURCE_LOCAL, 1024 scheduler()->ScheduleLocalNudge(zero(), ModelTypeSet(BOOKMARKS), FROM_HERE);
1077 ModelTypeSet(BOOKMARKS), FROM_HERE);
1078 RunLoop(); 1025 RunLoop();
1079 1026
1080 StopSyncScheduler(); 1027 StopSyncScheduler();
1081 1028
1082 EXPECT_EQ(kMinNumSamples, r.times.size()); 1029 EXPECT_EQ(kMinNumSamples, r.times.size());
1083 1030
1084 // The first nudge ran as soon as possible. It failed. 1031 // The first nudge ran as soon as possible. It failed.
1085 TimeTicks optimal_job_time = optimal_start; 1032 TimeTicks optimal_job_time = optimal_start;
1086 EXPECT_GE(r.times[0], optimal_job_time); 1033 EXPECT_GE(r.times[0], optimal_job_time);
1087 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, 1034 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL,
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1128 } 1075 }
1129 1076
1130 // Test that appropriate syncer steps are requested for each job type. 1077 // Test that appropriate syncer steps are requested for each job type.
1131 TEST_F(SyncSchedulerTest, SyncerSteps) { 1078 TEST_F(SyncSchedulerTest, SyncerSteps) {
1132 // Nudges. 1079 // Nudges.
1133 EXPECT_CALL(*syncer(), SyncShare(_, SYNCER_BEGIN, SYNCER_END)) 1080 EXPECT_CALL(*syncer(), SyncShare(_, SYNCER_BEGIN, SYNCER_END))
1134 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 1081 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
1135 Return(true))); 1082 Return(true)));
1136 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 1083 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
1137 1084
1138 scheduler()->ScheduleNudgeAsync( 1085 scheduler()->ScheduleLocalNudge(zero(), ModelTypeSet(BOOKMARKS), FROM_HERE);
1139 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(BOOKMARKS), FROM_HERE);
1140 PumpLoop(); 1086 PumpLoop();
1141 // Pump again to run job. 1087 // Pump again to run job.
1142 PumpLoop(); 1088 PumpLoop();
1143 1089
1144 StopSyncScheduler(); 1090 StopSyncScheduler();
1145 Mock::VerifyAndClearExpectations(syncer()); 1091 Mock::VerifyAndClearExpectations(syncer());
1146 1092
1147 // Configuration. 1093 // Configuration.
1148 EXPECT_CALL(*syncer(), SyncShare(_, DOWNLOAD_UPDATES, APPLY_UPDATES)) 1094 EXPECT_CALL(*syncer(), SyncShare(_, DOWNLOAD_UPDATES, APPLY_UPDATES))
1149 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 1095 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1187 TEST_F(SyncSchedulerTest, StartWhenNotConnected) { 1133 TEST_F(SyncSchedulerTest, StartWhenNotConnected) {
1188 connection()->SetServerNotReachable(); 1134 connection()->SetServerNotReachable();
1189 connection()->UpdateConnectionStatus(); 1135 connection()->UpdateConnectionStatus();
1190 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 1136 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
1191 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConnectionFailure), 1137 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConnectionFailure),
1192 Return(true))) 1138 Return(true)))
1193 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 1139 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
1194 Return(true))); 1140 Return(true)));
1195 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 1141 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
1196 1142
1197 scheduler()->ScheduleNudgeAsync( 1143 scheduler()->ScheduleLocalNudge(zero(), ModelTypeSet(BOOKMARKS), FROM_HERE);
1198 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(BOOKMARKS), FROM_HERE);
1199 // Should save the nudge for until after the server is reachable. 1144 // Should save the nudge for until after the server is reachable.
1200 MessageLoop::current()->RunUntilIdle(); 1145 MessageLoop::current()->RunUntilIdle();
1201 1146
1202 scheduler()->OnConnectionStatusChange(); 1147 scheduler()->OnConnectionStatusChange();
1203 connection()->SetServerReachable(); 1148 connection()->SetServerReachable();
1204 connection()->UpdateConnectionStatus(); 1149 connection()->UpdateConnectionStatus();
1205 MessageLoop::current()->RunUntilIdle(); 1150 MessageLoop::current()->RunUntilIdle();
1206 } 1151 }
1207 1152
1208 TEST_F(SyncSchedulerTest, ServerConnectionChangeDuringBackoff) { 1153 TEST_F(SyncSchedulerTest, ServerConnectionChangeDuringBackoff) {
1209 UseMockDelayProvider(); 1154 UseMockDelayProvider();
1210 EXPECT_CALL(*delay(), GetDelay(_)) 1155 EXPECT_CALL(*delay(), GetDelay(_))
1211 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(0))); 1156 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(0)));
1212 1157
1213 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 1158 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
1214 connection()->SetServerNotReachable(); 1159 connection()->SetServerNotReachable();
1215 connection()->UpdateConnectionStatus(); 1160 connection()->UpdateConnectionStatus();
1216 1161
1217 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 1162 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
1218 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConnectionFailure), 1163 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConnectionFailure),
1219 Return(true))) 1164 Return(true)))
1220 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 1165 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
1221 Return(true))); 1166 Return(true)));
1222 1167
1223 scheduler()->ScheduleNudgeAsync( 1168 scheduler()->ScheduleLocalNudge(zero(), ModelTypeSet(BOOKMARKS), FROM_HERE);
1224 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(BOOKMARKS), FROM_HERE);
1225 1169
1226 PumpLoop(); // Run the nudge, that will fail and schedule a quick retry. 1170 PumpLoop(); // Run the nudge, that will fail and schedule a quick retry.
1227 ASSERT_TRUE(scheduler()->IsBackingOff()); 1171 ASSERT_TRUE(scheduler()->IsBackingOff());
1228 1172
1229 // Before we run the scheduled canary, trigger a server connection change. 1173 // Before we run the scheduled canary, trigger a server connection change.
1230 scheduler()->OnConnectionStatusChange(); 1174 scheduler()->OnConnectionStatusChange();
1231 connection()->SetServerReachable(); 1175 connection()->SetServerReachable();
1232 connection()->UpdateConnectionStatus(); 1176 connection()->UpdateConnectionStatus();
1233 MessageLoop::current()->RunUntilIdle(); 1177 MessageLoop::current()->RunUntilIdle();
1234 } 1178 }
(...skipping 11 matching lines...) Expand all
1246 connection()->UpdateConnectionStatus(); 1190 connection()->UpdateConnectionStatus();
1247 1191
1248 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 1192 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
1249 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConnectionFailure), 1193 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConnectionFailure),
1250 Return(true))) 1194 Return(true)))
1251 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 1195 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
1252 Return(true))) 1196 Return(true)))
1253 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 1197 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
1254 QuitLoopNowAction())); 1198 QuitLoopNowAction()));
1255 1199
1256 scheduler()->ScheduleNudgeAsync( 1200 scheduler()->ScheduleLocalNudge(zero(), ModelTypeSet(BOOKMARKS), FROM_HERE);
1257 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(BOOKMARKS), FROM_HERE);
1258 1201
1259 PumpLoop(); // Run the nudge, that will fail and schedule a quick retry. 1202 PumpLoop(); // Run the nudge, that will fail and schedule a quick retry.
1260 ASSERT_TRUE(scheduler()->IsBackingOff()); 1203 ASSERT_TRUE(scheduler()->IsBackingOff());
1261 1204
1262 // Before we run the scheduled canary, trigger a server connection change. 1205 // Before we run the scheduled canary, trigger a server connection change.
1263 scheduler()->OnConnectionStatusChange(); 1206 scheduler()->OnConnectionStatusChange();
1264 connection()->SetServerReachable(); 1207 connection()->SetServerReachable();
1265 connection()->UpdateConnectionStatus(); 1208 connection()->UpdateConnectionStatus();
1266 scheduler()->ScheduleNudgeAsync( 1209 scheduler()->ScheduleLocalNudge(zero(), ModelTypeSet(BOOKMARKS), FROM_HERE);
1267 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(BOOKMARKS), FROM_HERE);
1268 MessageLoop::current()->RunUntilIdle(); 1210 MessageLoop::current()->RunUntilIdle();
1269 } 1211 }
1270 1212
1271 // Tests that we don't crash trying to run two canaries at once if we receive 1213 // Tests that we don't crash trying to run two canaries at once if we receive
1272 // extra connection status change notifications. See crbug.com/190085. 1214 // extra connection status change notifications. See crbug.com/190085.
1273 TEST_F(SyncSchedulerTest, DoubleCanaryInConfigure) { 1215 TEST_F(SyncSchedulerTest, DoubleCanaryInConfigure) {
1274 EXPECT_CALL(*syncer(), SyncShare(_, DOWNLOAD_UPDATES, APPLY_UPDATES)) 1216 EXPECT_CALL(*syncer(), SyncShare(_, DOWNLOAD_UPDATES, APPLY_UPDATES))
1275 .WillRepeatedly(DoAll( 1217 .WillRepeatedly(DoAll(
1276 Invoke(sessions::test_util::SimulateConnectionFailure), 1218 Invoke(sessions::test_util::SimulateConnectionFailure),
1277 Return(true))); 1219 Return(true)));
(...skipping 10 matching lines...) Expand all
1288 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); 1230 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter)));
1289 scheduler()->ScheduleConfiguration(params); 1231 scheduler()->ScheduleConfiguration(params);
1290 1232
1291 scheduler()->OnConnectionStatusChange(); 1233 scheduler()->OnConnectionStatusChange();
1292 scheduler()->OnConnectionStatusChange(); 1234 scheduler()->OnConnectionStatusChange();
1293 1235
1294 PumpLoop(); // Run the nudge, that will fail and schedule a quick retry. 1236 PumpLoop(); // Run the nudge, that will fail and schedule a quick retry.
1295 } 1237 }
1296 1238
1297 } // namespace syncer 1239 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698