OLD | NEW |
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" |
11 #include "sync/engine/sync_scheduler.h" | 11 #include "sync/engine/sync_scheduler.h" |
12 #include "sync/engine/syncer.h" | 12 #include "sync/engine/syncer.h" |
13 #include "sync/engine/throttled_data_type_tracker.h" | 13 #include "sync/engine/throttled_data_type_tracker.h" |
14 #include "sync/sessions/test_util.h" | 14 #include "sync/sessions/test_util.h" |
| 15 #include "sync/test/callback_counter.h" |
15 #include "sync/test/engine/fake_model_worker.h" | 16 #include "sync/test/engine/fake_model_worker.h" |
16 #include "sync/test/engine/mock_connection_manager.h" | 17 #include "sync/test/engine/mock_connection_manager.h" |
17 #include "sync/test/engine/test_directory_setter_upper.h" | 18 #include "sync/test/engine/test_directory_setter_upper.h" |
18 #include "sync/test/fake_extensions_activity_monitor.h" | 19 #include "sync/test/fake_extensions_activity_monitor.h" |
19 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
21 | 22 |
22 using base::TimeDelta; | 23 using base::TimeDelta; |
23 using base::TimeTicks; | 24 using base::TimeTicks; |
24 using testing::_; | 25 using testing::_; |
25 using testing::AtLeast; | 26 using testing::AtLeast; |
26 using testing::DoAll; | 27 using testing::DoAll; |
27 using testing::Eq; | 28 using testing::Eq; |
28 using testing::Invoke; | 29 using testing::Invoke; |
29 using testing::Mock; | 30 using testing::Mock; |
| 31 using testing::Not; |
30 using testing::Return; | 32 using testing::Return; |
31 using testing::WithArg; | 33 using testing::WithArg; |
32 | 34 |
33 namespace browser_sync { | 35 namespace browser_sync { |
34 using sessions::SyncSession; | 36 using sessions::SyncSession; |
35 using sessions::SyncSessionContext; | 37 using sessions::SyncSessionContext; |
36 using sessions::SyncSessionSnapshot; | 38 using sessions::SyncSessionSnapshot; |
37 using syncable::ModelTypeSet; | 39 using syncable::ModelTypeSet; |
38 using sync_pb::GetUpdatesCallerInfo; | 40 using sync_pb::GetUpdatesCallerInfo; |
39 | 41 |
(...skipping 22 matching lines...) Expand all Loading... |
62 } | 64 } |
63 | 65 |
64 void PumpLoop() { | 66 void PumpLoop() { |
65 // Do it this way instead of RunAllPending to pump loop exactly once | 67 // Do it this way instead of RunAllPending to pump loop exactly once |
66 // (necessary in the presence of timers; see comment in | 68 // (necessary in the presence of timers; see comment in |
67 // QuitLoopNow). | 69 // QuitLoopNow). |
68 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(&QuitLoopNow)); | 70 MessageLoop::current()->PostTask(FROM_HERE, base::Bind(&QuitLoopNow)); |
69 RunLoop(); | 71 RunLoop(); |
70 } | 72 } |
71 | 73 |
| 74 ModelSafeRoutingInfo TypesToRoutingInfo(const ModelTypeSet& types) { |
| 75 ModelSafeRoutingInfo routes; |
| 76 for (ModelTypeSet::Iterator iter = types.First(); iter.Good(); iter.Inc()) { |
| 77 routes[iter.Get()] = GROUP_PASSIVE; |
| 78 } |
| 79 return routes; |
| 80 } |
| 81 |
72 // Convenient to use in tests wishing to analyze SyncShare calls over time. | 82 // Convenient to use in tests wishing to analyze SyncShare calls over time. |
73 static const size_t kMinNumSamples = 5; | 83 static const size_t kMinNumSamples = 5; |
74 class SyncSchedulerTest : public testing::Test { | 84 class SyncSchedulerTest : public testing::Test { |
75 public: | 85 public: |
76 SyncSchedulerTest() | 86 SyncSchedulerTest() |
77 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 87 : weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
78 context_(NULL), | 88 context_(NULL), |
79 syncer_(NULL), | 89 syncer_(NULL), |
80 delay_(NULL) {} | 90 delay_(NULL) {} |
81 | 91 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 EXPECT_EQ(GetUpdatesCallerInfo::PERIODIC, | 155 EXPECT_EQ(GetUpdatesCallerInfo::PERIODIC, |
146 records.snapshots[i].source().updates_source); | 156 records.snapshots[i].source().updates_source); |
147 } | 157 } |
148 } | 158 } |
149 | 159 |
150 void DoQuitLoopNow() { | 160 void DoQuitLoopNow() { |
151 QuitLoopNow(); | 161 QuitLoopNow(); |
152 } | 162 } |
153 | 163 |
154 void StartSyncScheduler(SyncScheduler::Mode mode) { | 164 void StartSyncScheduler(SyncScheduler::Mode mode) { |
155 scheduler()->Start(mode, base::Closure()); | 165 scheduler()->Start(mode); |
156 } | 166 } |
157 | 167 |
158 // This stops the scheduler synchronously. | 168 // This stops the scheduler synchronously. |
159 void StopSyncScheduler() { | 169 void StopSyncScheduler() { |
160 scheduler()->RequestStop(base::Bind(&SyncSchedulerTest::DoQuitLoopNow, | 170 scheduler()->RequestStop(base::Bind(&SyncSchedulerTest::DoQuitLoopNow, |
161 weak_ptr_factory_.GetWeakPtr())); | 171 weak_ptr_factory_.GetWeakPtr())); |
162 RunLoop(); | 172 RunLoop(); |
163 } | 173 } |
164 | 174 |
165 bool RunAndGetBackoff() { | 175 bool RunAndGetBackoff() { |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, | 294 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, |
285 records2.snapshots[0].source().updates_source); | 295 records2.snapshots[0].source().updates_source); |
286 } | 296 } |
287 | 297 |
288 // Make sure a regular config command is scheduled fine in the absence of any | 298 // Make sure a regular config command is scheduled fine in the absence of any |
289 // errors. | 299 // errors. |
290 TEST_F(SyncSchedulerTest, Config) { | 300 TEST_F(SyncSchedulerTest, Config) { |
291 SyncShareRecords records; | 301 SyncShareRecords records; |
292 const ModelTypeSet model_types(syncable::BOOKMARKS); | 302 const ModelTypeSet model_types(syncable::BOOKMARKS); |
293 | 303 |
294 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 304 EXPECT_CALL(*syncer(), |
| 305 SyncShare(_,_,_)) |
| 306 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)) |
295 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 307 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
296 WithArg<0>(RecordSyncShare(&records)))); | 308 WithArg<0>(RecordSyncShare(&records)))); |
297 | 309 |
298 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 310 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
299 | 311 |
300 scheduler()->ScheduleConfiguration( | 312 CallbackCounter counter; |
301 model_types, GetUpdatesCallerInfo::RECONFIGURATION); | 313 ConfigurationParams params( |
| 314 GetUpdatesCallerInfo::RECONFIGURATION, |
| 315 model_types, |
| 316 TypesToRoutingInfo(model_types), |
| 317 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY, |
| 318 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); |
| 319 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params)); |
| 320 ASSERT_EQ(1, counter.times_called()); |
302 | 321 |
303 ASSERT_EQ(1U, records.snapshots.size()); | 322 ASSERT_EQ(1U, records.snapshots.size()); |
304 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types, | 323 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types, |
305 records.snapshots[0].source().types)); | 324 records.snapshots[0].source().types)); |
306 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, | 325 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, |
307 records.snapshots[0].source().updates_source); | 326 records.snapshots[0].source().updates_source); |
308 } | 327 } |
309 | 328 |
310 // Simulate a failure and make sure the config request is retried. | 329 // Simulate a failure and make sure the config request is retried. |
311 TEST_F(SyncSchedulerTest, ConfigWithBackingOff) { | 330 TEST_F(SyncSchedulerTest, ConfigWithBackingOff) { |
312 UseMockDelayProvider(); | 331 UseMockDelayProvider(); |
313 EXPECT_CALL(*delay(), GetDelay(_)) | 332 EXPECT_CALL(*delay(), GetDelay(_)) |
314 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(1))); | 333 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(1))); |
315 SyncShareRecords records; | 334 SyncShareRecords records; |
316 const ModelTypeSet model_types(syncable::BOOKMARKS); | 335 const ModelTypeSet model_types(syncable::BOOKMARKS); |
317 | 336 |
318 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 337 EXPECT_CALL(*syncer(), |
| 338 SyncShare(_,_,_)) |
| 339 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)) |
319 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), | 340 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), |
320 WithArg<0>(RecordSyncShare(&records)))) | 341 WithArg<0>(RecordSyncShare(&records)))) |
321 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 342 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
322 WithArg<0>(RecordSyncShare(&records)))); | 343 WithArg<0>(RecordSyncShare(&records)))); |
323 | 344 |
324 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 345 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
325 | 346 |
326 ASSERT_EQ(0U, records.snapshots.size()); | 347 ASSERT_EQ(0U, records.snapshots.size()); |
327 scheduler()->ScheduleConfiguration( | 348 CallbackCounter counter; |
328 model_types, GetUpdatesCallerInfo::RECONFIGURATION); | 349 ConfigurationParams params( |
| 350 GetUpdatesCallerInfo::RECONFIGURATION, |
| 351 model_types, |
| 352 TypesToRoutingInfo(model_types), |
| 353 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY, |
| 354 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); |
| 355 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params)); |
| 356 ASSERT_EQ(0, counter.times_called()); |
329 | 357 |
330 ASSERT_EQ(1U, records.snapshots.size()); | 358 ASSERT_EQ(1U, records.snapshots.size()); |
331 RunLoop(); | 359 RunLoop(); |
332 | 360 |
333 ASSERT_EQ(2U, records.snapshots.size()); | 361 ASSERT_EQ(2U, records.snapshots.size()); |
| 362 ASSERT_EQ(1, counter.times_called()); |
334 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types, | 363 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types, |
335 records.snapshots[1].source().types)); | 364 records.snapshots[1].source().types)); |
336 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, | 365 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, |
337 records.snapshots[1].source().updates_source); | 366 records.snapshots[1].source().updates_source); |
338 } | 367 } |
339 | 368 |
340 // Issue 2 config commands. Second one right after the first has failed | |
341 // and make sure LATEST is executed. | |
342 TEST_F(SyncSchedulerTest, MultipleConfigWithBackingOff) { | |
343 const ModelTypeSet | |
344 model_types1(syncable::BOOKMARKS), | |
345 model_types2(syncable::AUTOFILL); | |
346 UseMockDelayProvider(); | |
347 EXPECT_CALL(*delay(), GetDelay(_)) | |
348 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(30))); | |
349 SyncShareRecords records; | |
350 | |
351 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | |
352 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), | |
353 WithArg<0>(RecordSyncShare(&records)))) | |
354 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), | |
355 WithArg<0>(RecordSyncShare(&records)))) | |
356 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | |
357 WithArg<0>(RecordSyncShare(&records)))); | |
358 | |
359 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | |
360 | |
361 ASSERT_EQ(0U, records.snapshots.size()); | |
362 scheduler()->ScheduleConfiguration( | |
363 model_types1, GetUpdatesCallerInfo::RECONFIGURATION); | |
364 | |
365 ASSERT_EQ(1U, records.snapshots.size()); | |
366 scheduler()->ScheduleConfiguration( | |
367 model_types2, GetUpdatesCallerInfo::RECONFIGURATION); | |
368 | |
369 // A canary job gets posted when we go into exponential backoff. | |
370 RunLoop(); | |
371 | |
372 ASSERT_EQ(2U, records.snapshots.size()); | |
373 RunLoop(); | |
374 | |
375 ASSERT_EQ(3U, records.snapshots.size()); | |
376 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types2, | |
377 records.snapshots[2].source().types)); | |
378 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, | |
379 records.snapshots[2].source().updates_source); | |
380 } | |
381 | |
382 // Issue a nudge when the config has failed. Make sure both the config and | 369 // Issue a nudge when the config has failed. Make sure both the config and |
383 // nudge are executed. | 370 // nudge are executed. |
384 TEST_F(SyncSchedulerTest, NudgeWithConfigWithBackingOff) { | 371 TEST_F(SyncSchedulerTest, NudgeWithConfigWithBackingOff) { |
385 const ModelTypeSet model_types(syncable::BOOKMARKS); | 372 const ModelTypeSet model_types(syncable::BOOKMARKS); |
386 UseMockDelayProvider(); | 373 UseMockDelayProvider(); |
387 EXPECT_CALL(*delay(), GetDelay(_)) | 374 EXPECT_CALL(*delay(), GetDelay(_)) |
388 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(50))); | 375 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(50))); |
389 SyncShareRecords records; | 376 SyncShareRecords records; |
390 | 377 |
391 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 378 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
392 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), | 379 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), |
393 WithArg<0>(RecordSyncShare(&records)))) | 380 WithArg<0>(RecordSyncShare(&records)))) |
394 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), | 381 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), |
395 WithArg<0>(RecordSyncShare(&records)))) | 382 WithArg<0>(RecordSyncShare(&records)))) |
396 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 383 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
397 WithArg<0>(RecordSyncShare(&records)))) | 384 WithArg<0>(RecordSyncShare(&records)))) |
398 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 385 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
399 WithArg<0>(RecordSyncShare(&records)))); | 386 WithArg<0>(RecordSyncShare(&records)))); |
400 | 387 |
401 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 388 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
402 | 389 |
403 ASSERT_EQ(0U, records.snapshots.size()); | 390 ASSERT_EQ(0U, records.snapshots.size()); |
404 scheduler()->ScheduleConfiguration( | 391 CallbackCounter counter; |
405 model_types, GetUpdatesCallerInfo::RECONFIGURATION); | 392 ConfigurationParams params( |
| 393 GetUpdatesCallerInfo::RECONFIGURATION, |
| 394 model_types, |
| 395 TypesToRoutingInfo(model_types), |
| 396 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY, |
| 397 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); |
| 398 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params)); |
| 399 ASSERT_EQ(0, counter.times_called()); |
| 400 ASSERT_EQ(1U, records.snapshots.size()); |
406 | 401 |
407 ASSERT_EQ(1U, records.snapshots.size()); | |
408 scheduler()->ScheduleNudgeAsync( | 402 scheduler()->ScheduleNudgeAsync( |
409 zero(), NUDGE_SOURCE_LOCAL, model_types, FROM_HERE); | 403 zero(), NUDGE_SOURCE_LOCAL, model_types, FROM_HERE); |
410 RunLoop(); | 404 RunLoop(); |
| 405 ASSERT_EQ(2U, records.snapshots.size()); |
| 406 ASSERT_EQ(0, counter.times_called()); |
411 | 407 |
412 ASSERT_EQ(2U, records.snapshots.size()); | |
413 RunLoop(); | 408 RunLoop(); |
| 409 ASSERT_EQ(3U, records.snapshots.size()); |
| 410 ASSERT_EQ(1, counter.times_called()); |
414 | 411 |
415 // Now change the mode so nudge can execute. | 412 // Now change the mode so nudge can execute. |
416 ASSERT_EQ(3U, records.snapshots.size()); | |
417 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 413 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
418 | 414 |
419 ASSERT_EQ(4U, records.snapshots.size()); | 415 ASSERT_EQ(4U, records.snapshots.size()); |
420 | 416 |
421 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types, | 417 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types, |
422 records.snapshots[2].source().types)); | 418 records.snapshots[2].source().types)); |
423 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, | 419 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, |
424 records.snapshots[2].source().updates_source); | 420 records.snapshots[2].source().updates_source); |
425 | 421 |
426 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types, | 422 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(model_types, |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
711 QuitLoopNowAction())); | 707 QuitLoopNowAction())); |
712 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 708 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
713 | 709 |
714 scheduler()->ScheduleNudgeAsync( | 710 scheduler()->ScheduleNudgeAsync( |
715 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(), FROM_HERE); | 711 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(), FROM_HERE); |
716 | 712 |
717 // We should detect the failure on the second sync share, and go into backoff. | 713 // We should detect the failure on the second sync share, and go into backoff. |
718 EXPECT_TRUE(RunAndGetBackoff()); | 714 EXPECT_TRUE(RunAndGetBackoff()); |
719 } | 715 } |
720 | 716 |
721 // Test that no syncing occurs when throttled. | 717 // Test that no syncing occurs when throttled (although CleanupDisabledTypes |
| 718 // is allowed). |
722 TEST_F(SyncSchedulerTest, ThrottlingDoesThrottle) { | 719 TEST_F(SyncSchedulerTest, ThrottlingDoesThrottle) { |
723 const ModelTypeSet types(syncable::BOOKMARKS); | 720 const ModelTypeSet types(syncable::BOOKMARKS); |
724 TimeDelta poll(TimeDelta::FromMilliseconds(5)); | 721 TimeDelta poll(TimeDelta::FromMilliseconds(5)); |
725 TimeDelta throttle(TimeDelta::FromMinutes(10)); | 722 TimeDelta throttle(TimeDelta::FromMinutes(10)); |
726 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 723 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
727 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 724 |
| 725 EXPECT_CALL(*syncer(), |
| 726 SyncShare(_, CLEANUP_DISABLED_TYPES, CLEANUP_DISABLED_TYPES)) |
| 727 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)); |
| 728 EXPECT_CALL(*syncer(), SyncShare(_,Not(CLEANUP_DISABLED_TYPES), |
| 729 Not(CLEANUP_DISABLED_TYPES))) |
728 .WillOnce(WithArg<0>(sessions::test_util::SimulateThrottled(throttle))) | 730 .WillOnce(WithArg<0>(sessions::test_util::SimulateThrottled(throttle))) |
729 .WillRepeatedly(AddFailureAndQuitLoopNow()); | 731 .WillRepeatedly(AddFailureAndQuitLoopNow()); |
730 | 732 |
731 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 733 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
732 | 734 |
733 scheduler()->ScheduleNudgeAsync( | 735 scheduler()->ScheduleNudgeAsync( |
734 zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE); | 736 zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE); |
735 PumpLoop(); | 737 PumpLoop(); |
736 | 738 |
737 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 739 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
738 | 740 |
739 scheduler()->ScheduleConfiguration( | 741 CallbackCounter counter; |
740 types, GetUpdatesCallerInfo::RECONFIGURATION); | 742 ConfigurationParams params( |
| 743 GetUpdatesCallerInfo::RECONFIGURATION, |
| 744 types, |
| 745 TypesToRoutingInfo(types), |
| 746 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY, |
| 747 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); |
| 748 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params)); |
| 749 ASSERT_EQ(0, counter.times_called()); |
741 } | 750 } |
742 | 751 |
743 TEST_F(SyncSchedulerTest, ThrottlingExpires) { | 752 TEST_F(SyncSchedulerTest, ThrottlingExpires) { |
744 SyncShareRecords records; | 753 SyncShareRecords records; |
745 TimeDelta poll(TimeDelta::FromMilliseconds(15)); | 754 TimeDelta poll(TimeDelta::FromMilliseconds(15)); |
746 TimeDelta throttle1(TimeDelta::FromMilliseconds(150)); | 755 TimeDelta throttle1(TimeDelta::FromMilliseconds(150)); |
747 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 756 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
748 | 757 |
749 ::testing::InSequence seq; | 758 ::testing::InSequence seq; |
750 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 759 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
(...skipping 12 matching lines...) Expand all Loading... |
763 StopSyncScheduler(); | 772 StopSyncScheduler(); |
764 AnalyzePollRun(records, kMinNumSamples, optimal_start, poll); | 773 AnalyzePollRun(records, kMinNumSamples, optimal_start, poll); |
765 } | 774 } |
766 | 775 |
767 // Test nudges / polls don't run in config mode and config tasks do. | 776 // Test nudges / polls don't run in config mode and config tasks do. |
768 TEST_F(SyncSchedulerTest, ConfigurationMode) { | 777 TEST_F(SyncSchedulerTest, ConfigurationMode) { |
769 TimeDelta poll(TimeDelta::FromMilliseconds(15)); | 778 TimeDelta poll(TimeDelta::FromMilliseconds(15)); |
770 SyncShareRecords records; | 779 SyncShareRecords records; |
771 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 780 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
772 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 781 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
| 782 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)) |
773 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 783 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
774 WithArg<0>(RecordSyncShare(&records)))); | 784 WithArg<0>(RecordSyncShare(&records)))); |
775 | 785 |
776 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 786 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
777 | 787 |
778 const ModelTypeSet nudge_types(syncable::AUTOFILL); | 788 const ModelTypeSet nudge_types(syncable::AUTOFILL); |
779 scheduler()->ScheduleNudgeAsync( | 789 scheduler()->ScheduleNudgeAsync( |
780 zero(), NUDGE_SOURCE_LOCAL, nudge_types, FROM_HERE); | 790 zero(), NUDGE_SOURCE_LOCAL, nudge_types, FROM_HERE); |
781 scheduler()->ScheduleNudgeAsync( | 791 scheduler()->ScheduleNudgeAsync( |
782 zero(), NUDGE_SOURCE_LOCAL, nudge_types, FROM_HERE); | 792 zero(), NUDGE_SOURCE_LOCAL, nudge_types, FROM_HERE); |
783 | 793 |
784 const ModelTypeSet config_types(syncable::BOOKMARKS); | 794 const ModelTypeSet config_types(syncable::BOOKMARKS); |
785 | 795 |
786 scheduler()->ScheduleConfiguration( | 796 CallbackCounter counter; |
787 config_types, GetUpdatesCallerInfo::RECONFIGURATION); | 797 ConfigurationParams params( |
| 798 GetUpdatesCallerInfo::RECONFIGURATION, |
| 799 config_types, |
| 800 TypesToRoutingInfo(config_types), |
| 801 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY, |
| 802 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); |
| 803 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params)); |
| 804 ASSERT_EQ(1, counter.times_called()); |
788 | 805 |
789 ASSERT_EQ(1U, records.snapshots.size()); | 806 ASSERT_EQ(1U, records.snapshots.size()); |
790 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(config_types, | 807 EXPECT_TRUE(CompareModelTypeSetToModelTypePayloadMap(config_types, |
791 records.snapshots[0].source().types)); | 808 records.snapshots[0].source().types)); |
792 } | 809 } |
793 | 810 |
794 class BackoffTriggersSyncSchedulerTest : public SyncSchedulerTest { | 811 class BackoffTriggersSyncSchedulerTest : public SyncSchedulerTest { |
795 void SetUp() { | 812 void SetUp() { |
796 SyncSchedulerTest::SetUp(); | 813 SyncSchedulerTest::SetUp(); |
797 UseMockDelayProvider(); | 814 UseMockDelayProvider(); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
846 } | 863 } |
847 | 864 |
848 // Test that no polls or extraneous nudges occur when in backoff. | 865 // Test that no polls or extraneous nudges occur when in backoff. |
849 TEST_F(SyncSchedulerTest, BackoffDropsJobs) { | 866 TEST_F(SyncSchedulerTest, BackoffDropsJobs) { |
850 SyncShareRecords r; | 867 SyncShareRecords r; |
851 TimeDelta poll(TimeDelta::FromMilliseconds(5)); | 868 TimeDelta poll(TimeDelta::FromMilliseconds(5)); |
852 const ModelTypeSet types(syncable::BOOKMARKS); | 869 const ModelTypeSet types(syncable::BOOKMARKS); |
853 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 870 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
854 UseMockDelayProvider(); | 871 UseMockDelayProvider(); |
855 | 872 |
856 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(1) | 873 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
857 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), | 874 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), |
858 RecordSyncShareMultiple(&r, 1U))); | 875 RecordSyncShareMultiple(&r, 1U))); |
859 EXPECT_CALL(*delay(), GetDelay(_)). | 876 EXPECT_CALL(*delay(), GetDelay(_)). |
860 WillRepeatedly(Return(TimeDelta::FromDays(1))); | 877 WillRepeatedly(Return(TimeDelta::FromDays(1))); |
861 | 878 |
862 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 879 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
863 | 880 |
864 // This nudge should fail and put us into backoff. Thanks to our mock | 881 // This nudge should fail and put us into backoff. Thanks to our mock |
865 // GetDelay() setup above, this will be a long backoff. | 882 // GetDelay() setup above, this will be a long backoff. |
866 scheduler()->ScheduleNudgeAsync(zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE); | 883 scheduler()->ScheduleNudgeAsync(zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE); |
(...skipping 21 matching lines...) Expand all Loading... |
888 r.snapshots[1].source().updates_source); | 905 r.snapshots[1].source().updates_source); |
889 | 906 |
890 // Cleanup is not affected by backoff, but it should not relieve it either. | 907 // Cleanup is not affected by backoff, but it should not relieve it either. |
891 EXPECT_CALL(*syncer(), | 908 EXPECT_CALL(*syncer(), |
892 SyncShare(_, CLEANUP_DISABLED_TYPES, CLEANUP_DISABLED_TYPES)) | 909 SyncShare(_, CLEANUP_DISABLED_TYPES, CLEANUP_DISABLED_TYPES)) |
893 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)); | 910 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)); |
894 EXPECT_CALL(*delay(), GetDelay(_)).Times(0); | 911 EXPECT_CALL(*delay(), GetDelay(_)).Times(0); |
895 | 912 |
896 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 913 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
897 | 914 |
898 scheduler()->CleanupDisabledTypes(); | 915 CallbackCounter counter; |
899 scheduler()->ScheduleConfiguration( | 916 ConfigurationParams params( |
900 types, GetUpdatesCallerInfo::RECONFIGURATION); | 917 GetUpdatesCallerInfo::RECONFIGURATION, |
| 918 types, |
| 919 TypesToRoutingInfo(types), |
| 920 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY, |
| 921 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); |
| 922 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params)); |
| 923 ASSERT_EQ(0, counter.times_called()); |
901 | 924 |
902 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 925 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
903 | 926 |
904 scheduler()->ScheduleNudgeAsync( | 927 scheduler()->ScheduleNudgeAsync( |
905 zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE); | 928 zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE); |
906 scheduler()->ScheduleNudgeAsync( | 929 scheduler()->ScheduleNudgeAsync( |
907 zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE); | 930 zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE); |
908 PumpLoop(); | 931 PumpLoop(); |
909 } | 932 } |
910 | 933 |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1059 // ClearUserData. | 1082 // ClearUserData. |
1060 EXPECT_CALL(*syncer(), SyncShare(_, CLEAR_PRIVATE_DATA, CLEAR_PRIVATE_DATA)) | 1083 EXPECT_CALL(*syncer(), SyncShare(_, CLEAR_PRIVATE_DATA, CLEAR_PRIVATE_DATA)) |
1061 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)); | 1084 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)); |
1062 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 1085 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
1063 | 1086 |
1064 scheduler()->ClearUserData(); | 1087 scheduler()->ClearUserData(); |
1065 | 1088 |
1066 StopSyncScheduler(); | 1089 StopSyncScheduler(); |
1067 Mock::VerifyAndClearExpectations(syncer()); | 1090 Mock::VerifyAndClearExpectations(syncer()); |
1068 | 1091 |
1069 // Configuration. | 1092 // Configuration (always includes a cleanup disabled types). |
| 1093 EXPECT_CALL(*syncer(), |
| 1094 SyncShare(_, CLEANUP_DISABLED_TYPES, CLEANUP_DISABLED_TYPES)) |
| 1095 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)); |
1070 EXPECT_CALL(*syncer(), SyncShare(_, DOWNLOAD_UPDATES, APPLY_UPDATES)) | 1096 EXPECT_CALL(*syncer(), SyncShare(_, DOWNLOAD_UPDATES, APPLY_UPDATES)) |
1071 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)); | 1097 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)); |
1072 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 1098 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
1073 | 1099 |
1074 scheduler()->ScheduleConfiguration( | 1100 syncable::ModelTypeSet model_types(syncable::BOOKMARKS); |
1075 ModelTypeSet(), GetUpdatesCallerInfo::RECONFIGURATION); | 1101 CallbackCounter counter; |
1076 | 1102 ConfigurationParams params( |
| 1103 GetUpdatesCallerInfo::RECONFIGURATION, |
| 1104 model_types, |
| 1105 TypesToRoutingInfo(model_types), |
| 1106 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY, |
| 1107 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); |
| 1108 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params)); |
| 1109 ASSERT_EQ(1, counter.times_called()); |
| 1110 // Runs directly so no need to pump the loop. |
1077 StopSyncScheduler(); | 1111 StopSyncScheduler(); |
1078 Mock::VerifyAndClearExpectations(syncer()); | 1112 Mock::VerifyAndClearExpectations(syncer()); |
1079 | 1113 |
1080 // Cleanup disabled types. | 1114 // Cleanup disabled types. Because no types are being configured, we just |
| 1115 // perform the cleanup. |
1081 EXPECT_CALL(*syncer(), | 1116 EXPECT_CALL(*syncer(), |
1082 SyncShare(_, CLEANUP_DISABLED_TYPES, CLEANUP_DISABLED_TYPES)) | 1117 SyncShare(_, CLEANUP_DISABLED_TYPES, CLEANUP_DISABLED_TYPES)). |
1083 .WillOnce(Invoke(sessions::test_util::SimulateSuccess)); | 1118 WillOnce(Invoke(sessions::test_util::SimulateSuccess)); |
1084 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 1119 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
1085 | 1120 |
1086 scheduler()->CleanupDisabledTypes(); | 1121 CallbackCounter counter2; |
1087 | 1122 ConfigurationParams params2( |
| 1123 GetUpdatesCallerInfo::RECONFIGURATION, |
| 1124 ModelTypeSet(), |
| 1125 ModelSafeRoutingInfo(), |
| 1126 ConfigurationParams::KEYSTORE_KEY_UNNECESSARY, |
| 1127 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter2))); |
| 1128 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params2)); |
| 1129 ASSERT_EQ(1, counter2.times_called()); |
1088 StopSyncScheduler(); | 1130 StopSyncScheduler(); |
1089 Mock::VerifyAndClearExpectations(syncer()); | 1131 Mock::VerifyAndClearExpectations(syncer()); |
1090 | 1132 |
| 1133 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
| 1134 |
1091 // Poll. | 1135 // Poll. |
1092 EXPECT_CALL(*syncer(), SyncShare(_, SYNCER_BEGIN, SYNCER_END)) | 1136 EXPECT_CALL(*syncer(), SyncShare(_, SYNCER_BEGIN, SYNCER_END)) |
1093 .Times(AtLeast(1)) | 1137 .Times(AtLeast(1)) |
1094 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess), | 1138 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess), |
1095 QuitLoopNowAction())); | 1139 QuitLoopNowAction())); |
1096 const TimeDelta poll(TimeDelta::FromMilliseconds(10)); | 1140 const TimeDelta poll(TimeDelta::FromMilliseconds(10)); |
1097 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 1141 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
1098 | 1142 |
1099 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 1143 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
1100 | 1144 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1145 PumpLoop(); | 1189 PumpLoop(); |
1146 // Pump again to run job. | 1190 // Pump again to run job. |
1147 PumpLoop(); | 1191 PumpLoop(); |
1148 | 1192 |
1149 StopSyncScheduler(); | 1193 StopSyncScheduler(); |
1150 | 1194 |
1151 EXPECT_TRUE(expected == context()->previous_session_routing_info()); | 1195 EXPECT_TRUE(expected == context()->previous_session_routing_info()); |
1152 } | 1196 } |
1153 | 1197 |
1154 } // namespace browser_sync | 1198 } // namespace browser_sync |
OLD | NEW |