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

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

Powered by Google App Engine
This is Rietveld 408576698