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

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

Issue 19982002: sync: Remove SyncSourceInfo (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/bind.h" 5 #include "base/bind.h"
6 #include "base/callback.h" 6 #include "base/callback.h"
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/memory/weak_ptr.h" 8 #include "base/memory/weak_ptr.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/test/test_timeouts.h" 10 #include "base/test/test_timeouts.h"
(...skipping 27 matching lines...) Expand all
38 using sessions::SyncSession; 38 using sessions::SyncSession;
39 using sessions::SyncSessionContext; 39 using sessions::SyncSessionContext;
40 using sessions::SyncSessionSnapshot; 40 using sessions::SyncSessionSnapshot;
41 using sync_pb::GetUpdatesCallerInfo; 41 using sync_pb::GetUpdatesCallerInfo;
42 42
43 class MockSyncer : public Syncer { 43 class MockSyncer : public Syncer {
44 public: 44 public:
45 MOCK_METHOD3(NormalSyncShare, bool(ModelTypeSet, 45 MOCK_METHOD3(NormalSyncShare, bool(ModelTypeSet,
46 const sessions::NudgeTracker&, 46 const sessions::NudgeTracker&,
47 sessions::SyncSession*)); 47 sessions::SyncSession*));
48 MOCK_METHOD2(ConfigureSyncShare, bool(ModelTypeSet, sessions::SyncSession*)); 48 MOCK_METHOD3(ConfigureSyncShare,
49 bool(ModelTypeSet,
50 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource,
51 SyncSession*));
49 MOCK_METHOD2(PollSyncShare, bool(ModelTypeSet, sessions::SyncSession*)); 52 MOCK_METHOD2(PollSyncShare, bool(ModelTypeSet, sessions::SyncSession*));
50 }; 53 };
51 54
52 // Used when tests want to record syncing activity to examine later. 55 // Used when tests want to record syncing activity to examine later.
56 enum SyncShareSource { POLL, CONFIG, NORMAL };
57
53 struct SyncShareRecords { 58 struct SyncShareRecords {
54 std::vector<TimeTicks> times; 59 std::vector<TimeTicks> times;
55 std::vector<SyncSessionSnapshot> snapshots; 60 std::vector<SyncShareSource> sources;
56 }; 61 };
57 62
58 void QuitLoopNow() { 63 void QuitLoopNow() {
59 // We use QuitNow() instead of Quit() as the latter may get stalled 64 // We use QuitNow() instead of Quit() as the latter may get stalled
60 // indefinitely in the presence of repeated timers with low delays 65 // indefinitely in the presence of repeated timers with low delays
61 // and a slow test (e.g., ThrottlingDoesThrottle [which has a poll 66 // and a slow test (e.g., ThrottlingDoesThrottle [which has a poll
62 // delay of 5ms] run under TSAN on the trybots). 67 // delay of 5ms] run under TSAN on the trybots).
63 base::MessageLoop::current()->QuitNow(); 68 base::MessageLoop::current()->QuitNow();
64 } 69 }
65 70
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 } 185 }
181 186
182 void AnalyzePollRun(const SyncShareRecords& records, size_t min_num_samples, 187 void AnalyzePollRun(const SyncShareRecords& records, size_t min_num_samples,
183 const TimeTicks& optimal_start, const TimeDelta& poll_interval) { 188 const TimeTicks& optimal_start, const TimeDelta& poll_interval) {
184 const std::vector<TimeTicks>& data(records.times); 189 const std::vector<TimeTicks>& data(records.times);
185 EXPECT_GE(data.size(), min_num_samples); 190 EXPECT_GE(data.size(), min_num_samples);
186 for (size_t i = 0; i < data.size(); i++) { 191 for (size_t i = 0; i < data.size(); i++) {
187 SCOPED_TRACE(testing::Message() << "SyncShare # (" << i << ")"); 192 SCOPED_TRACE(testing::Message() << "SyncShare # (" << i << ")");
188 TimeTicks optimal_next_sync = optimal_start + poll_interval * i; 193 TimeTicks optimal_next_sync = optimal_start + poll_interval * i;
189 EXPECT_GE(data[i], optimal_next_sync); 194 EXPECT_GE(data[i], optimal_next_sync);
190 EXPECT_EQ(GetUpdatesCallerInfo::PERIODIC, 195 EXPECT_EQ(POLL, records.sources[i]);
191 records.snapshots[i].source().updates_source);
192 } 196 }
193 } 197 }
194 198
195 void DoQuitLoopNow() { 199 void DoQuitLoopNow() {
196 QuitLoopNow(); 200 QuitLoopNow();
197 } 201 }
198 202
199 void StartSyncScheduler(SyncScheduler::Mode mode) { 203 void StartSyncScheduler(SyncScheduler::Mode mode) {
200 scheduler()->Start(mode); 204 scheduler()->Start(mode);
201 } 205 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 scoped_ptr<MockConnectionManager> connection_; 243 scoped_ptr<MockConnectionManager> connection_;
240 scoped_ptr<SyncSessionContext> context_; 244 scoped_ptr<SyncSessionContext> context_;
241 scoped_ptr<SyncSchedulerImpl> scheduler_; 245 scoped_ptr<SyncSchedulerImpl> scheduler_;
242 MockSyncer* syncer_; 246 MockSyncer* syncer_;
243 MockDelayProvider* delay_; 247 MockDelayProvider* delay_;
244 std::vector<scoped_refptr<FakeModelWorker> > workers_; 248 std::vector<scoped_refptr<FakeModelWorker> > workers_;
245 FakeExtensionsActivityMonitor extensions_activity_monitor_; 249 FakeExtensionsActivityMonitor extensions_activity_monitor_;
246 ModelSafeRoutingInfo routing_info_; 250 ModelSafeRoutingInfo routing_info_;
247 }; 251 };
248 252
249 void RecordSyncShareImpl(SyncSession* s, SyncShareRecords* record) { 253 void RecordSyncShareImpl(SyncShareSource source, SyncShareRecords* record) {
250 record->times.push_back(TimeTicks::Now()); 254 record->times.push_back(TimeTicks::Now());
251 record->snapshots.push_back(s->TakeSnapshot()); 255 record->sources.push_back(source);
252 } 256 }
253 257
254 ACTION_P(RecordSyncShare, record) { 258 ACTION_P2(RecordSyncShare, source, record) {
255 RecordSyncShareImpl(arg0, record); 259 RecordSyncShareImpl(source, record);
256 if (base::MessageLoop::current()->is_running()) 260 if (base::MessageLoop::current()->is_running())
257 QuitLoopNow(); 261 QuitLoopNow();
258 return true; 262 return true;
259 } 263 }
260 264
261 ACTION_P2(RecordSyncShareMultiple, record, quit_after) { 265 ACTION_P3(RecordSyncShareMultiple, source, record, quit_after) {
262 RecordSyncShareImpl(arg0, record); 266 RecordSyncShareImpl(source, record);
263 EXPECT_LE(record->times.size(), quit_after); 267 EXPECT_LE(record->times.size(), quit_after);
264 if (record->times.size() >= quit_after && 268 if (record->times.size() >= quit_after &&
265 base::MessageLoop::current()->is_running()) { 269 base::MessageLoop::current()->is_running()) {
266 QuitLoopNow(); 270 QuitLoopNow();
267 } 271 }
268 return true; 272 return true;
269 } 273 }
270 274
271 ACTION(AddFailureAndQuitLoopNow) { 275 ACTION(AddFailureAndQuitLoopNow) {
272 ADD_FAILURE(); 276 ADD_FAILURE();
273 QuitLoopNow(); 277 QuitLoopNow();
274 return true; 278 return true;
275 } 279 }
276 280
277 ACTION(QuitLoopNowAction) { 281 ACTION(QuitLoopNowAction) {
278 QuitLoopNow(); 282 QuitLoopNow();
279 return true; 283 return true;
280 } 284 }
281 285
282 // Test nudge scheduling. 286 // Test nudge scheduling.
283 TEST_F(SyncSchedulerTest, Nudge) { 287 TEST_F(SyncSchedulerTest, Nudge) {
284 SyncShareRecords records; 288 SyncShareRecords records;
285 ModelTypeSet model_types(BOOKMARKS); 289 ModelTypeSet model_types(BOOKMARKS);
286 290
287 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) 291 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
288 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), 292 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess),
289 WithArg<2>(RecordSyncShare(&records)))) 293 RecordSyncShare(NORMAL, &records)))
290 .RetiresOnSaturation(); 294 .RetiresOnSaturation();
291 295
292 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 296 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
293 297
294 scheduler()->ScheduleLocalNudge(zero(), model_types, FROM_HERE); 298 scheduler()->ScheduleLocalNudge(zero(), model_types, FROM_HERE);
295 RunLoop(); 299 RunLoop();
296 300
297 ASSERT_EQ(1U, records.snapshots.size()); 301 ASSERT_EQ(1U, records.sources.size());
298 EXPECT_TRUE(ModelTypeSetMatchesInvalidationMap( 302 EXPECT_EQ(NORMAL, records.sources[0]);
tim (not reviewing) 2013/08/01 17:16:38 This expectation doesn't fill the shoes of the pre
rlarocque 2013/08/01 21:01:41 You're right that this code tests less than it use
299 model_types,
300 records.snapshots[0].source().types));
301 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL,
302 records.snapshots[0].source().updates_source);
303 303
304 Mock::VerifyAndClearExpectations(syncer()); 304 Mock::VerifyAndClearExpectations(syncer());
305 305
306 // Make sure a second, later, nudge is unaffected by first (no coalescing). 306 // Make sure a second, later, nudge is unaffected by first (no coalescing).
307 SyncShareRecords records2; 307 SyncShareRecords records2;
308 model_types.Remove(BOOKMARKS); 308 model_types.Remove(BOOKMARKS);
309 model_types.Put(AUTOFILL); 309 model_types.Put(AUTOFILL);
310 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) 310 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
311 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), 311 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess),
312 WithArg<2>(RecordSyncShare(&records2)))); 312 RecordSyncShare(NORMAL, &records2)));
313 scheduler()->ScheduleLocalNudge(zero(), model_types, FROM_HERE); 313 scheduler()->ScheduleLocalNudge(zero(), model_types, FROM_HERE);
314 RunLoop(); 314 RunLoop();
315 315
316 ASSERT_EQ(1U, records2.snapshots.size()); 316 ASSERT_EQ(1U, records2.sources.size());
317 EXPECT_TRUE(ModelTypeSetMatchesInvalidationMap( 317 EXPECT_EQ(NORMAL, records2.sources[0]);
318 model_types,
319 records2.snapshots[0].source().types));
320 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL,
321 records2.snapshots[0].source().updates_source);
322 } 318 }
323 319
324 // Make sure a regular config command is scheduled fine in the absence of any 320 // Make sure a regular config command is scheduled fine in the absence of any
325 // errors. 321 // errors.
326 TEST_F(SyncSchedulerTest, Config) { 322 TEST_F(SyncSchedulerTest, Config) {
327 SyncShareRecords records; 323 SyncShareRecords records;
328 const ModelTypeSet model_types(BOOKMARKS); 324 const ModelTypeSet model_types(BOOKMARKS);
329 325
330 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_)) 326 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_))
331 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess), 327 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess),
332 WithArg<1>(RecordSyncShare(&records)))); 328 RecordSyncShare(CONFIG, &records)));
333 329
334 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 330 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
335 331
336 CallbackCounter counter; 332 CallbackCounter counter;
337 ConfigurationParams params( 333 ConfigurationParams params(
338 GetUpdatesCallerInfo::RECONFIGURATION, 334 GetUpdatesCallerInfo::RECONFIGURATION,
339 model_types, 335 model_types,
340 TypesToRoutingInfo(model_types), 336 TypesToRoutingInfo(model_types),
341 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); 337 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter)));
342 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params)); 338 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params));
343 ASSERT_EQ(1, counter.times_called()); 339 ASSERT_EQ(1, counter.times_called());
344 340
345 ASSERT_EQ(1U, records.snapshots.size()); 341 ASSERT_EQ(1U, records.sources.size());
346 EXPECT_TRUE(ModelTypeSetMatchesInvalidationMap( 342 EXPECT_EQ(CONFIG, records.sources[0]);
347 model_types,
348 records.snapshots[0].source().types));
349 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION,
350 records.snapshots[0].source().updates_source);
351 } 343 }
352 344
353 // Simulate a failure and make sure the config request is retried. 345 // Simulate a failure and make sure the config request is retried.
354 TEST_F(SyncSchedulerTest, ConfigWithBackingOff) { 346 TEST_F(SyncSchedulerTest, ConfigWithBackingOff) {
355 UseMockDelayProvider(); 347 UseMockDelayProvider();
356 EXPECT_CALL(*delay(), GetDelay(_)) 348 EXPECT_CALL(*delay(), GetDelay(_))
357 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(1))); 349 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(1)));
358 SyncShareRecords records; 350 SyncShareRecords records;
359 const ModelTypeSet model_types(BOOKMARKS); 351 const ModelTypeSet model_types(BOOKMARKS);
360 352
361 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_)) 353 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_))
362 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureFailed), 354 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureFailed),
363 WithArg<1>(RecordSyncShare(&records)))) 355 RecordSyncShare(CONFIG, &records)))
364 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess), 356 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess),
365 WithArg<1>(RecordSyncShare(&records)))); 357 RecordSyncShare(CONFIG, &records)));
366 358
367 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 359 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
368 360
369 ASSERT_EQ(0U, records.snapshots.size()); 361 ASSERT_EQ(0U, records.sources.size());
370 CallbackCounter counter; 362 CallbackCounter counter;
371 ConfigurationParams params( 363 ConfigurationParams params(
372 GetUpdatesCallerInfo::RECONFIGURATION, 364 GetUpdatesCallerInfo::RECONFIGURATION,
373 model_types, 365 model_types,
374 TypesToRoutingInfo(model_types), 366 TypesToRoutingInfo(model_types),
375 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); 367 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter)));
376 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params)); 368 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params));
377 ASSERT_EQ(0, counter.times_called()); 369 ASSERT_EQ(0, counter.times_called());
378 370
379 ASSERT_EQ(1U, records.snapshots.size()); 371 ASSERT_EQ(1U, records.sources.size());
380 RunLoop(); 372 RunLoop();
381 373
382 ASSERT_EQ(2U, records.snapshots.size()); 374 ASSERT_EQ(2U, records.sources.size());
383 ASSERT_EQ(1, counter.times_called()); 375 ASSERT_EQ(1, counter.times_called());
384 EXPECT_TRUE(ModelTypeSetMatchesInvalidationMap( 376 EXPECT_EQ(CONFIG, records.sources[1]);
385 model_types,
386 records.snapshots[1].source().types));
387 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION,
388 records.snapshots[1].source().updates_source);
389 } 377 }
390 378
391 // Issue a nudge when the config has failed. Make sure both the config and 379 // Issue a nudge when the config has failed. Make sure both the config and
392 // nudge are executed. 380 // nudge are executed.
393 TEST_F(SyncSchedulerTest, NudgeWithConfigWithBackingOff) { 381 TEST_F(SyncSchedulerTest, NudgeWithConfigWithBackingOff) {
394 const ModelTypeSet model_types(BOOKMARKS); 382 const ModelTypeSet model_types(BOOKMARKS);
395 UseMockDelayProvider(); 383 UseMockDelayProvider();
396 EXPECT_CALL(*delay(), GetDelay(_)) 384 EXPECT_CALL(*delay(), GetDelay(_))
397 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(50))); 385 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(50)));
398 SyncShareRecords records; 386 SyncShareRecords records;
399 387
400 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_)) 388 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_))
401 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureFailed), 389 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureFailed),
402 WithArg<1>(RecordSyncShare(&records)))) 390 RecordSyncShare(CONFIG, &records)))
403 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureFailed), 391 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureFailed),
404 WithArg<1>(RecordSyncShare(&records)))) 392 RecordSyncShare(CONFIG, &records)))
405 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess), 393 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess),
406 WithArg<1>(RecordSyncShare(&records)))); 394 RecordSyncShare(CONFIG, &records)));
407 395
408 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) 396 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
409 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), 397 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess),
410 WithArg<2>(RecordSyncShare(&records)))); 398 RecordSyncShare(NORMAL, &records)));
411 399
412 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 400 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
413 401
414 ASSERT_EQ(0U, records.snapshots.size()); 402 ASSERT_EQ(0U, records.sources.size());
415 CallbackCounter counter; 403 CallbackCounter counter;
416 ConfigurationParams params( 404 ConfigurationParams params(
417 GetUpdatesCallerInfo::RECONFIGURATION, 405 GetUpdatesCallerInfo::RECONFIGURATION,
418 model_types, 406 model_types,
419 TypesToRoutingInfo(model_types), 407 TypesToRoutingInfo(model_types),
420 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); 408 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter)));
421 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params)); 409 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params));
422 ASSERT_EQ(0, counter.times_called()); 410 ASSERT_EQ(0, counter.times_called());
423 ASSERT_EQ(1U, records.snapshots.size()); 411 ASSERT_EQ(1U, records.sources.size());
424 412
425 scheduler()->ScheduleLocalNudge(zero(), model_types, FROM_HERE); 413 scheduler()->ScheduleLocalNudge(zero(), model_types, FROM_HERE);
426 RunLoop(); 414 RunLoop();
427 // Note that we're not RunLoop()ing for the NUDGE we just scheduled, but 415 // Note that we're not RunLoop()ing for the NUDGE we just scheduled, but
428 // for the first retry attempt from the config job (after 416 // for the first retry attempt from the config job (after
429 // waiting ~+/- 50ms). 417 // waiting ~+/- 50ms).
430 ASSERT_EQ(2U, records.snapshots.size()); 418 ASSERT_EQ(2U, records.sources.size());
431 ASSERT_EQ(0, counter.times_called()); 419 ASSERT_EQ(0, counter.times_called());
432 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, 420 EXPECT_EQ(CONFIG, records.sources[1]);
433 records.snapshots[1].source().updates_source);
434 421
435 RunLoop(); 422 RunLoop();
436 // This is the 3rd attempt, which we've set up to SimulateSuccess. 423 // This is the 3rd attempt, which we've set up to SimulateSuccess.
437 ASSERT_EQ(3U, records.snapshots.size()); 424 ASSERT_EQ(3U, records.sources.size());
438 ASSERT_EQ(1, counter.times_called()); 425 ASSERT_EQ(1, counter.times_called());
439 426
440 // Now change the mode so nudge can execute. 427 // Now change the mode so nudge can execute.
441 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 428 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
442 429
443 ASSERT_EQ(4U, records.snapshots.size()); 430 ASSERT_EQ(4U, records.sources.size());
444 431 EXPECT_EQ(CONFIG, records.sources[2]);
445 EXPECT_TRUE(ModelTypeSetMatchesInvalidationMap( 432 EXPECT_EQ(NORMAL, records.sources[3]);
446 model_types,
447 records.snapshots[2].source().types));
448 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION,
449 records.snapshots[2].source().updates_source);
450
451 EXPECT_TRUE(ModelTypeSetMatchesInvalidationMap(
452 model_types,
453 records.snapshots[3].source().types));
454 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL,
455 records.snapshots[3].source().updates_source);
456
457 } 433 }
458 434
459 // Test that nudges are coalesced. 435 // Test that nudges are coalesced.
460 TEST_F(SyncSchedulerTest, NudgeCoalescing) { 436 TEST_F(SyncSchedulerTest, NudgeCoalescing) {
461 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 437 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
462 438
463 SyncShareRecords r; 439 SyncShareRecords r;
464 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) 440 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
465 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), 441 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess),
466 WithArg<2>(RecordSyncShare(&r)))); 442 RecordSyncShare(NORMAL, &r)));
467 const ModelTypeSet types1(BOOKMARKS), types2(AUTOFILL), types3(THEMES); 443 const ModelTypeSet types1(BOOKMARKS), types2(AUTOFILL), types3(THEMES);
468 TimeDelta delay = zero(); 444 TimeDelta delay = zero();
469 TimeTicks optimal_time = TimeTicks::Now() + delay; 445 TimeTicks optimal_time = TimeTicks::Now() + delay;
470 scheduler()->ScheduleLocalNudge(delay, types1, FROM_HERE); 446 scheduler()->ScheduleLocalNudge(delay, types1, FROM_HERE);
471 scheduler()->ScheduleLocalNudge(zero(), types2, FROM_HERE); 447 scheduler()->ScheduleLocalNudge(zero(), types2, FROM_HERE);
472 RunLoop(); 448 RunLoop();
473 449
474 ASSERT_EQ(1U, r.snapshots.size()); 450 ASSERT_EQ(1U, r.sources.size());
475 EXPECT_GE(r.times[0], optimal_time); 451 EXPECT_GE(r.times[0], optimal_time);
476 EXPECT_TRUE(ModelTypeSetMatchesInvalidationMap( 452 EXPECT_EQ(NORMAL, r.sources[0]);
477 Union(types1, types2),
478 r.snapshots[0].source().types));
479 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL,
480 r.snapshots[0].source().updates_source);
481 453
482 Mock::VerifyAndClearExpectations(syncer()); 454 Mock::VerifyAndClearExpectations(syncer());
483 455
484 SyncShareRecords r2; 456 SyncShareRecords r2;
485 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) 457 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
486 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), 458 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess),
487 WithArg<2>(RecordSyncShare(&r2)))); 459 RecordSyncShare(NORMAL, &r2)));
488 scheduler()->ScheduleLocalNudge(zero(), types3, FROM_HERE); 460 scheduler()->ScheduleLocalNudge(zero(), types3, FROM_HERE);
489 RunLoop(); 461 RunLoop();
490 462
491 ASSERT_EQ(1U, r2.snapshots.size()); 463 ASSERT_EQ(1U, r2.sources.size());
492 EXPECT_TRUE(ModelTypeSetMatchesInvalidationMap( 464 EXPECT_EQ(NORMAL, r2.sources[0]);
493 types3,
494 r2.snapshots[0].source().types));
495 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL,
496 r2.snapshots[0].source().updates_source);
497 } 465 }
498 466
499 // Test that nudges are coalesced. 467 // Test that nudges are coalesced.
500 TEST_F(SyncSchedulerTest, NudgeCoalescingWithDifferentTimings) { 468 TEST_F(SyncSchedulerTest, NudgeCoalescingWithDifferentTimings) {
501 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 469 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
502 470
503 SyncShareRecords r; 471 SyncShareRecords r;
504 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) 472 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
505 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), 473 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess),
506 WithArg<2>(RecordSyncShare(&r)))); 474 RecordSyncShare(NORMAL, &r)));
507 ModelTypeSet types1(BOOKMARKS), types2(AUTOFILL), types3; 475 ModelTypeSet types1(BOOKMARKS), types2(AUTOFILL), types3;
508 476
509 // Create a huge time delay. 477 // Create a huge time delay.
510 TimeDelta delay = TimeDelta::FromDays(1); 478 TimeDelta delay = TimeDelta::FromDays(1);
511 479
512 scheduler()->ScheduleLocalNudge(delay, types1, FROM_HERE); 480 scheduler()->ScheduleLocalNudge(delay, types1, FROM_HERE);
513 scheduler()->ScheduleLocalNudge(zero(), types2, FROM_HERE); 481 scheduler()->ScheduleLocalNudge(zero(), types2, FROM_HERE);
514 482
515 TimeTicks min_time = TimeTicks::Now(); 483 TimeTicks min_time = TimeTicks::Now();
516 TimeTicks max_time = TimeTicks::Now() + delay; 484 TimeTicks max_time = TimeTicks::Now() + delay;
517 485
518 RunLoop(); 486 RunLoop();
519 487
520 // Make sure the sync has happened. 488 // Make sure the sync has happened.
521 ASSERT_EQ(1U, r.snapshots.size()); 489 ASSERT_EQ(1U, r.sources.size());
522 EXPECT_TRUE(ModelTypeSetMatchesInvalidationMap(
523 Union(types1, types2),
524 r.snapshots[0].source().types));
525 490
526 // Make sure the sync happened at the right time. 491 // Make sure the sync happened at the right time.
527 EXPECT_GE(r.times[0], min_time); 492 EXPECT_GE(r.times[0], min_time);
528 EXPECT_LE(r.times[0], max_time); 493 EXPECT_LE(r.times[0], max_time);
529 } 494 }
530 495
531 // Test nudge scheduling. 496 // Test nudge scheduling.
532 TEST_F(SyncSchedulerTest, NudgeWithStates) { 497 TEST_F(SyncSchedulerTest, NudgeWithStates) {
533 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 498 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
534 499
535 SyncShareRecords records; 500 SyncShareRecords records;
536 const ModelTypeSet types(BOOKMARKS); 501 const ModelTypeSet types(BOOKMARKS);
537 ModelTypeInvalidationMap invalidation_map = 502 ModelTypeInvalidationMap invalidation_map =
538 ModelTypeSetToInvalidationMap(types, "test"); 503 ModelTypeSetToInvalidationMap(types, "test");
539 504
540 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) 505 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
541 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), 506 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess),
542 WithArg<2>(RecordSyncShare(&records)))) 507 RecordSyncShare(NORMAL, &records)))
543 .RetiresOnSaturation(); 508 .RetiresOnSaturation();
544 scheduler()->ScheduleInvalidationNudge(zero(), invalidation_map, FROM_HERE); 509 scheduler()->ScheduleInvalidationNudge(zero(), invalidation_map, FROM_HERE);
545 RunLoop(); 510 RunLoop();
546 511
547 ASSERT_EQ(1U, records.snapshots.size()); 512 ASSERT_EQ(1U, records.sources.size());
548 EXPECT_THAT(invalidation_map, Eq(records.snapshots[0].source().types)); 513 EXPECT_EQ(NORMAL, records.sources[0]);
549 EXPECT_EQ(GetUpdatesCallerInfo::NOTIFICATION,
550 records.snapshots[0].source().updates_source);
551 514
552 Mock::VerifyAndClearExpectations(syncer()); 515 Mock::VerifyAndClearExpectations(syncer());
553 516
554 // Make sure a second, later, nudge is unaffected by first (no coalescing). 517 // Make sure a second, later, nudge is unaffected by first (no coalescing).
555 SyncShareRecords records2; 518 SyncShareRecords records2;
556 invalidation_map.erase(BOOKMARKS); 519 invalidation_map.erase(BOOKMARKS);
557 invalidation_map[AUTOFILL].payload = "test2"; 520 invalidation_map[AUTOFILL].payload = "test2";
558 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) 521 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
559 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), 522 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess),
560 WithArg<2>(RecordSyncShare(&records2)))); 523 RecordSyncShare(NORMAL, &records2)));
561 scheduler()->ScheduleInvalidationNudge(zero(), invalidation_map, FROM_HERE); 524 scheduler()->ScheduleInvalidationNudge(zero(), invalidation_map, FROM_HERE);
562 RunLoop(); 525 RunLoop();
563 526
564 ASSERT_EQ(1U, records2.snapshots.size()); 527 ASSERT_EQ(1U, records2.sources.size());
565 EXPECT_THAT(invalidation_map, Eq(records2.snapshots[0].source().types)); 528 EXPECT_EQ(NORMAL, records2.sources[0]);
566 EXPECT_EQ(GetUpdatesCallerInfo::NOTIFICATION,
567 records2.snapshots[0].source().updates_source);
568 } 529 }
569 530
570 // Test that polling works as expected. 531 // Test that polling works as expected.
571 TEST_F(SyncSchedulerTest, Polling) { 532 TEST_F(SyncSchedulerTest, Polling) {
572 SyncShareRecords records; 533 SyncShareRecords records;
573 TimeDelta poll_interval(TimeDelta::FromMilliseconds(30)); 534 TimeDelta poll_interval(TimeDelta::FromMilliseconds(30));
574 EXPECT_CALL(*syncer(), PollSyncShare(_,_)).Times(AtLeast(kMinNumSamples)) 535 EXPECT_CALL(*syncer(), PollSyncShare(_,_)).Times(AtLeast(kMinNumSamples))
575 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulatePollSuccess), 536 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulatePollSuccess),
576 WithArg<1>(RecordSyncShareMultiple(&records, kMinNumSamples)))); 537 RecordSyncShareMultiple(POLL, &records, kMinNumSamples)));
577 538
578 scheduler()->OnReceivedLongPollIntervalUpdate(poll_interval); 539 scheduler()->OnReceivedLongPollIntervalUpdate(poll_interval);
579 540
580 TimeTicks optimal_start = TimeTicks::Now() + poll_interval; 541 TimeTicks optimal_start = TimeTicks::Now() + poll_interval;
581 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 542 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
582 543
583 // Run again to wait for polling. 544 // Run again to wait for polling.
584 RunLoop(); 545 RunLoop();
585 546
586 StopSyncScheduler(); 547 StopSyncScheduler();
587 AnalyzePollRun(records, kMinNumSamples, optimal_start, poll_interval); 548 AnalyzePollRun(records, kMinNumSamples, optimal_start, poll_interval);
588 } 549 }
589 550
590 // Test that the short poll interval is used. 551 // Test that the short poll interval is used.
591 TEST_F(SyncSchedulerTest, PollNotificationsDisabled) { 552 TEST_F(SyncSchedulerTest, PollNotificationsDisabled) {
592 SyncShareRecords records; 553 SyncShareRecords records;
593 TimeDelta poll_interval(TimeDelta::FromMilliseconds(30)); 554 TimeDelta poll_interval(TimeDelta::FromMilliseconds(30));
594 EXPECT_CALL(*syncer(), PollSyncShare(_,_)).Times(AtLeast(kMinNumSamples)) 555 EXPECT_CALL(*syncer(), PollSyncShare(_,_)).Times(AtLeast(kMinNumSamples))
595 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulatePollSuccess), 556 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulatePollSuccess),
596 WithArg<1>(RecordSyncShareMultiple(&records, kMinNumSamples)))); 557 RecordSyncShareMultiple(POLL, &records, kMinNumSamples)));
597 558
598 scheduler()->OnReceivedShortPollIntervalUpdate(poll_interval); 559 scheduler()->OnReceivedShortPollIntervalUpdate(poll_interval);
599 scheduler()->SetNotificationsEnabled(false); 560 scheduler()->SetNotificationsEnabled(false);
600 561
601 TimeTicks optimal_start = TimeTicks::Now() + poll_interval; 562 TimeTicks optimal_start = TimeTicks::Now() + poll_interval;
602 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 563 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
603 564
604 // Run again to wait for polling. 565 // Run again to wait for polling.
605 RunLoop(); 566 RunLoop();
606 567
607 StopSyncScheduler(); 568 StopSyncScheduler();
608 AnalyzePollRun(records, kMinNumSamples, optimal_start, poll_interval); 569 AnalyzePollRun(records, kMinNumSamples, optimal_start, poll_interval);
609 } 570 }
610 571
611 // Test that polling intervals are updated when needed. 572 // Test that polling intervals are updated when needed.
612 TEST_F(SyncSchedulerTest, PollIntervalUpdate) { 573 TEST_F(SyncSchedulerTest, PollIntervalUpdate) {
613 SyncShareRecords records; 574 SyncShareRecords records;
614 TimeDelta poll1(TimeDelta::FromMilliseconds(120)); 575 TimeDelta poll1(TimeDelta::FromMilliseconds(120));
615 TimeDelta poll2(TimeDelta::FromMilliseconds(30)); 576 TimeDelta poll2(TimeDelta::FromMilliseconds(30));
616 scheduler()->OnReceivedLongPollIntervalUpdate(poll1); 577 scheduler()->OnReceivedLongPollIntervalUpdate(poll1);
617 EXPECT_CALL(*syncer(), PollSyncShare(_,_)).Times(AtLeast(kMinNumSamples)) 578 EXPECT_CALL(*syncer(), PollSyncShare(_,_)).Times(AtLeast(kMinNumSamples))
618 .WillOnce(DoAll( 579 .WillOnce(DoAll(
619 WithArgs<0,1>( 580 WithArgs<0,1>(
620 sessions::test_util::SimulatePollIntervalUpdate(poll2)), 581 sessions::test_util::SimulatePollIntervalUpdate(poll2)),
621 Return(true))) 582 Return(true)))
622 .WillRepeatedly( 583 .WillRepeatedly(
623 DoAll(Invoke(sessions::test_util::SimulatePollSuccess), 584 DoAll(Invoke(sessions::test_util::SimulatePollSuccess),
624 WithArg<1>( 585 WithArg<1>(
625 RecordSyncShareMultiple(&records, kMinNumSamples)))); 586 RecordSyncShareMultiple(POLL, &records, kMinNumSamples))));
626 587
627 TimeTicks optimal_start = TimeTicks::Now() + poll1 + poll2; 588 TimeTicks optimal_start = TimeTicks::Now() + poll1 + poll2;
628 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 589 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
629 590
630 // Run again to wait for polling. 591 // Run again to wait for polling.
631 RunLoop(); 592 RunLoop();
632 593
633 StopSyncScheduler(); 594 StopSyncScheduler();
634 AnalyzePollRun(records, kMinNumSamples, optimal_start, poll2); 595 AnalyzePollRun(records, kMinNumSamples, optimal_start, poll2);
635 } 596 }
(...skipping 26 matching lines...) Expand all
662 StopSyncScheduler(); 623 StopSyncScheduler();
663 } 624 }
664 625
665 // Test that no syncing occurs when throttled. 626 // Test that no syncing occurs when throttled.
666 TEST_F(SyncSchedulerTest, ThrottlingDoesThrottle) { 627 TEST_F(SyncSchedulerTest, ThrottlingDoesThrottle) {
667 const ModelTypeSet types(BOOKMARKS); 628 const ModelTypeSet types(BOOKMARKS);
668 TimeDelta poll(TimeDelta::FromMilliseconds(5)); 629 TimeDelta poll(TimeDelta::FromMilliseconds(5));
669 TimeDelta throttle(TimeDelta::FromMinutes(10)); 630 TimeDelta throttle(TimeDelta::FromMinutes(10));
670 scheduler()->OnReceivedLongPollIntervalUpdate(poll); 631 scheduler()->OnReceivedLongPollIntervalUpdate(poll);
671 632
672 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_)) 633 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_))
673 .WillOnce(DoAll( 634 .WillOnce(DoAll(
674 WithArg<1>(sessions::test_util::SimulateThrottled(throttle)), 635 WithArg<2>(sessions::test_util::SimulateThrottled(throttle)),
675 Return(true))) 636 Return(true)))
676 .WillRepeatedly(AddFailureAndQuitLoopNow()); 637 .WillRepeatedly(AddFailureAndQuitLoopNow());
677 638
678 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 639 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
679 640
680 scheduler()->ScheduleLocalNudge( 641 scheduler()->ScheduleLocalNudge(
681 TimeDelta::FromMicroseconds(1), types, FROM_HERE); 642 TimeDelta::FromMicroseconds(1), types, FROM_HERE);
682 PumpLoop(); 643 PumpLoop();
683 644
684 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 645 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
(...skipping 15 matching lines...) Expand all
700 scheduler()->OnReceivedLongPollIntervalUpdate(poll); 661 scheduler()->OnReceivedLongPollIntervalUpdate(poll);
701 662
702 ::testing::InSequence seq; 663 ::testing::InSequence seq;
703 EXPECT_CALL(*syncer(), PollSyncShare(_,_)) 664 EXPECT_CALL(*syncer(), PollSyncShare(_,_))
704 .WillOnce(DoAll( 665 .WillOnce(DoAll(
705 WithArg<1>(sessions::test_util::SimulateThrottled(throttle1)), 666 WithArg<1>(sessions::test_util::SimulateThrottled(throttle1)),
706 Return(true))) 667 Return(true)))
707 .RetiresOnSaturation(); 668 .RetiresOnSaturation();
708 EXPECT_CALL(*syncer(), PollSyncShare(_,_)) 669 EXPECT_CALL(*syncer(), PollSyncShare(_,_))
709 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulatePollSuccess), 670 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulatePollSuccess),
710 WithArg<1>(RecordSyncShareMultiple(&records, kMinNumSamples)))); 671 RecordSyncShareMultiple(POLL, &records, kMinNumSamples)));
711 672
712 TimeTicks optimal_start = TimeTicks::Now() + poll + throttle1; 673 TimeTicks optimal_start = TimeTicks::Now() + poll + throttle1;
713 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 674 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
714 675
715 // Run again to wait for polling. 676 // Run again to wait for polling.
716 RunLoop(); 677 RunLoop();
717 678
718 StopSyncScheduler(); 679 StopSyncScheduler();
719 AnalyzePollRun(records, kMinNumSamples, optimal_start, poll); 680 AnalyzePollRun(records, kMinNumSamples, optimal_start, poll);
720 } 681 }
(...skipping 26 matching lines...) Expand all
747 StopSyncScheduler(); 708 StopSyncScheduler();
748 } 709 }
749 710
750 TEST_F(SyncSchedulerTest, ThrottlingExpiresFromConfigure) { 711 TEST_F(SyncSchedulerTest, ThrottlingExpiresFromConfigure) {
751 SyncShareRecords records; 712 SyncShareRecords records;
752 TimeDelta poll(TimeDelta::FromDays(1)); 713 TimeDelta poll(TimeDelta::FromDays(1));
753 TimeDelta throttle1(TimeDelta::FromMilliseconds(150)); 714 TimeDelta throttle1(TimeDelta::FromMilliseconds(150));
754 scheduler()->OnReceivedLongPollIntervalUpdate(poll); 715 scheduler()->OnReceivedLongPollIntervalUpdate(poll);
755 716
756 ::testing::InSequence seq; 717 ::testing::InSequence seq;
757 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_)) 718 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_))
758 .WillOnce(DoAll( 719 .WillOnce(DoAll(
759 WithArg<1>(sessions::test_util::SimulateThrottled(throttle1)), 720 WithArg<2>(sessions::test_util::SimulateThrottled(throttle1)),
760 Return(true))) 721 Return(true)))
761 .RetiresOnSaturation(); 722 .RetiresOnSaturation();
762 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_)) 723 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_))
763 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess), 724 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess),
764 QuitLoopNowAction())); 725 QuitLoopNowAction()));
765 726
766 const ModelTypeSet types(BOOKMARKS); 727 const ModelTypeSet types(BOOKMARKS);
767 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 728 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
768 729
769 CallbackCounter counter; 730 CallbackCounter counter;
770 ConfigurationParams params( 731 ConfigurationParams params(
771 GetUpdatesCallerInfo::RECONFIGURATION, 732 GetUpdatesCallerInfo::RECONFIGURATION,
772 types, 733 types,
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 ::testing::InSequence seq; 790 ::testing::InSequence seq;
830 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) 791 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
831 .WillOnce(DoAll( 792 .WillOnce(DoAll(
832 WithArg<2>( 793 WithArg<2>(
833 sessions::test_util::SimulateTypesThrottled( 794 sessions::test_util::SimulateTypesThrottled(
834 throttled_types, throttle1)), 795 throttled_types, throttle1)),
835 Return(true))) 796 Return(true)))
836 .RetiresOnSaturation(); 797 .RetiresOnSaturation();
837 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) 798 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
838 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), 799 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess),
839 WithArg<2>(RecordSyncShare(&records)))); 800 RecordSyncShare(NORMAL, &records)));
840 801
841 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 802 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
842 scheduler()->ScheduleLocalNudge(zero(), throttled_types, FROM_HERE); 803 scheduler()->ScheduleLocalNudge(zero(), throttled_types, FROM_HERE);
843 PumpLoop(); 804 PumpLoop();
844 EXPECT_EQ(0U, records.snapshots.size()); 805 EXPECT_EQ(0U, records.sources.size());
845 EXPECT_TRUE(GetThrottledTypes().HasAll(throttled_types)); 806 EXPECT_TRUE(GetThrottledTypes().HasAll(throttled_types));
846 807
847 // Ignore invalidations for throttled types. 808 // Ignore invalidations for throttled types.
848 ModelTypeInvalidationMap invalidation_map = 809 ModelTypeInvalidationMap invalidation_map =
849 ModelTypeSetToInvalidationMap(throttled_types, "test"); 810 ModelTypeSetToInvalidationMap(throttled_types, "test");
850 scheduler()->ScheduleInvalidationNudge(zero(), invalidation_map, FROM_HERE); 811 scheduler()->ScheduleInvalidationNudge(zero(), invalidation_map, FROM_HERE);
851 PumpLoop(); 812 PumpLoop();
852 EXPECT_EQ(0U, records.snapshots.size()); 813 EXPECT_EQ(0U, records.sources.size());
853 814
854 // Ignore refresh requests for throttled types. 815 // Ignore refresh requests for throttled types.
855 scheduler()->ScheduleLocalRefreshRequest(zero(), throttled_types, FROM_HERE); 816 scheduler()->ScheduleLocalRefreshRequest(zero(), throttled_types, FROM_HERE);
856 PumpLoop(); 817 PumpLoop();
857 EXPECT_EQ(0U, records.snapshots.size()); 818 EXPECT_EQ(0U, records.sources.size());
858 819
859 // Local nudges for non-throttled types will trigger a sync. 820 // Local nudges for non-throttled types will trigger a sync.
860 scheduler()->ScheduleLocalNudge(zero(), unthrottled_types, FROM_HERE); 821 scheduler()->ScheduleLocalNudge(zero(), unthrottled_types, FROM_HERE);
861 RunLoop(); 822 RunLoop();
862 EXPECT_EQ(1U, records.snapshots.size()); 823 EXPECT_EQ(1U, records.sources.size());
863 824
864 StopSyncScheduler(); 825 StopSyncScheduler();
865 } 826 }
866 827
867 // Test nudges / polls don't run in config mode and config tasks do. 828 // Test nudges / polls don't run in config mode and config tasks do.
868 TEST_F(SyncSchedulerTest, ConfigurationMode) { 829 TEST_F(SyncSchedulerTest, ConfigurationMode) {
869 TimeDelta poll(TimeDelta::FromMilliseconds(15)); 830 TimeDelta poll(TimeDelta::FromMilliseconds(15));
870 SyncShareRecords records; 831 SyncShareRecords records;
871 scheduler()->OnReceivedLongPollIntervalUpdate(poll); 832 scheduler()->OnReceivedLongPollIntervalUpdate(poll);
872 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_)) 833 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_))
873 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess), 834 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess),
874 WithArg<1>(RecordSyncShare(&records)))) 835 RecordSyncShare(CONFIG, &records)))
875 .RetiresOnSaturation(); 836 .RetiresOnSaturation();
876 837
877 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 838 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
878 839
879 const ModelTypeSet nudge_types(AUTOFILL); 840 const ModelTypeSet nudge_types(AUTOFILL);
880 scheduler()->ScheduleLocalNudge(zero(), nudge_types, FROM_HERE); 841 scheduler()->ScheduleLocalNudge(zero(), nudge_types, FROM_HERE);
881 scheduler()->ScheduleLocalNudge(zero(), nudge_types, FROM_HERE); 842 scheduler()->ScheduleLocalNudge(zero(), nudge_types, FROM_HERE);
882 843
883 const ModelTypeSet config_types(BOOKMARKS); 844 const ModelTypeSet config_types(BOOKMARKS);
884 845
885 CallbackCounter counter; 846 CallbackCounter counter;
886 ConfigurationParams params( 847 ConfigurationParams params(
887 GetUpdatesCallerInfo::RECONFIGURATION, 848 GetUpdatesCallerInfo::RECONFIGURATION,
888 config_types, 849 config_types,
889 TypesToRoutingInfo(config_types), 850 TypesToRoutingInfo(config_types),
890 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); 851 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter)));
891 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params)); 852 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params));
892 ASSERT_EQ(1, counter.times_called()); 853 ASSERT_EQ(1, counter.times_called());
893 854
894 ASSERT_EQ(1U, records.snapshots.size()); 855 ASSERT_EQ(1U, records.sources.size());
895 EXPECT_TRUE(ModelTypeSetMatchesInvalidationMap(
896 config_types,
897 records.snapshots[0].source().types));
898 856
899 // Switch to NORMAL_MODE to ensure NUDGES were properly saved and run. 857 // Switch to NORMAL_MODE to ensure NUDGES were properly saved and run.
900 // SyncSchedulerWhiteboxTest also provides coverage for this, but much 858 // SyncSchedulerWhiteboxTest also provides coverage for this, but much
901 // more targeted ('whitebox' style). 859 // more targeted ('whitebox' style).
902 scheduler()->OnReceivedLongPollIntervalUpdate(TimeDelta::FromDays(1)); 860 scheduler()->OnReceivedLongPollIntervalUpdate(TimeDelta::FromDays(1));
903 SyncShareRecords records2; 861 SyncShareRecords records2;
904 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) 862 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
905 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), 863 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess),
906 WithArg<2>(RecordSyncShare(&records2)))); 864 RecordSyncShare(NORMAL, &records2)));
907 865
908 // TODO(tim): Figure out how to remove this dangerous need to reset 866 // TODO(tim): Figure out how to remove this dangerous need to reset
909 // routing info between mode switches. 867 // routing info between mode switches.
910 context()->set_routing_info(routing_info()); 868 context()->set_routing_info(routing_info());
911 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 869 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
912 870
913 ASSERT_EQ(1U, records2.snapshots.size()); 871 ASSERT_EQ(1U, records2.sources.size());
914 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, 872 EXPECT_EQ(NORMAL, records2.sources[0]);
915 records2.snapshots[0].source().updates_source);
916 EXPECT_TRUE(ModelTypeSetMatchesInvalidationMap(
917 nudge_types,
918 records2.snapshots[0].source().types));
919 PumpLoop(); 873 PumpLoop();
920 } 874 }
921 875
922 class BackoffTriggersSyncSchedulerTest : public SyncSchedulerTest { 876 class BackoffTriggersSyncSchedulerTest : public SyncSchedulerTest {
923 virtual void SetUp() { 877 virtual void SetUp() {
924 SyncSchedulerTest::SetUp(); 878 SyncSchedulerTest::SetUp();
925 UseMockDelayProvider(); 879 UseMockDelayProvider();
926 EXPECT_CALL(*delay(), GetDelay(_)) 880 EXPECT_CALL(*delay(), GetDelay(_))
927 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(1))); 881 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(1)));
928 } 882 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
975 Return(true))) 929 Return(true)))
976 .WillRepeatedly(DoAll( 930 .WillRepeatedly(DoAll(
977 Invoke(sessions::test_util::SimulateDownloadUpdatesFailed), 931 Invoke(sessions::test_util::SimulateDownloadUpdatesFailed),
978 QuitLoopNowAction())); 932 QuitLoopNowAction()));
979 EXPECT_TRUE(RunAndGetBackoff()); 933 EXPECT_TRUE(RunAndGetBackoff());
980 } 934 }
981 935
982 // Have the syncer fail to get the encryption key yet succeed in downloading 936 // Have the syncer fail to get the encryption key yet succeed in downloading
983 // updates. Expect this will leave the scheduler in backoff. 937 // updates. Expect this will leave the scheduler in backoff.
984 TEST_F(BackoffTriggersSyncSchedulerTest, FailGetEncryptionKey) { 938 TEST_F(BackoffTriggersSyncSchedulerTest, FailGetEncryptionKey) {
985 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_)) 939 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_))
986 .WillOnce(DoAll( 940 .WillOnce(DoAll(
987 Invoke(sessions::test_util::SimulateGetEncryptionKeyFailed), 941 Invoke(sessions::test_util::SimulateGetEncryptionKeyFailed),
988 Return(true))) 942 Return(true)))
989 .WillRepeatedly(DoAll( 943 .WillRepeatedly(DoAll(
990 Invoke(sessions::test_util::SimulateGetEncryptionKeyFailed), 944 Invoke(sessions::test_util::SimulateGetEncryptionKeyFailed),
991 QuitLoopNowAction())); 945 QuitLoopNowAction()));
992 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 946 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
993 947
994 ModelTypeSet types(BOOKMARKS); 948 ModelTypeSet types(BOOKMARKS);
995 CallbackCounter counter; 949 CallbackCounter counter;
(...skipping 11 matching lines...) Expand all
1007 // Test that no polls or extraneous nudges occur when in backoff. 961 // Test that no polls or extraneous nudges occur when in backoff.
1008 TEST_F(SyncSchedulerTest, BackoffDropsJobs) { 962 TEST_F(SyncSchedulerTest, BackoffDropsJobs) {
1009 SyncShareRecords r; 963 SyncShareRecords r;
1010 TimeDelta poll(TimeDelta::FromMilliseconds(5)); 964 TimeDelta poll(TimeDelta::FromMilliseconds(5));
1011 const ModelTypeSet types(BOOKMARKS); 965 const ModelTypeSet types(BOOKMARKS);
1012 scheduler()->OnReceivedLongPollIntervalUpdate(poll); 966 scheduler()->OnReceivedLongPollIntervalUpdate(poll);
1013 UseMockDelayProvider(); 967 UseMockDelayProvider();
1014 968
1015 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) 969 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
1016 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), 970 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateCommitFailed),
1017 WithArg<2>(RecordSyncShareMultiple(&r, 1U)))); 971 RecordSyncShareMultiple(NORMAL, &r, 1U)));
1018 EXPECT_CALL(*delay(), GetDelay(_)). 972 EXPECT_CALL(*delay(), GetDelay(_)).
1019 WillRepeatedly(Return(TimeDelta::FromDays(1))); 973 WillRepeatedly(Return(TimeDelta::FromDays(1)));
1020 974
1021 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 975 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
1022 976
1023 // This nudge should fail and put us into backoff. Thanks to our mock 977 // This nudge should fail and put us into backoff. Thanks to our mock
1024 // GetDelay() setup above, this will be a long backoff. 978 // GetDelay() setup above, this will be a long backoff.
1025 scheduler()->ScheduleLocalNudge(zero(), types, FROM_HERE); 979 scheduler()->ScheduleLocalNudge(zero(), types, FROM_HERE);
1026 RunLoop(); 980 RunLoop();
1027 981
1028 Mock::VerifyAndClearExpectations(syncer()); 982 Mock::VerifyAndClearExpectations(syncer());
1029 ASSERT_EQ(1U, r.snapshots.size()); 983 ASSERT_EQ(1U, r.sources.size());
1030 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, 984 EXPECT_EQ(NORMAL, r.sources[0]);
1031 r.snapshots[0].source().updates_source);
1032 985
1033 // Wait a while (10x poll interval) so a few poll jobs will be attempted. 986 // Wait a while (10x poll interval) so a few poll jobs will be attempted.
1034 PumpLoopFor(poll * 10); 987 PumpLoopFor(poll * 10);
1035 988
1036 // Try (and fail) to schedule a nudge. 989 // Try (and fail) to schedule a nudge.
1037 scheduler()->ScheduleLocalNudge( 990 scheduler()->ScheduleLocalNudge(
1038 base::TimeDelta::FromMilliseconds(1), 991 base::TimeDelta::FromMilliseconds(1),
1039 types, 992 types,
1040 FROM_HERE); 993 FROM_HERE);
1041 994
1042 Mock::VerifyAndClearExpectations(syncer()); 995 Mock::VerifyAndClearExpectations(syncer());
1043 Mock::VerifyAndClearExpectations(delay()); 996 Mock::VerifyAndClearExpectations(delay());
1044 997
1045 ASSERT_EQ(1U, r.snapshots.size()); 998 ASSERT_EQ(1U, r.sources.size());
1046 999
1047 EXPECT_CALL(*delay(), GetDelay(_)).Times(0); 1000 EXPECT_CALL(*delay(), GetDelay(_)).Times(0);
1048 1001
1049 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 1002 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
1050 1003
1051 CallbackCounter counter; 1004 CallbackCounter counter;
1052 ConfigurationParams params( 1005 ConfigurationParams params(
1053 GetUpdatesCallerInfo::RECONFIGURATION, 1006 GetUpdatesCallerInfo::RECONFIGURATION,
1054 types, 1007 types,
1055 TypesToRoutingInfo(types), 1008 TypesToRoutingInfo(types),
1056 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); 1009 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter)));
1057 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params)); 1010 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params));
1058 ASSERT_EQ(0, counter.times_called()); 1011 ASSERT_EQ(0, counter.times_called());
1059 } 1012 }
1060 1013
1061 // Test that backoff is shaping traffic properly with consecutive errors. 1014 // Test that backoff is shaping traffic properly with consecutive errors.
1062 TEST_F(SyncSchedulerTest, BackoffElevation) { 1015 TEST_F(SyncSchedulerTest, BackoffElevation) {
1063 SyncShareRecords r; 1016 SyncShareRecords r;
1064 UseMockDelayProvider(); 1017 UseMockDelayProvider();
1065 1018
1066 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)).Times(kMinNumSamples) 1019 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)).Times(kMinNumSamples)
1067 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), 1020 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateCommitFailed),
1068 WithArg<2>(RecordSyncShareMultiple(&r, kMinNumSamples)))); 1021 RecordSyncShareMultiple(NORMAL, &r, kMinNumSamples)));
1069 1022
1070 const TimeDelta first = TimeDelta::FromSeconds(kInitialBackoffRetrySeconds); 1023 const TimeDelta first = TimeDelta::FromSeconds(kInitialBackoffRetrySeconds);
1071 const TimeDelta second = TimeDelta::FromMilliseconds(2); 1024 const TimeDelta second = TimeDelta::FromMilliseconds(2);
1072 const TimeDelta third = TimeDelta::FromMilliseconds(3); 1025 const TimeDelta third = TimeDelta::FromMilliseconds(3);
1073 const TimeDelta fourth = TimeDelta::FromMilliseconds(4); 1026 const TimeDelta fourth = TimeDelta::FromMilliseconds(4);
1074 const TimeDelta fifth = TimeDelta::FromMilliseconds(5); 1027 const TimeDelta fifth = TimeDelta::FromMilliseconds(5);
1075 const TimeDelta sixth = TimeDelta::FromDays(1); 1028 const TimeDelta sixth = TimeDelta::FromDays(1);
1076 1029
1077 EXPECT_CALL(*delay(), GetDelay(first)).WillOnce(Return(second)) 1030 EXPECT_CALL(*delay(), GetDelay(first)).WillOnce(Return(second))
1078 .RetiresOnSaturation(); 1031 .RetiresOnSaturation();
1079 EXPECT_CALL(*delay(), GetDelay(second)).WillOnce(Return(third)) 1032 EXPECT_CALL(*delay(), GetDelay(second)).WillOnce(Return(third))
1080 .RetiresOnSaturation(); 1033 .RetiresOnSaturation();
1081 EXPECT_CALL(*delay(), GetDelay(third)).WillOnce(Return(fourth)) 1034 EXPECT_CALL(*delay(), GetDelay(third)).WillOnce(Return(fourth))
1082 .RetiresOnSaturation(); 1035 .RetiresOnSaturation();
1083 EXPECT_CALL(*delay(), GetDelay(fourth)).WillOnce(Return(fifth)) 1036 EXPECT_CALL(*delay(), GetDelay(fourth)).WillOnce(Return(fifth))
1084 .RetiresOnSaturation(); 1037 .RetiresOnSaturation();
1085 EXPECT_CALL(*delay(), GetDelay(fifth)).WillOnce(Return(sixth)); 1038 EXPECT_CALL(*delay(), GetDelay(fifth)).WillOnce(Return(sixth));
1086 1039
1087 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 1040 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
1088 1041
1089 // Run again with a nudge. 1042 // Run again with a nudge.
1090 scheduler()->ScheduleLocalNudge(zero(), ModelTypeSet(BOOKMARKS), FROM_HERE); 1043 scheduler()->ScheduleLocalNudge(zero(), ModelTypeSet(BOOKMARKS), FROM_HERE);
1091 RunLoop(); 1044 RunLoop();
1092 1045
1093 ASSERT_EQ(kMinNumSamples, r.snapshots.size()); 1046 ASSERT_EQ(kMinNumSamples, r.sources.size());
1094 EXPECT_GE(r.times[1] - r.times[0], second); 1047 EXPECT_GE(r.times[1] - r.times[0], second);
1095 EXPECT_GE(r.times[2] - r.times[1], third); 1048 EXPECT_GE(r.times[2] - r.times[1], third);
1096 EXPECT_GE(r.times[3] - r.times[2], fourth); 1049 EXPECT_GE(r.times[3] - r.times[2], fourth);
1097 EXPECT_GE(r.times[4] - r.times[3], fifth); 1050 EXPECT_GE(r.times[4] - r.times[3], fifth);
1098 } 1051 }
1099 1052
1100 // Test that things go back to normal once a retry makes forward progress. 1053 // Test that things go back to normal once a retry makes forward progress.
1101 TEST_F(SyncSchedulerTest, BackoffRelief) { 1054 TEST_F(SyncSchedulerTest, BackoffRelief) {
1102 SyncShareRecords r; 1055 SyncShareRecords r;
1103 const TimeDelta poll(TimeDelta::FromMilliseconds(10)); 1056 const TimeDelta poll(TimeDelta::FromMilliseconds(10));
1104 scheduler()->OnReceivedLongPollIntervalUpdate(poll); 1057 scheduler()->OnReceivedLongPollIntervalUpdate(poll);
1105 UseMockDelayProvider(); 1058 UseMockDelayProvider();
1106 1059
1107 const TimeDelta backoff = TimeDelta::FromMilliseconds(5); 1060 const TimeDelta backoff = TimeDelta::FromMilliseconds(5);
1108 1061
1109 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) 1062 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_))
1110 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), 1063 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed),
1111 WithArg<2>(RecordSyncShareMultiple(&r, kMinNumSamples)))) 1064 RecordSyncShareMultiple(NORMAL, &r, kMinNumSamples)))
1112 .WillRepeatedly(DoAll( 1065 .WillRepeatedly(DoAll(
1113 Invoke(sessions::test_util::SimulateNormalSuccess), 1066 Invoke(sessions::test_util::SimulateNormalSuccess),
1114 WithArg<2>(RecordSyncShareMultiple(&r, kMinNumSamples)))); 1067 RecordSyncShareMultiple(NORMAL, &r, kMinNumSamples)));
1115 EXPECT_CALL(*syncer(), PollSyncShare(_,_)) 1068 EXPECT_CALL(*syncer(), PollSyncShare(_,_))
1116 .WillRepeatedly(DoAll( 1069 .WillRepeatedly(DoAll(
1117 Invoke(sessions::test_util::SimulatePollSuccess), 1070 Invoke(sessions::test_util::SimulatePollSuccess),
1118 WithArg<1>(RecordSyncShareMultiple(&r, kMinNumSamples)))); 1071 RecordSyncShareMultiple(POLL, &r, kMinNumSamples)));
1119 EXPECT_CALL(*delay(), GetDelay(_)).WillOnce(Return(backoff)); 1072 EXPECT_CALL(*delay(), GetDelay(_)).WillOnce(Return(backoff));
1120 1073
1121 // Optimal start for the post-backoff poll party. 1074 // Optimal start for the post-backoff poll party.
1122 TimeTicks optimal_start = TimeTicks::Now(); 1075 TimeTicks optimal_start = TimeTicks::Now();
1123 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 1076 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
1124 1077
1125 // Run again to wait for polling. 1078 // Run again to wait for polling.
1126 scheduler()->ScheduleLocalNudge(zero(), ModelTypeSet(BOOKMARKS), FROM_HERE); 1079 scheduler()->ScheduleLocalNudge(zero(), ModelTypeSet(BOOKMARKS), FROM_HERE);
1127 RunLoop(); 1080 RunLoop();
1128 1081
1129 StopSyncScheduler(); 1082 StopSyncScheduler();
1130 1083
1131 EXPECT_EQ(kMinNumSamples, r.times.size()); 1084 EXPECT_EQ(kMinNumSamples, r.times.size());
1132 1085
1133 // The first nudge ran as soon as possible. It failed. 1086 // The first nudge ran as soon as possible. It failed.
1134 TimeTicks optimal_job_time = optimal_start; 1087 TimeTicks optimal_job_time = optimal_start;
1135 EXPECT_GE(r.times[0], optimal_job_time); 1088 EXPECT_GE(r.times[0], optimal_job_time);
1136 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, 1089 EXPECT_EQ(NORMAL, r.sources[0]);
1137 r.snapshots[0].source().updates_source);
1138 1090
1139 // It was followed by a successful retry nudge shortly afterward. 1091 // It was followed by a successful retry nudge shortly afterward.
1140 optimal_job_time = optimal_job_time + backoff; 1092 optimal_job_time = optimal_job_time + backoff;
1141 EXPECT_GE(r.times[1], optimal_job_time); 1093 EXPECT_GE(r.times[1], optimal_job_time);
1142 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, 1094 EXPECT_EQ(NORMAL, r.sources[1]);
1143 r.snapshots[1].source().updates_source); 1095
1144 // After that, we went back to polling. 1096 // After that, we went back to polling.
1145 for (size_t i = 2; i < r.snapshots.size(); i++) { 1097 for (size_t i = 2; i < r.sources.size(); i++) {
1146 optimal_job_time = optimal_job_time + poll; 1098 optimal_job_time = optimal_job_time + poll;
1147 SCOPED_TRACE(testing::Message() << "SyncShare # (" << i << ")"); 1099 SCOPED_TRACE(testing::Message() << "SyncShare # (" << i << ")");
1148 EXPECT_GE(r.times[i], optimal_job_time); 1100 EXPECT_GE(r.times[i], optimal_job_time);
1149 EXPECT_EQ(GetUpdatesCallerInfo::PERIODIC, 1101 EXPECT_EQ(POLL, r.sources[i]);
1150 r.snapshots[i].source().updates_source);
1151 } 1102 }
1152 } 1103 }
1153 1104
1154 // Test that poll failures are ignored. They should have no effect on 1105 // Test that poll failures are ignored. They should have no effect on
1155 // subsequent poll attempts, nor should they trigger a backoff/retry. 1106 // subsequent poll attempts, nor should they trigger a backoff/retry.
1156 TEST_F(SyncSchedulerTest, TransientPollFailure) { 1107 TEST_F(SyncSchedulerTest, TransientPollFailure) {
1157 SyncShareRecords r; 1108 SyncShareRecords r;
1158 const TimeDelta poll_interval(TimeDelta::FromMilliseconds(1)); 1109 const TimeDelta poll_interval(TimeDelta::FromMilliseconds(1));
1159 scheduler()->OnReceivedLongPollIntervalUpdate(poll_interval); 1110 scheduler()->OnReceivedLongPollIntervalUpdate(poll_interval);
1160 UseMockDelayProvider(); // Will cause test failure if backoff is initiated. 1111 UseMockDelayProvider(); // Will cause test failure if backoff is initiated.
1161 1112
1162 EXPECT_CALL(*syncer(), PollSyncShare(_,_)) 1113 EXPECT_CALL(*syncer(), PollSyncShare(_,_))
1163 .WillOnce(DoAll(Invoke(sessions::test_util::SimulatePollFailed), 1114 .WillOnce(DoAll(Invoke(sessions::test_util::SimulatePollFailed),
1164 WithArg<1>(RecordSyncShare(&r)))) 1115 RecordSyncShare(POLL, &r)))
1165 .WillOnce(DoAll(Invoke(sessions::test_util::SimulatePollSuccess), 1116 .WillOnce(DoAll(Invoke(sessions::test_util::SimulatePollSuccess),
1166 WithArg<1>(RecordSyncShare(&r)))); 1117 RecordSyncShare(POLL, &r)));
1167 1118
1168 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 1119 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
1169 1120
1170 // Run the unsucessful poll. The failed poll should not trigger backoff. 1121 // Run the unsucessful poll. The failed poll should not trigger backoff.
1171 RunLoop(); 1122 RunLoop();
1172 EXPECT_FALSE(scheduler()->IsBackingOff()); 1123 EXPECT_FALSE(scheduler()->IsBackingOff());
1173 1124
1174 // Run the successful poll. 1125 // Run the successful poll.
1175 RunLoop(); 1126 RunLoop();
1176 EXPECT_FALSE(scheduler()->IsBackingOff()); 1127 EXPECT_FALSE(scheduler()->IsBackingOff());
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1254 scheduler()->OnConnectionStatusChange(); 1205 scheduler()->OnConnectionStatusChange();
1255 connection()->SetServerReachable(); 1206 connection()->SetServerReachable();
1256 connection()->UpdateConnectionStatus(); 1207 connection()->UpdateConnectionStatus();
1257 scheduler()->ScheduleLocalNudge(zero(), ModelTypeSet(BOOKMARKS), FROM_HERE); 1208 scheduler()->ScheduleLocalNudge(zero(), ModelTypeSet(BOOKMARKS), FROM_HERE);
1258 base::MessageLoop::current()->RunUntilIdle(); 1209 base::MessageLoop::current()->RunUntilIdle();
1259 } 1210 }
1260 1211
1261 // 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
1262 // extra connection status change notifications. See crbug.com/190085. 1213 // extra connection status change notifications. See crbug.com/190085.
1263 TEST_F(SyncSchedulerTest, DoubleCanaryInConfigure) { 1214 TEST_F(SyncSchedulerTest, DoubleCanaryInConfigure) {
1264 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_)) 1215 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_))
1265 .WillRepeatedly(DoAll( 1216 .WillRepeatedly(DoAll(
1266 Invoke(sessions::test_util::SimulateConfigureConnectionFailure), 1217 Invoke(sessions::test_util::SimulateConfigureConnectionFailure),
1267 Return(true))); 1218 Return(true)));
1268 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 1219 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
1269 connection()->SetServerNotReachable(); 1220 connection()->SetServerNotReachable();
1270 connection()->UpdateConnectionStatus(); 1221 connection()->UpdateConnectionStatus();
1271 1222
1272 ModelTypeSet model_types(BOOKMARKS); 1223 ModelTypeSet model_types(BOOKMARKS);
1273 CallbackCounter counter; 1224 CallbackCounter counter;
1274 ConfigurationParams params( 1225 ConfigurationParams params(
(...skipping 10 matching lines...) Expand all
1285 } 1236 }
1286 1237
1287 TEST_F(SyncSchedulerTest, PollFromCanaryAfterAuthError) { 1238 TEST_F(SyncSchedulerTest, PollFromCanaryAfterAuthError) {
1288 SyncShareRecords records; 1239 SyncShareRecords records;
1289 TimeDelta poll(TimeDelta::FromMilliseconds(15)); 1240 TimeDelta poll(TimeDelta::FromMilliseconds(15));
1290 scheduler()->OnReceivedLongPollIntervalUpdate(poll); 1241 scheduler()->OnReceivedLongPollIntervalUpdate(poll);
1291 1242
1292 ::testing::InSequence seq; 1243 ::testing::InSequence seq;
1293 EXPECT_CALL(*syncer(), PollSyncShare(_,_)) 1244 EXPECT_CALL(*syncer(), PollSyncShare(_,_))
1294 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulatePollSuccess), 1245 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulatePollSuccess),
1295 WithArg<1>(RecordSyncShareMultiple(&records, kMinNumSamples)))); 1246 RecordSyncShareMultiple(POLL, &records, kMinNumSamples)));
1296 1247
1297 connection()->SetServerStatus(HttpResponse::SYNC_AUTH_ERROR); 1248 connection()->SetServerStatus(HttpResponse::SYNC_AUTH_ERROR);
1298 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 1249 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
1299 1250
1300 // Run to wait for polling. 1251 // Run to wait for polling.
1301 RunLoop(); 1252 RunLoop();
1302 1253
1303 // Normally OnCredentialsUpdated calls TryCanaryJob that doesn't run Poll, 1254 // Normally OnCredentialsUpdated calls TryCanaryJob that doesn't run Poll,
1304 // but after poll finished with auth error from poll timer it should retry 1255 // but after poll finished with auth error from poll timer it should retry
1305 // poll once more 1256 // poll once more
1306 EXPECT_CALL(*syncer(), PollSyncShare(_,_)) 1257 EXPECT_CALL(*syncer(), PollSyncShare(_,_))
1307 .WillOnce(DoAll(Invoke(sessions::test_util::SimulatePollSuccess), 1258 .WillOnce(DoAll(Invoke(sessions::test_util::SimulatePollSuccess),
1308 WithArg<1>(RecordSyncShare(&records)))); 1259 RecordSyncShare(POLL, &records)));
1309 scheduler()->OnCredentialsUpdated(); 1260 scheduler()->OnCredentialsUpdated();
1310 connection()->SetServerStatus(HttpResponse::SERVER_CONNECTION_OK); 1261 connection()->SetServerStatus(HttpResponse::SERVER_CONNECTION_OK);
1311 StopSyncScheduler(); 1262 StopSyncScheduler();
1312 } 1263 }
1313 1264
1314 } // namespace syncer 1265 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698