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

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

Issue 10696087: [Sync] Move ModelType and related classes to 'syncer' namespace (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sort headers, update copyrights Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « sync/engine/sync_scheduler.cc ('k') | sync/engine/sync_scheduler_whitebox_unittest.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 16 matching lines...) Expand all
27 using testing::Eq; 27 using testing::Eq;
28 using testing::Invoke; 28 using testing::Invoke;
29 using testing::Mock; 29 using testing::Mock;
30 using testing::Return; 30 using testing::Return;
31 using testing::WithArg; 31 using testing::WithArg;
32 32
33 namespace syncer { 33 namespace syncer {
34 using sessions::SyncSession; 34 using sessions::SyncSession;
35 using sessions::SyncSessionContext; 35 using sessions::SyncSessionContext;
36 using sessions::SyncSessionSnapshot; 36 using sessions::SyncSessionSnapshot;
37 using syncable::ModelTypeSet;
38 using sync_pb::GetUpdatesCallerInfo; 37 using sync_pb::GetUpdatesCallerInfo;
39 38
40 class MockSyncer : public Syncer { 39 class MockSyncer : public Syncer {
41 public: 40 public:
42 MOCK_METHOD3(SyncShare, void(sessions::SyncSession*, SyncerStep, 41 MOCK_METHOD3(SyncShare, void(sessions::SyncSession*, SyncerStep,
43 SyncerStep)); 42 SyncerStep));
44 }; 43 };
45 44
46 // Used when tests want to record syncing activity to examine later. 45 // Used when tests want to record syncing activity to examine later.
47 struct SyncShareRecords { 46 struct SyncShareRecords {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 public: 82 public:
84 MOCK_METHOD1(GetDelay, TimeDelta(const TimeDelta&)); 83 MOCK_METHOD1(GetDelay, TimeDelta(const TimeDelta&));
85 }; 84 };
86 85
87 virtual void SetUp() { 86 virtual void SetUp() {
88 dir_maker_.SetUp(); 87 dir_maker_.SetUp();
89 syncer_ = new MockSyncer(); 88 syncer_ = new MockSyncer();
90 delay_ = NULL; 89 delay_ = NULL;
91 90
92 ModelSafeRoutingInfo routing_info; 91 ModelSafeRoutingInfo routing_info;
93 routing_info[syncable::BOOKMARKS] = GROUP_UI; 92 routing_info[syncer::BOOKMARKS] = GROUP_UI;
94 routing_info[syncable::AUTOFILL] = GROUP_DB; 93 routing_info[syncer::AUTOFILL] = GROUP_DB;
95 routing_info[syncable::THEMES] = GROUP_UI; 94 routing_info[syncer::THEMES] = GROUP_UI;
96 routing_info[syncable::NIGORI] = GROUP_PASSIVE; 95 routing_info[syncer::NIGORI] = GROUP_PASSIVE;
97 96
98 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_UI))); 97 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_UI)));
99 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_DB))); 98 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_DB)));
100 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_PASSIVE))); 99 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_PASSIVE)));
101 100
102 std::vector<ModelSafeWorker*> workers; 101 std::vector<ModelSafeWorker*> workers;
103 for (std::vector<scoped_refptr<FakeModelWorker> >::iterator it = 102 for (std::vector<scoped_refptr<FakeModelWorker> >::iterator it =
104 workers_.begin(); it != workers_.end(); ++it) { 103 workers_.begin(); it != workers_.end(); ++it) {
105 workers.push_back(it->get()); 104 workers.push_back(it->get());
106 } 105 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 174
176 void UseMockDelayProvider() { 175 void UseMockDelayProvider() {
177 delay_ = new MockDelayProvider(); 176 delay_ = new MockDelayProvider();
178 scheduler_->delay_provider_.reset(delay_); 177 scheduler_->delay_provider_.reset(delay_);
179 } 178 }
180 179
181 // Compare a ModelTypeSet to a ModelTypePayloadMap, ignoring 180 // Compare a ModelTypeSet to a ModelTypePayloadMap, ignoring
182 // payload values. 181 // payload values.
183 bool CompareModelTypeSetToModelTypePayloadMap( 182 bool CompareModelTypeSetToModelTypePayloadMap(
184 ModelTypeSet lhs, 183 ModelTypeSet lhs,
185 const syncable::ModelTypePayloadMap& rhs) { 184 const syncer::ModelTypePayloadMap& rhs) {
186 size_t count = 0; 185 size_t count = 0;
187 for (syncable::ModelTypePayloadMap::const_iterator i = rhs.begin(); 186 for (syncer::ModelTypePayloadMap::const_iterator i = rhs.begin();
188 i != rhs.end(); ++i, ++count) { 187 i != rhs.end(); ++i, ++count) {
189 if (!lhs.Has(i->first)) 188 if (!lhs.Has(i->first))
190 return false; 189 return false;
191 } 190 }
192 if (lhs.Size() != count) 191 if (lhs.Size() != count)
193 return false; 192 return false;
194 return true; 193 return true;
195 } 194 }
196 195
197 SyncSessionContext* context() { return context_.get(); } 196 SyncSessionContext* context() { return context_.get(); }
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 QuitLoopNow(); 238 QuitLoopNow();
240 } 239 }
241 240
242 ACTION(QuitLoopNowAction) { 241 ACTION(QuitLoopNowAction) {
243 QuitLoopNow(); 242 QuitLoopNow();
244 } 243 }
245 244
246 // Test nudge scheduling. 245 // Test nudge scheduling.
247 TEST_F(SyncSchedulerTest, Nudge) { 246 TEST_F(SyncSchedulerTest, Nudge) {
248 SyncShareRecords records; 247 SyncShareRecords records;
249 ModelTypeSet model_types(syncable::BOOKMARKS); 248 ModelTypeSet model_types(syncer::BOOKMARKS);
250 249
251 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 250 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
252 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 251 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
253 WithArg<0>(RecordSyncShare(&records)))) 252 WithArg<0>(RecordSyncShare(&records))))
254 .RetiresOnSaturation(); 253 .RetiresOnSaturation();
255 254
256 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 255 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
257 256
258 scheduler()->ScheduleNudgeAsync( 257 scheduler()->ScheduleNudgeAsync(
259 zero(), NUDGE_SOURCE_LOCAL, model_types, FROM_HERE); 258 zero(), NUDGE_SOURCE_LOCAL, model_types, FROM_HERE);
260 RunLoop(); 259 RunLoop();
261 260
262 ASSERT_EQ(1U, records.snapshots.size()); 261 ASSERT_EQ(1U, records.snapshots.size());
263 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types, 262 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types,
264 records.snapshots[0].source().types)); 263 records.snapshots[0].source().types));
265 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, 264 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL,
266 records.snapshots[0].source().updates_source); 265 records.snapshots[0].source().updates_source);
267 266
268 Mock::VerifyAndClearExpectations(syncer()); 267 Mock::VerifyAndClearExpectations(syncer());
269 268
270 // Make sure a second, later, nudge is unaffected by first (no coalescing). 269 // Make sure a second, later, nudge is unaffected by first (no coalescing).
271 SyncShareRecords records2; 270 SyncShareRecords records2;
272 model_types.Remove(syncable::BOOKMARKS); 271 model_types.Remove(syncer::BOOKMARKS);
273 model_types.Put(syncable::AUTOFILL); 272 model_types.Put(syncer::AUTOFILL);
274 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 273 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
275 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 274 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
276 WithArg<0>(RecordSyncShare(&records2)))); 275 WithArg<0>(RecordSyncShare(&records2))));
277 scheduler()->ScheduleNudgeAsync( 276 scheduler()->ScheduleNudgeAsync(
278 zero(), NUDGE_SOURCE_LOCAL, model_types, FROM_HERE); 277 zero(), NUDGE_SOURCE_LOCAL, model_types, FROM_HERE);
279 RunLoop(); 278 RunLoop();
280 279
281 ASSERT_EQ(1U, records2.snapshots.size()); 280 ASSERT_EQ(1U, records2.snapshots.size());
282 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types, 281 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types,
283 records2.snapshots[0].source().types)); 282 records2.snapshots[0].source().types));
284 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, 283 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL,
285 records2.snapshots[0].source().updates_source); 284 records2.snapshots[0].source().updates_source);
286 } 285 }
287 286
288 // Make sure a regular config command is scheduled fine in the absence of any 287 // Make sure a regular config command is scheduled fine in the absence of any
289 // errors. 288 // errors.
290 TEST_F(SyncSchedulerTest, Config) { 289 TEST_F(SyncSchedulerTest, Config) {
291 SyncShareRecords records; 290 SyncShareRecords records;
292 const ModelTypeSet model_types(syncable::BOOKMARKS); 291 const ModelTypeSet model_types(syncer::BOOKMARKS);
293 292
294 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 293 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
295 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 294 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
296 WithArg<0>(RecordSyncShare(&records)))); 295 WithArg<0>(RecordSyncShare(&records))));
297 296
298 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 297 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
299 298
300 scheduler()->ScheduleConfiguration( 299 scheduler()->ScheduleConfiguration(
301 model_types, GetUpdatesCallerInfo::RECONFIGURATION); 300 model_types, GetUpdatesCallerInfo::RECONFIGURATION);
302 301
303 ASSERT_EQ(1U, records.snapshots.size()); 302 ASSERT_EQ(1U, records.snapshots.size());
304 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types, 303 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types,
305 records.snapshots[0].source().types)); 304 records.snapshots[0].source().types));
306 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, 305 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION,
307 records.snapshots[0].source().updates_source); 306 records.snapshots[0].source().updates_source);
308 } 307 }
309 308
310 // Simulate a failure and make sure the config request is retried. 309 // Simulate a failure and make sure the config request is retried.
311 TEST_F(SyncSchedulerTest, ConfigWithBackingOff) { 310 TEST_F(SyncSchedulerTest, ConfigWithBackingOff) {
312 UseMockDelayProvider(); 311 UseMockDelayProvider();
313 EXPECT_CALL(*delay(), GetDelay(_)) 312 EXPECT_CALL(*delay(), GetDelay(_))
314 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(1))); 313 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(1)));
315 SyncShareRecords records; 314 SyncShareRecords records;
316 const ModelTypeSet model_types(syncable::BOOKMARKS); 315 const ModelTypeSet model_types(syncer::BOOKMARKS);
317 316
318 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 317 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
319 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), 318 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed),
320 WithArg<0>(RecordSyncShare(&records)))) 319 WithArg<0>(RecordSyncShare(&records))))
321 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 320 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
322 WithArg<0>(RecordSyncShare(&records)))); 321 WithArg<0>(RecordSyncShare(&records))));
323 322
324 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 323 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
325 324
326 ASSERT_EQ(0U, records.snapshots.size()); 325 ASSERT_EQ(0U, records.snapshots.size());
327 scheduler()->ScheduleConfiguration( 326 scheduler()->ScheduleConfiguration(
328 model_types, GetUpdatesCallerInfo::RECONFIGURATION); 327 model_types, GetUpdatesCallerInfo::RECONFIGURATION);
329 328
330 ASSERT_EQ(1U, records.snapshots.size()); 329 ASSERT_EQ(1U, records.snapshots.size());
331 RunLoop(); 330 RunLoop();
332 331
333 ASSERT_EQ(2U, records.snapshots.size()); 332 ASSERT_EQ(2U, records.snapshots.size());
334 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types, 333 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types,
335 records.snapshots[1].source().types)); 334 records.snapshots[1].source().types));
336 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, 335 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION,
337 records.snapshots[1].source().updates_source); 336 records.snapshots[1].source().updates_source);
338 } 337 }
339 338
340 // Issue 2 config commands. Second one right after the first has failed 339 // Issue 2 config commands. Second one right after the first has failed
341 // and make sure LATEST is executed. 340 // and make sure LATEST is executed.
342 TEST_F(SyncSchedulerTest, MultipleConfigWithBackingOff) { 341 TEST_F(SyncSchedulerTest, MultipleConfigWithBackingOff) {
343 const ModelTypeSet 342 const ModelTypeSet
344 model_types1(syncable::BOOKMARKS), 343 model_types1(syncer::BOOKMARKS),
345 model_types2(syncable::AUTOFILL); 344 model_types2(syncer::AUTOFILL);
346 UseMockDelayProvider(); 345 UseMockDelayProvider();
347 EXPECT_CALL(*delay(), GetDelay(_)) 346 EXPECT_CALL(*delay(), GetDelay(_))
348 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(30))); 347 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(30)));
349 SyncShareRecords records; 348 SyncShareRecords records;
350 349
351 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 350 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
352 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), 351 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed),
353 WithArg<0>(RecordSyncShare(&records)))) 352 WithArg<0>(RecordSyncShare(&records))))
354 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), 353 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed),
355 WithArg<0>(RecordSyncShare(&records)))) 354 WithArg<0>(RecordSyncShare(&records))))
(...skipping 19 matching lines...) Expand all
375 ASSERT_EQ(3U, records.snapshots.size()); 374 ASSERT_EQ(3U, records.snapshots.size());
376 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types2, 375 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types2,
377 records.snapshots[2].source().types)); 376 records.snapshots[2].source().types));
378 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, 377 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION,
379 records.snapshots[2].source().updates_source); 378 records.snapshots[2].source().updates_source);
380 } 379 }
381 380
382 // Issue a nudge when the config has failed. Make sure both the config and 381 // Issue a nudge when the config has failed. Make sure both the config and
383 // nudge are executed. 382 // nudge are executed.
384 TEST_F(SyncSchedulerTest, NudgeWithConfigWithBackingOff) { 383 TEST_F(SyncSchedulerTest, NudgeWithConfigWithBackingOff) {
385 const ModelTypeSet model_types(syncable::BOOKMARKS); 384 const ModelTypeSet model_types(syncer::BOOKMARKS);
386 UseMockDelayProvider(); 385 UseMockDelayProvider();
387 EXPECT_CALL(*delay(), GetDelay(_)) 386 EXPECT_CALL(*delay(), GetDelay(_))
388 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(50))); 387 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(50)));
389 SyncShareRecords records; 388 SyncShareRecords records;
390 389
391 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 390 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
392 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), 391 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed),
393 WithArg<0>(RecordSyncShare(&records)))) 392 WithArg<0>(RecordSyncShare(&records))))
394 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), 393 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed),
395 WithArg<0>(RecordSyncShare(&records)))) 394 WithArg<0>(RecordSyncShare(&records))))
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 431
433 // Test that nudges are coalesced. 432 // Test that nudges are coalesced.
434 TEST_F(SyncSchedulerTest, NudgeCoalescing) { 433 TEST_F(SyncSchedulerTest, NudgeCoalescing) {
435 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 434 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
436 435
437 SyncShareRecords r; 436 SyncShareRecords r;
438 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 437 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
439 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 438 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
440 WithArg<0>(RecordSyncShare(&r)))); 439 WithArg<0>(RecordSyncShare(&r))));
441 const ModelTypeSet 440 const ModelTypeSet
442 types1(syncable::BOOKMARKS), 441 types1(syncer::BOOKMARKS),
443 types2(syncable::AUTOFILL), 442 types2(syncer::AUTOFILL),
444 types3(syncable::THEMES); 443 types3(syncer::THEMES);
445 TimeDelta delay = zero(); 444 TimeDelta delay = zero();
446 TimeTicks optimal_time = TimeTicks::Now() + delay; 445 TimeTicks optimal_time = TimeTicks::Now() + delay;
447 scheduler()->ScheduleNudgeAsync( 446 scheduler()->ScheduleNudgeAsync(
448 delay, NUDGE_SOURCE_UNKNOWN, types1, FROM_HERE); 447 delay, NUDGE_SOURCE_UNKNOWN, types1, FROM_HERE);
449 scheduler()->ScheduleNudgeAsync( 448 scheduler()->ScheduleNudgeAsync(
450 zero(), NUDGE_SOURCE_LOCAL, types2, FROM_HERE); 449 zero(), NUDGE_SOURCE_LOCAL, types2, FROM_HERE);
451 RunLoop(); 450 RunLoop();
452 451
453 ASSERT_EQ(1U, r.snapshots.size()); 452 ASSERT_EQ(1U, r.snapshots.size());
454 EXPECT_GE(r.times[0], optimal_time); 453 EXPECT_GE(r.times[0], optimal_time);
(...skipping 20 matching lines...) Expand all
475 } 474 }
476 475
477 // Test that nudges are coalesced. 476 // Test that nudges are coalesced.
478 TEST_F(SyncSchedulerTest, NudgeCoalescingWithDifferentTimings) { 477 TEST_F(SyncSchedulerTest, NudgeCoalescingWithDifferentTimings) {
479 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 478 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
480 479
481 SyncShareRecords r; 480 SyncShareRecords r;
482 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 481 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
483 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 482 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
484 WithArg<0>(RecordSyncShare(&r)))); 483 WithArg<0>(RecordSyncShare(&r))));
485 syncable::ModelTypeSet types1(syncable::BOOKMARKS), 484 syncer::ModelTypeSet types1(syncer::BOOKMARKS),
486 types2(syncable::AUTOFILL), types3; 485 types2(syncer::AUTOFILL), types3;
487 486
488 // Create a huge time delay. 487 // Create a huge time delay.
489 TimeDelta delay = TimeDelta::FromDays(1); 488 TimeDelta delay = TimeDelta::FromDays(1);
490 489
491 scheduler()->ScheduleNudgeAsync( 490 scheduler()->ScheduleNudgeAsync(
492 delay, NUDGE_SOURCE_UNKNOWN, types1, FROM_HERE); 491 delay, NUDGE_SOURCE_UNKNOWN, types1, FROM_HERE);
493 492
494 scheduler()->ScheduleNudgeAsync( 493 scheduler()->ScheduleNudgeAsync(
495 zero(), NUDGE_SOURCE_UNKNOWN, types2, FROM_HERE); 494 zero(), NUDGE_SOURCE_UNKNOWN, types2, FROM_HERE);
496 495
(...skipping 10 matching lines...) Expand all
507 // Make sure the sync happened at the right time. 506 // Make sure the sync happened at the right time.
508 EXPECT_GE(r.times[0], min_time); 507 EXPECT_GE(r.times[0], min_time);
509 EXPECT_LE(r.times[0], max_time); 508 EXPECT_LE(r.times[0], max_time);
510 } 509 }
511 510
512 // Test nudge scheduling. 511 // Test nudge scheduling.
513 TEST_F(SyncSchedulerTest, NudgeWithPayloads) { 512 TEST_F(SyncSchedulerTest, NudgeWithPayloads) {
514 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 513 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
515 514
516 SyncShareRecords records; 515 SyncShareRecords records;
517 syncable::ModelTypePayloadMap model_types_with_payloads; 516 syncer::ModelTypePayloadMap model_types_with_payloads;
518 model_types_with_payloads[syncable::BOOKMARKS] = "test"; 517 model_types_with_payloads[syncer::BOOKMARKS] = "test";
519 518
520 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 519 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
521 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 520 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
522 WithArg<0>(RecordSyncShare(&records)))) 521 WithArg<0>(RecordSyncShare(&records))))
523 .RetiresOnSaturation(); 522 .RetiresOnSaturation();
524 scheduler()->ScheduleNudgeWithPayloadsAsync( 523 scheduler()->ScheduleNudgeWithPayloadsAsync(
525 zero(), NUDGE_SOURCE_LOCAL, model_types_with_payloads, FROM_HERE); 524 zero(), NUDGE_SOURCE_LOCAL, model_types_with_payloads, FROM_HERE);
526 RunLoop(); 525 RunLoop();
527 526
528 ASSERT_EQ(1U, records.snapshots.size()); 527 ASSERT_EQ(1U, records.snapshots.size());
529 EXPECT_EQ(model_types_with_payloads, records.snapshots[0].source().types); 528 EXPECT_EQ(model_types_with_payloads, records.snapshots[0].source().types);
530 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, 529 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL,
531 records.snapshots[0].source().updates_source); 530 records.snapshots[0].source().updates_source);
532 531
533 Mock::VerifyAndClearExpectations(syncer()); 532 Mock::VerifyAndClearExpectations(syncer());
534 533
535 // Make sure a second, later, nudge is unaffected by first (no coalescing). 534 // Make sure a second, later, nudge is unaffected by first (no coalescing).
536 SyncShareRecords records2; 535 SyncShareRecords records2;
537 model_types_with_payloads.erase(syncable::BOOKMARKS); 536 model_types_with_payloads.erase(syncer::BOOKMARKS);
538 model_types_with_payloads[syncable::AUTOFILL] = "test2"; 537 model_types_with_payloads[syncer::AUTOFILL] = "test2";
539 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 538 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
540 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 539 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
541 WithArg<0>(RecordSyncShare(&records2)))); 540 WithArg<0>(RecordSyncShare(&records2))));
542 scheduler()->ScheduleNudgeWithPayloadsAsync( 541 scheduler()->ScheduleNudgeWithPayloadsAsync(
543 zero(), NUDGE_SOURCE_LOCAL, model_types_with_payloads, FROM_HERE); 542 zero(), NUDGE_SOURCE_LOCAL, model_types_with_payloads, FROM_HERE);
544 RunLoop(); 543 RunLoop();
545 544
546 ASSERT_EQ(1U, records2.snapshots.size()); 545 ASSERT_EQ(1U, records2.snapshots.size());
547 EXPECT_EQ(model_types_with_payloads, records2.snapshots[0].source().types); 546 EXPECT_EQ(model_types_with_payloads, records2.snapshots[0].source().types);
548 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, 547 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL,
549 records2.snapshots[0].source().updates_source); 548 records2.snapshots[0].source().updates_source);
550 } 549 }
551 550
552 // Test that nudges are coalesced. 551 // Test that nudges are coalesced.
553 TEST_F(SyncSchedulerTest, NudgeWithPayloadsCoalescing) { 552 TEST_F(SyncSchedulerTest, NudgeWithPayloadsCoalescing) {
554 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 553 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
555 554
556 SyncShareRecords r; 555 SyncShareRecords r;
557 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 556 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
558 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 557 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
559 WithArg<0>(RecordSyncShare(&r)))); 558 WithArg<0>(RecordSyncShare(&r))));
560 syncable::ModelTypePayloadMap types1, types2, types3; 559 syncer::ModelTypePayloadMap types1, types2, types3;
561 types1[syncable::BOOKMARKS] = "test1"; 560 types1[syncer::BOOKMARKS] = "test1";
562 types2[syncable::AUTOFILL] = "test2"; 561 types2[syncer::AUTOFILL] = "test2";
563 types3[syncable::THEMES] = "test3"; 562 types3[syncer::THEMES] = "test3";
564 TimeDelta delay = zero(); 563 TimeDelta delay = zero();
565 TimeTicks optimal_time = TimeTicks::Now() + delay; 564 TimeTicks optimal_time = TimeTicks::Now() + delay;
566 scheduler()->ScheduleNudgeWithPayloadsAsync( 565 scheduler()->ScheduleNudgeWithPayloadsAsync(
567 delay, NUDGE_SOURCE_UNKNOWN, types1, FROM_HERE); 566 delay, NUDGE_SOURCE_UNKNOWN, types1, FROM_HERE);
568 scheduler()->ScheduleNudgeWithPayloadsAsync( 567 scheduler()->ScheduleNudgeWithPayloadsAsync(
569 zero(), NUDGE_SOURCE_LOCAL, types2, FROM_HERE); 568 zero(), NUDGE_SOURCE_LOCAL, types2, FROM_HERE);
570 RunLoop(); 569 RunLoop();
571 570
572 ASSERT_EQ(1U, r.snapshots.size()); 571 ASSERT_EQ(1U, r.snapshots.size());
573 EXPECT_GE(r.times[0], optimal_time); 572 EXPECT_GE(r.times[0], optimal_time);
574 syncable::ModelTypePayloadMap coalesced_types; 573 syncer::ModelTypePayloadMap coalesced_types;
575 syncable::CoalescePayloads(&coalesced_types, types1); 574 syncer::CoalescePayloads(&coalesced_types, types1);
576 syncable::CoalescePayloads(&coalesced_types, types2); 575 syncer::CoalescePayloads(&coalesced_types, types2);
577 EXPECT_EQ(coalesced_types, r.snapshots[0].source().types); 576 EXPECT_EQ(coalesced_types, r.snapshots[0].source().types);
578 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, 577 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL,
579 r.snapshots[0].source().updates_source); 578 r.snapshots[0].source().updates_source);
580 579
581 Mock::VerifyAndClearExpectations(syncer()); 580 Mock::VerifyAndClearExpectations(syncer());
582 581
583 SyncShareRecords r2; 582 SyncShareRecords r2;
584 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 583 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
585 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 584 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
586 WithArg<0>(RecordSyncShare(&r2)))); 585 WithArg<0>(RecordSyncShare(&r2))));
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 WithArg<0>( 671 WithArg<0>(
673 sessions::test_util::SimulateSessionsCommitDelayUpdate( 672 sessions::test_util::SimulateSessionsCommitDelayUpdate(
674 delay2)), 673 delay2)),
675 Invoke(sessions::test_util::SimulateSuccess), 674 Invoke(sessions::test_util::SimulateSuccess),
676 QuitLoopNowAction())); 675 QuitLoopNowAction()));
677 676
678 EXPECT_EQ(delay1, scheduler()->sessions_commit_delay()); 677 EXPECT_EQ(delay1, scheduler()->sessions_commit_delay());
679 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 678 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
680 679
681 EXPECT_EQ(delay1, scheduler()->sessions_commit_delay()); 680 EXPECT_EQ(delay1, scheduler()->sessions_commit_delay());
682 const ModelTypeSet model_types(syncable::BOOKMARKS); 681 const ModelTypeSet model_types(syncer::BOOKMARKS);
683 scheduler()->ScheduleNudgeAsync( 682 scheduler()->ScheduleNudgeAsync(
684 zero(), NUDGE_SOURCE_LOCAL, model_types, FROM_HERE); 683 zero(), NUDGE_SOURCE_LOCAL, model_types, FROM_HERE);
685 RunLoop(); 684 RunLoop();
686 685
687 EXPECT_EQ(delay2, scheduler()->sessions_commit_delay()); 686 EXPECT_EQ(delay2, scheduler()->sessions_commit_delay());
688 StopSyncScheduler(); 687 StopSyncScheduler();
689 } 688 }
690 689
691 // Test that a sync session is run through to completion. 690 // Test that a sync session is run through to completion.
692 TEST_F(SyncSchedulerTest, HasMoreToSync) { 691 TEST_F(SyncSchedulerTest, HasMoreToSync) {
(...skipping 20 matching lines...) Expand all
713 712
714 scheduler()->ScheduleNudgeAsync( 713 scheduler()->ScheduleNudgeAsync(
715 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(), FROM_HERE); 714 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(), FROM_HERE);
716 715
717 // We should detect the failure on the second sync share, and go into backoff. 716 // We should detect the failure on the second sync share, and go into backoff.
718 EXPECT_TRUE(RunAndGetBackoff()); 717 EXPECT_TRUE(RunAndGetBackoff());
719 } 718 }
720 719
721 // Test that no syncing occurs when throttled. 720 // Test that no syncing occurs when throttled.
722 TEST_F(SyncSchedulerTest, ThrottlingDoesThrottle) { 721 TEST_F(SyncSchedulerTest, ThrottlingDoesThrottle) {
723 const ModelTypeSet types(syncable::BOOKMARKS); 722 const ModelTypeSet types(syncer::BOOKMARKS);
724 TimeDelta poll(TimeDelta::FromMilliseconds(5)); 723 TimeDelta poll(TimeDelta::FromMilliseconds(5));
725 TimeDelta throttle(TimeDelta::FromMinutes(10)); 724 TimeDelta throttle(TimeDelta::FromMinutes(10));
726 scheduler()->OnReceivedLongPollIntervalUpdate(poll); 725 scheduler()->OnReceivedLongPollIntervalUpdate(poll);
727 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 726 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
728 .WillOnce(WithArg<0>(sessions::test_util::SimulateThrottled(throttle))) 727 .WillOnce(WithArg<0>(sessions::test_util::SimulateThrottled(throttle)))
729 .WillRepeatedly(AddFailureAndQuitLoopNow()); 728 .WillRepeatedly(AddFailureAndQuitLoopNow());
730 729
731 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 730 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
732 731
733 scheduler()->ScheduleNudgeAsync( 732 scheduler()->ScheduleNudgeAsync(
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
768 TEST_F(SyncSchedulerTest, ConfigurationMode) { 767 TEST_F(SyncSchedulerTest, ConfigurationMode) {
769 TimeDelta poll(TimeDelta::FromMilliseconds(15)); 768 TimeDelta poll(TimeDelta::FromMilliseconds(15));
770 SyncShareRecords records; 769 SyncShareRecords records;
771 scheduler()->OnReceivedLongPollIntervalUpdate(poll); 770 scheduler()->OnReceivedLongPollIntervalUpdate(poll);
772 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 771 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
773 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), 772 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
774 WithArg<0>(RecordSyncShare(&records)))); 773 WithArg<0>(RecordSyncShare(&records))));
775 774
776 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 775 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
777 776
778 const ModelTypeSet nudge_types(syncable::AUTOFILL); 777 const ModelTypeSet nudge_types(syncer::AUTOFILL);
779 scheduler()->ScheduleNudgeAsync( 778 scheduler()->ScheduleNudgeAsync(
780 zero(), NUDGE_SOURCE_LOCAL, nudge_types, FROM_HERE); 779 zero(), NUDGE_SOURCE_LOCAL, nudge_types, FROM_HERE);
781 scheduler()->ScheduleNudgeAsync( 780 scheduler()->ScheduleNudgeAsync(
782 zero(), NUDGE_SOURCE_LOCAL, nudge_types, FROM_HERE); 781 zero(), NUDGE_SOURCE_LOCAL, nudge_types, FROM_HERE);
783 782
784 const ModelTypeSet config_types(syncable::BOOKMARKS); 783 const ModelTypeSet config_types(syncer::BOOKMARKS);
785 784
786 scheduler()->ScheduleConfiguration( 785 scheduler()->ScheduleConfiguration(
787 config_types, GetUpdatesCallerInfo::RECONFIGURATION); 786 config_types, GetUpdatesCallerInfo::RECONFIGURATION);
788 787
789 ASSERT_EQ(1U, records.snapshots.size()); 788 ASSERT_EQ(1U, records.snapshots.size());
790 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(config_types, 789 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(config_types,
791 records.snapshots[0].source().types)); 790 records.snapshots[0].source().types));
792 } 791 }
793 792
794 class BackoffTriggersSyncSchedulerTest : public SyncSchedulerTest { 793 class BackoffTriggersSyncSchedulerTest : public SyncSchedulerTest {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 .WillRepeatedly(DoAll( 841 .WillRepeatedly(DoAll(
843 Invoke(sessions::test_util::SimulateDownloadUpdatesFailed), 842 Invoke(sessions::test_util::SimulateDownloadUpdatesFailed),
844 QuitLoopNowAction())); 843 QuitLoopNowAction()));
845 EXPECT_TRUE(RunAndGetBackoff()); 844 EXPECT_TRUE(RunAndGetBackoff());
846 } 845 }
847 846
848 // Test that no polls or extraneous nudges occur when in backoff. 847 // Test that no polls or extraneous nudges occur when in backoff.
849 TEST_F(SyncSchedulerTest, BackoffDropsJobs) { 848 TEST_F(SyncSchedulerTest, BackoffDropsJobs) {
850 SyncShareRecords r; 849 SyncShareRecords r;
851 TimeDelta poll(TimeDelta::FromMilliseconds(5)); 850 TimeDelta poll(TimeDelta::FromMilliseconds(5));
852 const ModelTypeSet types(syncable::BOOKMARKS); 851 const ModelTypeSet types(syncer::BOOKMARKS);
853 scheduler()->OnReceivedLongPollIntervalUpdate(poll); 852 scheduler()->OnReceivedLongPollIntervalUpdate(poll);
854 UseMockDelayProvider(); 853 UseMockDelayProvider();
855 854
856 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(1) 855 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(1)
857 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), 856 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateCommitFailed),
858 RecordSyncShareMultiple(&r, 1U))); 857 RecordSyncShareMultiple(&r, 1U)));
859 EXPECT_CALL(*delay(), GetDelay(_)). 858 EXPECT_CALL(*delay(), GetDelay(_)).
860 WillRepeatedly(Return(TimeDelta::FromDays(1))); 859 WillRepeatedly(Return(TimeDelta::FromDays(1)));
861 860
862 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 861 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
1134 PumpLoop(); 1133 PumpLoop();
1135 // Pump again to run job. 1134 // Pump again to run job.
1136 PumpLoop(); 1135 PumpLoop();
1137 1136
1138 StopSyncScheduler(); 1137 StopSyncScheduler();
1139 1138
1140 EXPECT_TRUE(expected == context()->previous_session_routing_info()); 1139 EXPECT_TRUE(expected == context()->previous_session_routing_info());
1141 } 1140 }
1142 1141
1143 } // namespace syncer 1142 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/engine/sync_scheduler.cc ('k') | sync/engine/sync_scheduler_whitebox_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698