| 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/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" |
| 11 #include "sync/engine/backoff_delay_provider.h" | 11 #include "sync/engine/backoff_delay_provider.h" |
| 12 #include "sync/engine/sync_scheduler_impl.h" | 12 #include "sync/engine/sync_scheduler_impl.h" |
| 13 #include "sync/engine/syncer.h" | 13 #include "sync/engine/syncer.h" |
| 14 #include "sync/internal_api/public/base/model_type_invalidation_map_test_util.h" | |
| 15 #include "sync/sessions/test_util.h" | 14 #include "sync/sessions/test_util.h" |
| 16 #include "sync/test/callback_counter.h" | 15 #include "sync/test/callback_counter.h" |
| 17 #include "sync/test/engine/fake_model_worker.h" | 16 #include "sync/test/engine/fake_model_worker.h" |
| 18 #include "sync/test/engine/mock_connection_manager.h" | 17 #include "sync/test/engine/mock_connection_manager.h" |
| 19 #include "sync/test/engine/test_directory_setter_upper.h" | 18 #include "sync/test/engine/test_directory_setter_upper.h" |
| 20 #include "sync/test/fake_extensions_activity_monitor.h" | 19 #include "sync/test/fake_extensions_activity_monitor.h" |
| 21 #include "testing/gmock/include/gmock/gmock.h" | 20 #include "testing/gmock/include/gmock/gmock.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 22 |
| 24 using base::TimeDelta; | 23 using base::TimeDelta; |
| 25 using base::TimeTicks; | 24 using base::TimeTicks; |
| 26 using testing::_; | 25 using testing::_; |
| 27 using testing::AtLeast; | 26 using testing::AtLeast; |
| 28 using testing::DoAll; | 27 using testing::DoAll; |
| 29 using testing::Eq; | |
| 30 using testing::Invoke; | 28 using testing::Invoke; |
| 31 using testing::Mock; | 29 using testing::Mock; |
| 32 using testing::Not; | |
| 33 using testing::Return; | 30 using testing::Return; |
| 34 using testing::WithArg; | 31 using testing::WithArg; |
| 35 using testing::WithArgs; | 32 using testing::WithArgs; |
| 36 | 33 |
| 37 namespace syncer { | 34 namespace syncer { |
| 38 using sessions::SyncSession; | 35 using sessions::SyncSession; |
| 39 using sessions::SyncSessionContext; | 36 using sessions::SyncSessionContext; |
| 40 using sessions::SyncSessionSnapshot; | |
| 41 using sync_pb::GetUpdatesCallerInfo; | 37 using sync_pb::GetUpdatesCallerInfo; |
| 42 | 38 |
| 43 class MockSyncer : public Syncer { | 39 class MockSyncer : public Syncer { |
| 44 public: | 40 public: |
| 45 MOCK_METHOD3(NormalSyncShare, bool(ModelTypeSet, | 41 MOCK_METHOD3(NormalSyncShare, bool(ModelTypeSet, |
| 46 const sessions::NudgeTracker&, | 42 const sessions::NudgeTracker&, |
| 47 sessions::SyncSession*)); | 43 sessions::SyncSession*)); |
| 48 MOCK_METHOD2(ConfigureSyncShare, bool(ModelTypeSet, sessions::SyncSession*)); | 44 MOCK_METHOD3(ConfigureSyncShare, |
| 45 bool(ModelTypeSet, |
| 46 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource, |
| 47 SyncSession*)); |
| 49 MOCK_METHOD2(PollSyncShare, bool(ModelTypeSet, sessions::SyncSession*)); | 48 MOCK_METHOD2(PollSyncShare, bool(ModelTypeSet, sessions::SyncSession*)); |
| 50 }; | 49 }; |
| 51 | 50 |
| 52 // Used when tests want to record syncing activity to examine later. | 51 typedef std::vector<TimeTicks> SyncShareTimes; |
| 53 struct SyncShareRecords { | |
| 54 std::vector<TimeTicks> times; | |
| 55 std::vector<SyncSessionSnapshot> snapshots; | |
| 56 }; | |
| 57 | 52 |
| 58 void QuitLoopNow() { | 53 void QuitLoopNow() { |
| 59 // We use QuitNow() instead of Quit() as the latter may get stalled | 54 // We use QuitNow() instead of Quit() as the latter may get stalled |
| 60 // indefinitely in the presence of repeated timers with low delays | 55 // indefinitely in the presence of repeated timers with low delays |
| 61 // and a slow test (e.g., ThrottlingDoesThrottle [which has a poll | 56 // and a slow test (e.g., ThrottlingDoesThrottle [which has a poll |
| 62 // delay of 5ms] run under TSAN on the trybots). | 57 // delay of 5ms] run under TSAN on the trybots). |
| 63 base::MessageLoop::current()->QuitNow(); | 58 base::MessageLoop::current()->QuitNow(); |
| 64 } | 59 } |
| 65 | 60 |
| 66 void RunLoop() { | 61 void RunLoop() { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 83 } | 78 } |
| 84 | 79 |
| 85 ModelSafeRoutingInfo TypesToRoutingInfo(ModelTypeSet types) { | 80 ModelSafeRoutingInfo TypesToRoutingInfo(ModelTypeSet types) { |
| 86 ModelSafeRoutingInfo routes; | 81 ModelSafeRoutingInfo routes; |
| 87 for (ModelTypeSet::Iterator iter = types.First(); iter.Good(); iter.Inc()) { | 82 for (ModelTypeSet::Iterator iter = types.First(); iter.Good(); iter.Inc()) { |
| 88 routes[iter.Get()] = GROUP_PASSIVE; | 83 routes[iter.Get()] = GROUP_PASSIVE; |
| 89 } | 84 } |
| 90 return routes; | 85 return routes; |
| 91 } | 86 } |
| 92 | 87 |
| 93 // Compare a ModelTypeSet to a ModelTypeInvalidationMap, ignoring | |
| 94 // state values. | |
| 95 testing::AssertionResult ModelTypeSetMatchesInvalidationMap( | |
| 96 ModelTypeSet lhs, const ModelTypeInvalidationMap& rhs) { | |
| 97 ModelTypeSet rhs_set = ModelTypeInvalidationMapToSet(rhs); | |
| 98 | |
| 99 if (!rhs_set.Equals(rhs_set)) { | |
| 100 return testing::AssertionFailure() | |
| 101 << "ModelTypeSet: " << ModelTypeSetToString(lhs) | |
| 102 << " does not match ModelTypeInvalidationMap: " | |
| 103 << ModelTypeSetToString(rhs_set); | |
| 104 } else { | |
| 105 return testing::AssertionSuccess(); | |
| 106 } | |
| 107 } | |
| 108 | |
| 109 // Convenient to use in tests wishing to analyze SyncShare calls over time. | 88 // Convenient to use in tests wishing to analyze SyncShare calls over time. |
| 110 static const size_t kMinNumSamples = 5; | 89 static const size_t kMinNumSamples = 5; |
| 111 class SyncSchedulerTest : public testing::Test { | 90 class SyncSchedulerTest : public testing::Test { |
| 112 public: | 91 public: |
| 113 SyncSchedulerTest() : weak_ptr_factory_(this), syncer_(NULL), delay_(NULL) {} | 92 SyncSchedulerTest() : weak_ptr_factory_(this), syncer_(NULL), delay_(NULL) {} |
| 114 | 93 |
| 115 class MockDelayProvider : public BackoffDelayProvider { | 94 class MockDelayProvider : public BackoffDelayProvider { |
| 116 public: | 95 public: |
| 117 MockDelayProvider() : BackoffDelayProvider( | 96 MockDelayProvider() : BackoffDelayProvider( |
| 118 TimeDelta::FromSeconds(kInitialBackoffRetrySeconds), | 97 TimeDelta::FromSeconds(kInitialBackoffRetrySeconds), |
| 119 TimeDelta::FromSeconds(kInitialBackoffImmediateRetrySeconds)) { | 98 TimeDelta::FromSeconds(kInitialBackoffImmediateRetrySeconds)) { |
| 120 } | 99 } |
| 121 | 100 |
| 122 MOCK_METHOD1(GetDelay, TimeDelta(const TimeDelta&)); | 101 MOCK_METHOD1(GetDelay, TimeDelta(const TimeDelta&)); |
| 123 }; | 102 }; |
| 124 | 103 |
| 125 virtual void SetUp() { | 104 virtual void SetUp() { |
| 126 dir_maker_.SetUp(); | 105 dir_maker_.SetUp(); |
| 127 syncer_ = new MockSyncer(); | 106 syncer_ = new testing::StrictMock<MockSyncer>(); |
| 128 delay_ = NULL; | 107 delay_ = NULL; |
| 129 | 108 |
| 130 routing_info_[BOOKMARKS] = GROUP_UI; | 109 routing_info_[BOOKMARKS] = GROUP_UI; |
| 131 routing_info_[AUTOFILL] = GROUP_DB; | 110 routing_info_[AUTOFILL] = GROUP_DB; |
| 132 routing_info_[THEMES] = GROUP_UI; | 111 routing_info_[THEMES] = GROUP_UI; |
| 133 routing_info_[NIGORI] = GROUP_PASSIVE; | 112 routing_info_[NIGORI] = GROUP_PASSIVE; |
| 134 | 113 |
| 135 workers_.clear(); | 114 workers_.clear(); |
| 136 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_UI))); | 115 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_UI))); |
| 137 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_DB))); | 116 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_DB))); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 return TestTimeouts::action_timeout(); | 151 return TestTimeouts::action_timeout(); |
| 173 } | 152 } |
| 174 | 153 |
| 175 virtual void TearDown() { | 154 virtual void TearDown() { |
| 176 PumpLoop(); | 155 PumpLoop(); |
| 177 scheduler_.reset(); | 156 scheduler_.reset(); |
| 178 PumpLoop(); | 157 PumpLoop(); |
| 179 dir_maker_.TearDown(); | 158 dir_maker_.TearDown(); |
| 180 } | 159 } |
| 181 | 160 |
| 182 void AnalyzePollRun(const SyncShareRecords& records, size_t min_num_samples, | 161 void AnalyzePollRun(const SyncShareTimes& times, size_t min_num_samples, |
| 183 const TimeTicks& optimal_start, const TimeDelta& poll_interval) { | 162 const TimeTicks& optimal_start, const TimeDelta& poll_interval) { |
| 184 const std::vector<TimeTicks>& data(records.times); | 163 EXPECT_GE(times.size(), min_num_samples); |
| 185 EXPECT_GE(data.size(), min_num_samples); | 164 for (size_t i = 0; i < times.size(); i++) { |
| 186 for (size_t i = 0; i < data.size(); i++) { | |
| 187 SCOPED_TRACE(testing::Message() << "SyncShare # (" << i << ")"); | 165 SCOPED_TRACE(testing::Message() << "SyncShare # (" << i << ")"); |
| 188 TimeTicks optimal_next_sync = optimal_start + poll_interval * i; | 166 TimeTicks optimal_next_sync = optimal_start + poll_interval * i; |
| 189 EXPECT_GE(data[i], optimal_next_sync); | 167 EXPECT_GE(times[i], optimal_next_sync); |
| 190 EXPECT_EQ(GetUpdatesCallerInfo::PERIODIC, | |
| 191 records.snapshots[i].source().updates_source); | |
| 192 } | 168 } |
| 193 } | 169 } |
| 194 | 170 |
| 195 void DoQuitLoopNow() { | 171 void DoQuitLoopNow() { |
| 196 QuitLoopNow(); | 172 QuitLoopNow(); |
| 197 } | 173 } |
| 198 | 174 |
| 199 void StartSyncScheduler(SyncScheduler::Mode mode) { | 175 void StartSyncScheduler(SyncScheduler::Mode mode) { |
| 200 scheduler()->Start(mode); | 176 scheduler()->Start(mode); |
| 201 } | 177 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 scoped_ptr<MockConnectionManager> connection_; | 215 scoped_ptr<MockConnectionManager> connection_; |
| 240 scoped_ptr<SyncSessionContext> context_; | 216 scoped_ptr<SyncSessionContext> context_; |
| 241 scoped_ptr<SyncSchedulerImpl> scheduler_; | 217 scoped_ptr<SyncSchedulerImpl> scheduler_; |
| 242 MockSyncer* syncer_; | 218 MockSyncer* syncer_; |
| 243 MockDelayProvider* delay_; | 219 MockDelayProvider* delay_; |
| 244 std::vector<scoped_refptr<FakeModelWorker> > workers_; | 220 std::vector<scoped_refptr<FakeModelWorker> > workers_; |
| 245 FakeExtensionsActivityMonitor extensions_activity_monitor_; | 221 FakeExtensionsActivityMonitor extensions_activity_monitor_; |
| 246 ModelSafeRoutingInfo routing_info_; | 222 ModelSafeRoutingInfo routing_info_; |
| 247 }; | 223 }; |
| 248 | 224 |
| 249 void RecordSyncShareImpl(SyncSession* s, SyncShareRecords* record) { | 225 void RecordSyncShareImpl(SyncShareTimes* times) { |
| 250 record->times.push_back(TimeTicks::Now()); | 226 times->push_back(TimeTicks::Now()); |
| 251 record->snapshots.push_back(s->TakeSnapshot()); | |
| 252 } | 227 } |
| 253 | 228 |
| 254 ACTION_P(RecordSyncShare, record) { | 229 ACTION_P(RecordSyncShare, times) { |
| 255 RecordSyncShareImpl(arg0, record); | 230 RecordSyncShareImpl(times); |
| 256 if (base::MessageLoop::current()->is_running()) | 231 if (base::MessageLoop::current()->is_running()) |
| 257 QuitLoopNow(); | 232 QuitLoopNow(); |
| 258 return true; | 233 return true; |
| 259 } | 234 } |
| 260 | 235 |
| 261 ACTION_P2(RecordSyncShareMultiple, record, quit_after) { | 236 ACTION_P2(RecordSyncShareMultiple, times, quit_after) { |
| 262 RecordSyncShareImpl(arg0, record); | 237 RecordSyncShareImpl(times); |
| 263 EXPECT_LE(record->times.size(), quit_after); | 238 EXPECT_LE(times->size(), quit_after); |
| 264 if (record->times.size() >= quit_after && | 239 if (times->size() >= quit_after && |
| 265 base::MessageLoop::current()->is_running()) { | 240 base::MessageLoop::current()->is_running()) { |
| 266 QuitLoopNow(); | 241 QuitLoopNow(); |
| 267 } | 242 } |
| 268 return true; | 243 return true; |
| 269 } | 244 } |
| 270 | 245 |
| 271 ACTION(AddFailureAndQuitLoopNow) { | 246 ACTION(AddFailureAndQuitLoopNow) { |
| 272 ADD_FAILURE(); | 247 ADD_FAILURE(); |
| 273 QuitLoopNow(); | 248 QuitLoopNow(); |
| 274 return true; | 249 return true; |
| 275 } | 250 } |
| 276 | 251 |
| 277 ACTION(QuitLoopNowAction) { | 252 ACTION(QuitLoopNowAction) { |
| 278 QuitLoopNow(); | 253 QuitLoopNow(); |
| 279 return true; | 254 return true; |
| 280 } | 255 } |
| 281 | 256 |
| 282 // Test nudge scheduling. | 257 // Test nudge scheduling. |
| 283 TEST_F(SyncSchedulerTest, Nudge) { | 258 TEST_F(SyncSchedulerTest, Nudge) { |
| 284 SyncShareRecords records; | 259 SyncShareTimes times; |
| 285 ModelTypeSet model_types(BOOKMARKS); | 260 ModelTypeSet model_types(BOOKMARKS); |
| 286 | 261 |
| 287 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 262 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
| 288 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 263 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), |
| 289 WithArg<2>(RecordSyncShare(&records)))) | 264 RecordSyncShare(×))) |
| 290 .RetiresOnSaturation(); | 265 .RetiresOnSaturation(); |
| 291 | 266 |
| 292 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 267 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
| 293 | 268 |
| 294 scheduler()->ScheduleLocalNudge(zero(), model_types, FROM_HERE); | 269 scheduler()->ScheduleLocalNudge(zero(), model_types, FROM_HERE); |
| 295 RunLoop(); | 270 RunLoop(); |
| 296 | 271 |
| 297 ASSERT_EQ(1U, records.snapshots.size()); | |
| 298 EXPECT_TRUE(ModelTypeSetMatchesInvalidationMap( | |
| 299 model_types, | |
| 300 records.snapshots[0].source().types)); | |
| 301 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, | |
| 302 records.snapshots[0].source().updates_source); | |
| 303 | |
| 304 Mock::VerifyAndClearExpectations(syncer()); | 272 Mock::VerifyAndClearExpectations(syncer()); |
| 305 | 273 |
| 306 // Make sure a second, later, nudge is unaffected by first (no coalescing). | 274 // Make sure a second, later, nudge is unaffected by first (no coalescing). |
| 307 SyncShareRecords records2; | 275 SyncShareTimes times2; |
| 308 model_types.Remove(BOOKMARKS); | 276 model_types.Remove(BOOKMARKS); |
| 309 model_types.Put(AUTOFILL); | 277 model_types.Put(AUTOFILL); |
| 310 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 278 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
| 311 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 279 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), |
| 312 WithArg<2>(RecordSyncShare(&records2)))); | 280 RecordSyncShare(×2))); |
| 313 scheduler()->ScheduleLocalNudge(zero(), model_types, FROM_HERE); | 281 scheduler()->ScheduleLocalNudge(zero(), model_types, FROM_HERE); |
| 314 RunLoop(); | 282 RunLoop(); |
| 315 | |
| 316 ASSERT_EQ(1U, records2.snapshots.size()); | |
| 317 EXPECT_TRUE(ModelTypeSetMatchesInvalidationMap( | |
| 318 model_types, | |
| 319 records2.snapshots[0].source().types)); | |
| 320 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, | |
| 321 records2.snapshots[0].source().updates_source); | |
| 322 } | 283 } |
| 323 | 284 |
| 324 // Make sure a regular config command is scheduled fine in the absence of any | 285 // Make sure a regular config command is scheduled fine in the absence of any |
| 325 // errors. | 286 // errors. |
| 326 TEST_F(SyncSchedulerTest, Config) { | 287 TEST_F(SyncSchedulerTest, Config) { |
| 327 SyncShareRecords records; | 288 SyncShareTimes times; |
| 328 const ModelTypeSet model_types(BOOKMARKS); | 289 const ModelTypeSet model_types(BOOKMARKS); |
| 329 | 290 |
| 330 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_)) | 291 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) |
| 331 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess), | 292 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess), |
| 332 WithArg<1>(RecordSyncShare(&records)))); | 293 RecordSyncShare(×))); |
| 333 | 294 |
| 334 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 295 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
| 335 | 296 |
| 336 CallbackCounter counter; | 297 CallbackCounter counter; |
| 337 ConfigurationParams params( | 298 ConfigurationParams params( |
| 338 GetUpdatesCallerInfo::RECONFIGURATION, | 299 GetUpdatesCallerInfo::RECONFIGURATION, |
| 339 model_types, | 300 model_types, |
| 340 TypesToRoutingInfo(model_types), | 301 TypesToRoutingInfo(model_types), |
| 341 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); | 302 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); |
| 342 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params)); | 303 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params)); |
| 343 ASSERT_EQ(1, counter.times_called()); | 304 ASSERT_EQ(1, counter.times_called()); |
| 344 | |
| 345 ASSERT_EQ(1U, records.snapshots.size()); | |
| 346 EXPECT_TRUE(ModelTypeSetMatchesInvalidationMap( | |
| 347 model_types, | |
| 348 records.snapshots[0].source().types)); | |
| 349 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, | |
| 350 records.snapshots[0].source().updates_source); | |
| 351 } | 305 } |
| 352 | 306 |
| 353 // Simulate a failure and make sure the config request is retried. | 307 // Simulate a failure and make sure the config request is retried. |
| 354 TEST_F(SyncSchedulerTest, ConfigWithBackingOff) { | 308 TEST_F(SyncSchedulerTest, ConfigWithBackingOff) { |
| 355 UseMockDelayProvider(); | 309 UseMockDelayProvider(); |
| 356 EXPECT_CALL(*delay(), GetDelay(_)) | 310 EXPECT_CALL(*delay(), GetDelay(_)) |
| 357 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(1))); | 311 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(1))); |
| 358 SyncShareRecords records; | 312 SyncShareTimes times; |
| 359 const ModelTypeSet model_types(BOOKMARKS); | 313 const ModelTypeSet model_types(BOOKMARKS); |
| 360 | 314 |
| 361 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_)) | |
| 362 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureFailed), | |
| 363 WithArg<1>(RecordSyncShare(&records)))) | |
| 364 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess), | |
| 365 WithArg<1>(RecordSyncShare(&records)))); | |
| 366 | |
| 367 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 315 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
| 368 | 316 |
| 369 ASSERT_EQ(0U, records.snapshots.size()); | 317 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) |
| 318 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureFailed), |
| 319 RecordSyncShare(×))); |
| 320 |
| 370 CallbackCounter counter; | 321 CallbackCounter counter; |
| 371 ConfigurationParams params( | 322 ConfigurationParams params( |
| 372 GetUpdatesCallerInfo::RECONFIGURATION, | 323 GetUpdatesCallerInfo::RECONFIGURATION, |
| 373 model_types, | 324 model_types, |
| 374 TypesToRoutingInfo(model_types), | 325 TypesToRoutingInfo(model_types), |
| 375 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); | 326 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); |
| 376 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params)); | 327 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params)); |
| 377 ASSERT_EQ(0, counter.times_called()); | 328 ASSERT_EQ(0, counter.times_called()); |
| 378 | 329 |
| 379 ASSERT_EQ(1U, records.snapshots.size()); | 330 Mock::VerifyAndClearExpectations(syncer()); |
| 331 |
| 332 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) |
| 333 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess), |
| 334 RecordSyncShare(×))); |
| 380 RunLoop(); | 335 RunLoop(); |
| 381 | 336 |
| 382 ASSERT_EQ(2U, records.snapshots.size()); | |
| 383 ASSERT_EQ(1, counter.times_called()); | 337 ASSERT_EQ(1, counter.times_called()); |
| 384 EXPECT_TRUE(ModelTypeSetMatchesInvalidationMap( | |
| 385 model_types, | |
| 386 records.snapshots[1].source().types)); | |
| 387 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, | |
| 388 records.snapshots[1].source().updates_source); | |
| 389 } | 338 } |
| 390 | 339 |
| 391 // Issue a nudge when the config has failed. Make sure both the config and | 340 // Issue a nudge when the config has failed. Make sure both the config and |
| 392 // nudge are executed. | 341 // nudge are executed. |
| 393 TEST_F(SyncSchedulerTest, NudgeWithConfigWithBackingOff) { | 342 TEST_F(SyncSchedulerTest, NudgeWithConfigWithBackingOff) { |
| 394 const ModelTypeSet model_types(BOOKMARKS); | 343 const ModelTypeSet model_types(BOOKMARKS); |
| 395 UseMockDelayProvider(); | 344 UseMockDelayProvider(); |
| 396 EXPECT_CALL(*delay(), GetDelay(_)) | 345 EXPECT_CALL(*delay(), GetDelay(_)) |
| 397 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(50))); | 346 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(50))); |
| 398 SyncShareRecords records; | 347 SyncShareTimes times; |
| 399 | |
| 400 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_)) | |
| 401 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureFailed), | |
| 402 WithArg<1>(RecordSyncShare(&records)))) | |
| 403 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureFailed), | |
| 404 WithArg<1>(RecordSyncShare(&records)))) | |
| 405 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess), | |
| 406 WithArg<1>(RecordSyncShare(&records)))); | |
| 407 | |
| 408 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | |
| 409 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | |
| 410 WithArg<2>(RecordSyncShare(&records)))); | |
| 411 | 348 |
| 412 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 349 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
| 413 | 350 |
| 414 ASSERT_EQ(0U, records.snapshots.size()); | 351 // Request a configure and make sure it fails. |
| 352 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) |
| 353 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureFailed), |
| 354 RecordSyncShare(×))); |
| 415 CallbackCounter counter; | 355 CallbackCounter counter; |
| 416 ConfigurationParams params( | 356 ConfigurationParams params( |
| 417 GetUpdatesCallerInfo::RECONFIGURATION, | 357 GetUpdatesCallerInfo::RECONFIGURATION, |
| 418 model_types, | 358 model_types, |
| 419 TypesToRoutingInfo(model_types), | 359 TypesToRoutingInfo(model_types), |
| 420 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); | 360 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); |
| 421 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params)); | 361 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params)); |
| 422 ASSERT_EQ(0, counter.times_called()); | 362 ASSERT_EQ(0, counter.times_called()); |
| 423 ASSERT_EQ(1U, records.snapshots.size()); | 363 Mock::VerifyAndClearExpectations(syncer()); |
| 424 | 364 |
| 365 // Ask for a nudge while dealing with repeated configure failure. |
| 366 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) |
| 367 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureFailed), |
| 368 RecordSyncShare(×))); |
| 425 scheduler()->ScheduleLocalNudge(zero(), model_types, FROM_HERE); | 369 scheduler()->ScheduleLocalNudge(zero(), model_types, FROM_HERE); |
| 426 RunLoop(); | 370 RunLoop(); |
| 427 // Note that we're not RunLoop()ing for the NUDGE we just scheduled, but | 371 // 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 | 372 // for the first retry attempt from the config job (after |
| 429 // waiting ~+/- 50ms). | 373 // waiting ~+/- 50ms). |
| 430 ASSERT_EQ(2U, records.snapshots.size()); | 374 Mock::VerifyAndClearExpectations(syncer()); |
| 431 ASSERT_EQ(0, counter.times_called()); | 375 ASSERT_EQ(0, counter.times_called()); |
| 432 EXPECT_EQ(GetUpdatesCallerInfo::RECONFIGURATION, | |
| 433 records.snapshots[1].source().updates_source); | |
| 434 | 376 |
| 377 // Let the next configure retry succeed. |
| 378 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) |
| 379 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess), |
| 380 RecordSyncShare(×))); |
| 435 RunLoop(); | 381 RunLoop(); |
| 436 // This is the 3rd attempt, which we've set up to SimulateSuccess. | |
| 437 ASSERT_EQ(3U, records.snapshots.size()); | |
| 438 ASSERT_EQ(1, counter.times_called()); | |
| 439 | 382 |
| 440 // Now change the mode so nudge can execute. | 383 // Now change the mode so nudge can execute. |
| 384 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
| 385 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), |
| 386 RecordSyncShare(×))); |
| 441 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 387 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
| 442 | |
| 443 ASSERT_EQ(4U, records.snapshots.size()); | |
| 444 | |
| 445 EXPECT_TRUE(ModelTypeSetMatchesInvalidationMap( | |
| 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 } | 388 } |
| 458 | 389 |
| 459 // Test that nudges are coalesced. | 390 // Test that nudges are coalesced. |
| 460 TEST_F(SyncSchedulerTest, NudgeCoalescing) { | 391 TEST_F(SyncSchedulerTest, NudgeCoalescing) { |
| 461 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 392 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
| 462 | 393 |
| 463 SyncShareRecords r; | 394 SyncShareTimes times; |
| 464 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 395 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
| 465 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 396 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), |
| 466 WithArg<2>(RecordSyncShare(&r)))); | 397 RecordSyncShare(×))); |
| 467 const ModelTypeSet types1(BOOKMARKS), types2(AUTOFILL), types3(THEMES); | 398 const ModelTypeSet types1(BOOKMARKS), types2(AUTOFILL), types3(THEMES); |
| 468 TimeDelta delay = zero(); | 399 TimeDelta delay = zero(); |
| 469 TimeTicks optimal_time = TimeTicks::Now() + delay; | 400 TimeTicks optimal_time = TimeTicks::Now() + delay; |
| 470 scheduler()->ScheduleLocalNudge(delay, types1, FROM_HERE); | 401 scheduler()->ScheduleLocalNudge(delay, types1, FROM_HERE); |
| 471 scheduler()->ScheduleLocalNudge(zero(), types2, FROM_HERE); | 402 scheduler()->ScheduleLocalNudge(zero(), types2, FROM_HERE); |
| 472 RunLoop(); | 403 RunLoop(); |
| 473 | 404 |
| 474 ASSERT_EQ(1U, r.snapshots.size()); | 405 ASSERT_EQ(1U, times.size()); |
| 475 EXPECT_GE(r.times[0], optimal_time); | 406 EXPECT_GE(times[0], optimal_time); |
| 476 EXPECT_TRUE(ModelTypeSetMatchesInvalidationMap( | |
| 477 Union(types1, types2), | |
| 478 r.snapshots[0].source().types)); | |
| 479 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, | |
| 480 r.snapshots[0].source().updates_source); | |
| 481 | 407 |
| 482 Mock::VerifyAndClearExpectations(syncer()); | 408 Mock::VerifyAndClearExpectations(syncer()); |
| 483 | 409 |
| 484 SyncShareRecords r2; | 410 SyncShareTimes times2; |
| 485 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 411 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
| 486 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 412 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), |
| 487 WithArg<2>(RecordSyncShare(&r2)))); | 413 RecordSyncShare(×2))); |
| 488 scheduler()->ScheduleLocalNudge(zero(), types3, FROM_HERE); | 414 scheduler()->ScheduleLocalNudge(zero(), types3, FROM_HERE); |
| 489 RunLoop(); | 415 RunLoop(); |
| 490 | |
| 491 ASSERT_EQ(1U, r2.snapshots.size()); | |
| 492 EXPECT_TRUE(ModelTypeSetMatchesInvalidationMap( | |
| 493 types3, | |
| 494 r2.snapshots[0].source().types)); | |
| 495 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, | |
| 496 r2.snapshots[0].source().updates_source); | |
| 497 } | 416 } |
| 498 | 417 |
| 499 // Test that nudges are coalesced. | 418 // Test that nudges are coalesced. |
| 500 TEST_F(SyncSchedulerTest, NudgeCoalescingWithDifferentTimings) { | 419 TEST_F(SyncSchedulerTest, NudgeCoalescingWithDifferentTimings) { |
| 501 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 420 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
| 502 | 421 |
| 503 SyncShareRecords r; | 422 SyncShareTimes times; |
| 504 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 423 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
| 505 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 424 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), |
| 506 WithArg<2>(RecordSyncShare(&r)))); | 425 RecordSyncShare(×))); |
| 507 ModelTypeSet types1(BOOKMARKS), types2(AUTOFILL), types3; | 426 ModelTypeSet types1(BOOKMARKS), types2(AUTOFILL), types3; |
| 508 | 427 |
| 509 // Create a huge time delay. | 428 // Create a huge time delay. |
| 510 TimeDelta delay = TimeDelta::FromDays(1); | 429 TimeDelta delay = TimeDelta::FromDays(1); |
| 511 | 430 |
| 512 scheduler()->ScheduleLocalNudge(delay, types1, FROM_HERE); | 431 scheduler()->ScheduleLocalNudge(delay, types1, FROM_HERE); |
| 513 scheduler()->ScheduleLocalNudge(zero(), types2, FROM_HERE); | 432 scheduler()->ScheduleLocalNudge(zero(), types2, FROM_HERE); |
| 514 | 433 |
| 515 TimeTicks min_time = TimeTicks::Now(); | 434 TimeTicks min_time = TimeTicks::Now(); |
| 516 TimeTicks max_time = TimeTicks::Now() + delay; | 435 TimeTicks max_time = TimeTicks::Now() + delay; |
| 517 | 436 |
| 518 RunLoop(); | 437 RunLoop(); |
| 519 | 438 Mock::VerifyAndClearExpectations(syncer()); |
| 520 // Make sure the sync has happened. | |
| 521 ASSERT_EQ(1U, r.snapshots.size()); | |
| 522 EXPECT_TRUE(ModelTypeSetMatchesInvalidationMap( | |
| 523 Union(types1, types2), | |
| 524 r.snapshots[0].source().types)); | |
| 525 | 439 |
| 526 // Make sure the sync happened at the right time. | 440 // Make sure the sync happened at the right time. |
| 527 EXPECT_GE(r.times[0], min_time); | 441 ASSERT_EQ(1U, times.size()); |
| 528 EXPECT_LE(r.times[0], max_time); | 442 EXPECT_GE(times[0], min_time); |
| 443 EXPECT_LE(times[0], max_time); |
| 529 } | 444 } |
| 530 | 445 |
| 531 // Test nudge scheduling. | 446 // Test nudge scheduling. |
| 532 TEST_F(SyncSchedulerTest, NudgeWithStates) { | 447 TEST_F(SyncSchedulerTest, NudgeWithStates) { |
| 533 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 448 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
| 534 | 449 |
| 535 SyncShareRecords records; | 450 SyncShareTimes times; |
| 536 const ModelTypeSet types(BOOKMARKS); | 451 const ModelTypeSet types(BOOKMARKS); |
| 537 ModelTypeInvalidationMap invalidation_map = | 452 ModelTypeInvalidationMap invalidation_map = |
| 538 ModelTypeSetToInvalidationMap(types, "test"); | 453 ModelTypeSetToInvalidationMap(types, "test"); |
| 539 | 454 |
| 540 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 455 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
| 541 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 456 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), |
| 542 WithArg<2>(RecordSyncShare(&records)))) | 457 RecordSyncShare(×))) |
| 543 .RetiresOnSaturation(); | 458 .RetiresOnSaturation(); |
| 544 scheduler()->ScheduleInvalidationNudge(zero(), invalidation_map, FROM_HERE); | 459 scheduler()->ScheduleInvalidationNudge(zero(), invalidation_map, FROM_HERE); |
| 545 RunLoop(); | 460 RunLoop(); |
| 546 | 461 |
| 547 ASSERT_EQ(1U, records.snapshots.size()); | |
| 548 EXPECT_THAT(invalidation_map, Eq(records.snapshots[0].source().types)); | |
| 549 EXPECT_EQ(GetUpdatesCallerInfo::NOTIFICATION, | |
| 550 records.snapshots[0].source().updates_source); | |
| 551 | |
| 552 Mock::VerifyAndClearExpectations(syncer()); | 462 Mock::VerifyAndClearExpectations(syncer()); |
| 553 | 463 |
| 554 // Make sure a second, later, nudge is unaffected by first (no coalescing). | 464 // Make sure a second, later, nudge is unaffected by first (no coalescing). |
| 555 SyncShareRecords records2; | 465 SyncShareTimes times2; |
| 556 invalidation_map.erase(BOOKMARKS); | 466 invalidation_map.erase(BOOKMARKS); |
| 557 invalidation_map[AUTOFILL].payload = "test2"; | 467 invalidation_map[AUTOFILL].payload = "test2"; |
| 558 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 468 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
| 559 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 469 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), |
| 560 WithArg<2>(RecordSyncShare(&records2)))); | 470 RecordSyncShare(×2))); |
| 561 scheduler()->ScheduleInvalidationNudge(zero(), invalidation_map, FROM_HERE); | 471 scheduler()->ScheduleInvalidationNudge(zero(), invalidation_map, FROM_HERE); |
| 562 RunLoop(); | 472 RunLoop(); |
| 563 | |
| 564 ASSERT_EQ(1U, records2.snapshots.size()); | |
| 565 EXPECT_THAT(invalidation_map, Eq(records2.snapshots[0].source().types)); | |
| 566 EXPECT_EQ(GetUpdatesCallerInfo::NOTIFICATION, | |
| 567 records2.snapshots[0].source().updates_source); | |
| 568 } | 473 } |
| 569 | 474 |
| 570 // Test that polling works as expected. | 475 // Test that polling works as expected. |
| 571 TEST_F(SyncSchedulerTest, Polling) { | 476 TEST_F(SyncSchedulerTest, Polling) { |
| 572 SyncShareRecords records; | 477 SyncShareTimes times; |
| 573 TimeDelta poll_interval(TimeDelta::FromMilliseconds(30)); | 478 TimeDelta poll_interval(TimeDelta::FromMilliseconds(30)); |
| 574 EXPECT_CALL(*syncer(), PollSyncShare(_,_)).Times(AtLeast(kMinNumSamples)) | 479 EXPECT_CALL(*syncer(), PollSyncShare(_,_)).Times(AtLeast(kMinNumSamples)) |
| 575 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulatePollSuccess), | 480 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulatePollSuccess), |
| 576 WithArg<1>(RecordSyncShareMultiple(&records, kMinNumSamples)))); | 481 RecordSyncShareMultiple(×, kMinNumSamples))); |
| 577 | 482 |
| 578 scheduler()->OnReceivedLongPollIntervalUpdate(poll_interval); | 483 scheduler()->OnReceivedLongPollIntervalUpdate(poll_interval); |
| 579 | 484 |
| 580 TimeTicks optimal_start = TimeTicks::Now() + poll_interval; | 485 TimeTicks optimal_start = TimeTicks::Now() + poll_interval; |
| 581 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 486 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
| 582 | 487 |
| 583 // Run again to wait for polling. | 488 // Run again to wait for polling. |
| 584 RunLoop(); | 489 RunLoop(); |
| 585 | 490 |
| 586 StopSyncScheduler(); | 491 StopSyncScheduler(); |
| 587 AnalyzePollRun(records, kMinNumSamples, optimal_start, poll_interval); | 492 AnalyzePollRun(times, kMinNumSamples, optimal_start, poll_interval); |
| 588 } | 493 } |
| 589 | 494 |
| 590 // Test that the short poll interval is used. | 495 // Test that the short poll interval is used. |
| 591 TEST_F(SyncSchedulerTest, PollNotificationsDisabled) { | 496 TEST_F(SyncSchedulerTest, PollNotificationsDisabled) { |
| 592 SyncShareRecords records; | 497 SyncShareTimes times; |
| 593 TimeDelta poll_interval(TimeDelta::FromMilliseconds(30)); | 498 TimeDelta poll_interval(TimeDelta::FromMilliseconds(30)); |
| 594 EXPECT_CALL(*syncer(), PollSyncShare(_,_)).Times(AtLeast(kMinNumSamples)) | 499 EXPECT_CALL(*syncer(), PollSyncShare(_,_)).Times(AtLeast(kMinNumSamples)) |
| 595 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulatePollSuccess), | 500 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulatePollSuccess), |
| 596 WithArg<1>(RecordSyncShareMultiple(&records, kMinNumSamples)))); | 501 RecordSyncShareMultiple(×, kMinNumSamples))); |
| 597 | 502 |
| 598 scheduler()->OnReceivedShortPollIntervalUpdate(poll_interval); | 503 scheduler()->OnReceivedShortPollIntervalUpdate(poll_interval); |
| 599 scheduler()->SetNotificationsEnabled(false); | 504 scheduler()->SetNotificationsEnabled(false); |
| 600 | 505 |
| 601 TimeTicks optimal_start = TimeTicks::Now() + poll_interval; | 506 TimeTicks optimal_start = TimeTicks::Now() + poll_interval; |
| 602 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 507 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
| 603 | 508 |
| 604 // Run again to wait for polling. | 509 // Run again to wait for polling. |
| 605 RunLoop(); | 510 RunLoop(); |
| 606 | 511 |
| 607 StopSyncScheduler(); | 512 StopSyncScheduler(); |
| 608 AnalyzePollRun(records, kMinNumSamples, optimal_start, poll_interval); | 513 AnalyzePollRun(times, kMinNumSamples, optimal_start, poll_interval); |
| 609 } | 514 } |
| 610 | 515 |
| 611 // Test that polling intervals are updated when needed. | 516 // Test that polling intervals are updated when needed. |
| 612 TEST_F(SyncSchedulerTest, PollIntervalUpdate) { | 517 TEST_F(SyncSchedulerTest, PollIntervalUpdate) { |
| 613 SyncShareRecords records; | 518 SyncShareTimes times; |
| 614 TimeDelta poll1(TimeDelta::FromMilliseconds(120)); | 519 TimeDelta poll1(TimeDelta::FromMilliseconds(120)); |
| 615 TimeDelta poll2(TimeDelta::FromMilliseconds(30)); | 520 TimeDelta poll2(TimeDelta::FromMilliseconds(30)); |
| 616 scheduler()->OnReceivedLongPollIntervalUpdate(poll1); | 521 scheduler()->OnReceivedLongPollIntervalUpdate(poll1); |
| 617 EXPECT_CALL(*syncer(), PollSyncShare(_,_)).Times(AtLeast(kMinNumSamples)) | 522 EXPECT_CALL(*syncer(), PollSyncShare(_,_)).Times(AtLeast(kMinNumSamples)) |
| 618 .WillOnce(DoAll( | 523 .WillOnce(DoAll( |
| 619 WithArgs<0,1>( | 524 WithArgs<0,1>( |
| 620 sessions::test_util::SimulatePollIntervalUpdate(poll2)), | 525 sessions::test_util::SimulatePollIntervalUpdate(poll2)), |
| 621 Return(true))) | 526 Return(true))) |
| 622 .WillRepeatedly( | 527 .WillRepeatedly( |
| 623 DoAll(Invoke(sessions::test_util::SimulatePollSuccess), | 528 DoAll(Invoke(sessions::test_util::SimulatePollSuccess), |
| 624 WithArg<1>( | 529 WithArg<1>( |
| 625 RecordSyncShareMultiple(&records, kMinNumSamples)))); | 530 RecordSyncShareMultiple(×, kMinNumSamples)))); |
| 626 | 531 |
| 627 TimeTicks optimal_start = TimeTicks::Now() + poll1 + poll2; | 532 TimeTicks optimal_start = TimeTicks::Now() + poll1 + poll2; |
| 628 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 533 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
| 629 | 534 |
| 630 // Run again to wait for polling. | 535 // Run again to wait for polling. |
| 631 RunLoop(); | 536 RunLoop(); |
| 632 | 537 |
| 633 StopSyncScheduler(); | 538 StopSyncScheduler(); |
| 634 AnalyzePollRun(records, kMinNumSamples, optimal_start, poll2); | 539 AnalyzePollRun(times, kMinNumSamples, optimal_start, poll2); |
| 635 } | 540 } |
| 636 | 541 |
| 637 // Test that the sessions commit delay is updated when needed. | 542 // Test that the sessions commit delay is updated when needed. |
| 638 TEST_F(SyncSchedulerTest, SessionsCommitDelay) { | 543 TEST_F(SyncSchedulerTest, SessionsCommitDelay) { |
| 639 SyncShareRecords records; | 544 SyncShareTimes times; |
| 640 TimeDelta delay1(TimeDelta::FromMilliseconds(120)); | 545 TimeDelta delay1(TimeDelta::FromMilliseconds(120)); |
| 641 TimeDelta delay2(TimeDelta::FromMilliseconds(30)); | 546 TimeDelta delay2(TimeDelta::FromMilliseconds(30)); |
| 642 scheduler()->OnReceivedSessionsCommitDelay(delay1); | 547 scheduler()->OnReceivedSessionsCommitDelay(delay1); |
| 643 | 548 |
| 644 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 549 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
| 645 .WillOnce( | 550 .WillOnce( |
| 646 DoAll( | 551 DoAll( |
| 647 WithArgs<0,1,2>( | 552 WithArgs<0,1,2>( |
| 648 sessions::test_util::SimulateSessionsCommitDelayUpdate( | 553 sessions::test_util::SimulateSessionsCommitDelayUpdate( |
| 649 delay2)), | 554 delay2)), |
| (...skipping 12 matching lines...) Expand all Loading... |
| 662 StopSyncScheduler(); | 567 StopSyncScheduler(); |
| 663 } | 568 } |
| 664 | 569 |
| 665 // Test that no syncing occurs when throttled. | 570 // Test that no syncing occurs when throttled. |
| 666 TEST_F(SyncSchedulerTest, ThrottlingDoesThrottle) { | 571 TEST_F(SyncSchedulerTest, ThrottlingDoesThrottle) { |
| 667 const ModelTypeSet types(BOOKMARKS); | 572 const ModelTypeSet types(BOOKMARKS); |
| 668 TimeDelta poll(TimeDelta::FromMilliseconds(5)); | 573 TimeDelta poll(TimeDelta::FromMilliseconds(5)); |
| 669 TimeDelta throttle(TimeDelta::FromMinutes(10)); | 574 TimeDelta throttle(TimeDelta::FromMinutes(10)); |
| 670 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 575 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
| 671 | 576 |
| 672 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_)) | 577 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) |
| 673 .WillOnce(DoAll( | 578 .WillOnce(DoAll( |
| 674 WithArg<1>(sessions::test_util::SimulateThrottled(throttle)), | 579 WithArg<2>(sessions::test_util::SimulateThrottled(throttle)), |
| 675 Return(true))) | 580 Return(true))) |
| 676 .WillRepeatedly(AddFailureAndQuitLoopNow()); | 581 .WillRepeatedly(AddFailureAndQuitLoopNow()); |
| 677 | 582 |
| 678 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 583 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
| 679 | 584 |
| 680 scheduler()->ScheduleLocalNudge( | 585 scheduler()->ScheduleLocalNudge( |
| 681 TimeDelta::FromMicroseconds(1), types, FROM_HERE); | 586 TimeDelta::FromMicroseconds(1), types, FROM_HERE); |
| 682 PumpLoop(); | 587 PumpLoop(); |
| 683 | 588 |
| 684 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 589 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
| 685 | 590 |
| 686 CallbackCounter counter; | 591 CallbackCounter counter; |
| 687 ConfigurationParams params( | 592 ConfigurationParams params( |
| 688 GetUpdatesCallerInfo::RECONFIGURATION, | 593 GetUpdatesCallerInfo::RECONFIGURATION, |
| 689 types, | 594 types, |
| 690 TypesToRoutingInfo(types), | 595 TypesToRoutingInfo(types), |
| 691 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); | 596 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); |
| 692 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params)); | 597 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params)); |
| 693 ASSERT_EQ(0, counter.times_called()); | 598 ASSERT_EQ(0, counter.times_called()); |
| 694 } | 599 } |
| 695 | 600 |
| 696 TEST_F(SyncSchedulerTest, ThrottlingExpiresFromPoll) { | 601 TEST_F(SyncSchedulerTest, ThrottlingExpiresFromPoll) { |
| 697 SyncShareRecords records; | 602 SyncShareTimes times; |
| 698 TimeDelta poll(TimeDelta::FromMilliseconds(15)); | 603 TimeDelta poll(TimeDelta::FromMilliseconds(15)); |
| 699 TimeDelta throttle1(TimeDelta::FromMilliseconds(150)); | 604 TimeDelta throttle1(TimeDelta::FromMilliseconds(150)); |
| 700 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 605 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
| 701 | 606 |
| 702 ::testing::InSequence seq; | 607 ::testing::InSequence seq; |
| 703 EXPECT_CALL(*syncer(), PollSyncShare(_,_)) | 608 EXPECT_CALL(*syncer(), PollSyncShare(_,_)) |
| 704 .WillOnce(DoAll( | 609 .WillOnce(DoAll( |
| 705 WithArg<1>(sessions::test_util::SimulateThrottled(throttle1)), | 610 WithArg<1>(sessions::test_util::SimulateThrottled(throttle1)), |
| 706 Return(true))) | 611 Return(true))) |
| 707 .RetiresOnSaturation(); | 612 .RetiresOnSaturation(); |
| 708 EXPECT_CALL(*syncer(), PollSyncShare(_,_)) | 613 EXPECT_CALL(*syncer(), PollSyncShare(_,_)) |
| 709 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulatePollSuccess), | 614 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulatePollSuccess), |
| 710 WithArg<1>(RecordSyncShareMultiple(&records, kMinNumSamples)))); | 615 RecordSyncShareMultiple(×, kMinNumSamples))); |
| 711 | 616 |
| 712 TimeTicks optimal_start = TimeTicks::Now() + poll + throttle1; | 617 TimeTicks optimal_start = TimeTicks::Now() + poll + throttle1; |
| 713 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 618 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
| 714 | 619 |
| 715 // Run again to wait for polling. | 620 // Run again to wait for polling. |
| 716 RunLoop(); | 621 RunLoop(); |
| 717 | 622 |
| 718 StopSyncScheduler(); | 623 StopSyncScheduler(); |
| 719 AnalyzePollRun(records, kMinNumSamples, optimal_start, poll); | 624 AnalyzePollRun(times, kMinNumSamples, optimal_start, poll); |
| 720 } | 625 } |
| 721 | 626 |
| 722 TEST_F(SyncSchedulerTest, ThrottlingExpiresFromNudge) { | 627 TEST_F(SyncSchedulerTest, ThrottlingExpiresFromNudge) { |
| 723 SyncShareRecords records; | 628 SyncShareTimes times; |
| 724 TimeDelta poll(TimeDelta::FromDays(1)); | 629 TimeDelta poll(TimeDelta::FromDays(1)); |
| 725 TimeDelta throttle1(TimeDelta::FromMilliseconds(150)); | 630 TimeDelta throttle1(TimeDelta::FromMilliseconds(150)); |
| 726 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 631 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
| 727 | 632 |
| 728 ::testing::InSequence seq; | 633 ::testing::InSequence seq; |
| 729 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 634 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
| 730 .WillOnce(DoAll( | 635 .WillOnce(DoAll( |
| 731 WithArg<2>(sessions::test_util::SimulateThrottled(throttle1)), | 636 WithArg<2>(sessions::test_util::SimulateThrottled(throttle1)), |
| 732 Return(true))) | 637 Return(true))) |
| 733 .RetiresOnSaturation(); | 638 .RetiresOnSaturation(); |
| 734 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 639 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
| 735 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 640 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), |
| 736 QuitLoopNowAction())); | 641 QuitLoopNowAction())); |
| 737 | 642 |
| 738 const ModelTypeSet types(BOOKMARKS); | 643 const ModelTypeSet types(BOOKMARKS); |
| 739 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 644 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
| 740 scheduler()->ScheduleLocalNudge(zero(), types, FROM_HERE); | 645 scheduler()->ScheduleLocalNudge(zero(), types, FROM_HERE); |
| 741 | 646 |
| 742 PumpLoop(); | 647 PumpLoop(); |
| 743 EXPECT_TRUE(scheduler()->IsCurrentlyThrottled()); | 648 EXPECT_TRUE(scheduler()->IsCurrentlyThrottled()); |
| 744 RunLoop(); | 649 RunLoop(); |
| 745 EXPECT_FALSE(scheduler()->IsCurrentlyThrottled()); | 650 EXPECT_FALSE(scheduler()->IsCurrentlyThrottled()); |
| 746 | 651 |
| 747 StopSyncScheduler(); | 652 StopSyncScheduler(); |
| 748 } | 653 } |
| 749 | 654 |
| 750 TEST_F(SyncSchedulerTest, ThrottlingExpiresFromConfigure) { | 655 TEST_F(SyncSchedulerTest, ThrottlingExpiresFromConfigure) { |
| 751 SyncShareRecords records; | 656 SyncShareTimes times; |
| 752 TimeDelta poll(TimeDelta::FromDays(1)); | 657 TimeDelta poll(TimeDelta::FromDays(1)); |
| 753 TimeDelta throttle1(TimeDelta::FromMilliseconds(150)); | 658 TimeDelta throttle1(TimeDelta::FromMilliseconds(150)); |
| 754 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 659 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
| 755 | 660 |
| 756 ::testing::InSequence seq; | 661 ::testing::InSequence seq; |
| 757 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_)) | 662 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) |
| 758 .WillOnce(DoAll( | 663 .WillOnce(DoAll( |
| 759 WithArg<1>(sessions::test_util::SimulateThrottled(throttle1)), | 664 WithArg<2>(sessions::test_util::SimulateThrottled(throttle1)), |
| 760 Return(true))) | 665 Return(true))) |
| 761 .RetiresOnSaturation(); | 666 .RetiresOnSaturation(); |
| 762 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_)) | 667 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) |
| 763 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess), | 668 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess), |
| 764 QuitLoopNowAction())); | 669 QuitLoopNowAction())); |
| 765 | 670 |
| 766 const ModelTypeSet types(BOOKMARKS); | 671 const ModelTypeSet types(BOOKMARKS); |
| 767 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 672 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
| 768 | 673 |
| 769 CallbackCounter counter; | 674 CallbackCounter counter; |
| 770 ConfigurationParams params( | 675 ConfigurationParams params( |
| 771 GetUpdatesCallerInfo::RECONFIGURATION, | 676 GetUpdatesCallerInfo::RECONFIGURATION, |
| 772 types, | 677 types, |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 811 PumpLoop(); | 716 PumpLoop(); |
| 812 | 717 |
| 813 StopSyncScheduler(); | 718 StopSyncScheduler(); |
| 814 } | 719 } |
| 815 | 720 |
| 816 TEST_F(SyncSchedulerTest, TypeThrottlingDoesBlockOtherSources) { | 721 TEST_F(SyncSchedulerTest, TypeThrottlingDoesBlockOtherSources) { |
| 817 UseMockDelayProvider(); | 722 UseMockDelayProvider(); |
| 818 EXPECT_CALL(*delay(), GetDelay(_)) | 723 EXPECT_CALL(*delay(), GetDelay(_)) |
| 819 .WillRepeatedly(Return(zero())); | 724 .WillRepeatedly(Return(zero())); |
| 820 | 725 |
| 821 SyncShareRecords records; | 726 SyncShareTimes times; |
| 822 TimeDelta poll(TimeDelta::FromDays(1)); | 727 TimeDelta poll(TimeDelta::FromDays(1)); |
| 823 TimeDelta throttle1(TimeDelta::FromSeconds(60)); | 728 TimeDelta throttle1(TimeDelta::FromSeconds(60)); |
| 824 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 729 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
| 825 | 730 |
| 826 const ModelTypeSet throttled_types(BOOKMARKS); | 731 const ModelTypeSet throttled_types(BOOKMARKS); |
| 827 const ModelTypeSet unthrottled_types(PREFERENCES); | 732 const ModelTypeSet unthrottled_types(PREFERENCES); |
| 828 | 733 |
| 829 ::testing::InSequence seq; | 734 ::testing::InSequence seq; |
| 830 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 735 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
| 831 .WillOnce(DoAll( | 736 .WillOnce(DoAll( |
| 832 WithArg<2>( | 737 WithArg<2>( |
| 833 sessions::test_util::SimulateTypesThrottled( | 738 sessions::test_util::SimulateTypesThrottled( |
| 834 throttled_types, throttle1)), | 739 throttled_types, throttle1)), |
| 835 Return(true))) | 740 Return(true))) |
| 836 .RetiresOnSaturation(); | 741 .RetiresOnSaturation(); |
| 837 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | |
| 838 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | |
| 839 WithArg<2>(RecordSyncShare(&records)))); | |
| 840 | 742 |
| 841 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 743 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
| 842 scheduler()->ScheduleLocalNudge(zero(), throttled_types, FROM_HERE); | 744 scheduler()->ScheduleLocalNudge(zero(), throttled_types, FROM_HERE); |
| 843 PumpLoop(); | 745 PumpLoop(); |
| 844 EXPECT_EQ(0U, records.snapshots.size()); | |
| 845 EXPECT_TRUE(GetThrottledTypes().HasAll(throttled_types)); | 746 EXPECT_TRUE(GetThrottledTypes().HasAll(throttled_types)); |
| 846 | 747 |
| 847 // Ignore invalidations for throttled types. | 748 // Ignore invalidations for throttled types. |
| 848 ModelTypeInvalidationMap invalidation_map = | 749 ModelTypeInvalidationMap invalidation_map = |
| 849 ModelTypeSetToInvalidationMap(throttled_types, "test"); | 750 ModelTypeSetToInvalidationMap(throttled_types, "test"); |
| 850 scheduler()->ScheduleInvalidationNudge(zero(), invalidation_map, FROM_HERE); | 751 scheduler()->ScheduleInvalidationNudge(zero(), invalidation_map, FROM_HERE); |
| 851 PumpLoop(); | 752 PumpLoop(); |
| 852 EXPECT_EQ(0U, records.snapshots.size()); | |
| 853 | 753 |
| 854 // Ignore refresh requests for throttled types. | 754 // Ignore refresh requests for throttled types. |
| 855 scheduler()->ScheduleLocalRefreshRequest(zero(), throttled_types, FROM_HERE); | 755 scheduler()->ScheduleLocalRefreshRequest(zero(), throttled_types, FROM_HERE); |
| 856 PumpLoop(); | 756 PumpLoop(); |
| 857 EXPECT_EQ(0U, records.snapshots.size()); | 757 |
| 758 Mock::VerifyAndClearExpectations(syncer()); |
| 858 | 759 |
| 859 // Local nudges for non-throttled types will trigger a sync. | 760 // Local nudges for non-throttled types will trigger a sync. |
| 761 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
| 762 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), |
| 763 RecordSyncShare(×))); |
| 860 scheduler()->ScheduleLocalNudge(zero(), unthrottled_types, FROM_HERE); | 764 scheduler()->ScheduleLocalNudge(zero(), unthrottled_types, FROM_HERE); |
| 861 RunLoop(); | 765 RunLoop(); |
| 862 EXPECT_EQ(1U, records.snapshots.size()); | 766 Mock::VerifyAndClearExpectations(syncer()); |
| 863 | 767 |
| 864 StopSyncScheduler(); | 768 StopSyncScheduler(); |
| 865 } | 769 } |
| 866 | 770 |
| 867 // Test nudges / polls don't run in config mode and config tasks do. | 771 // Test nudges / polls don't run in config mode and config tasks do. |
| 868 TEST_F(SyncSchedulerTest, ConfigurationMode) { | 772 TEST_F(SyncSchedulerTest, ConfigurationMode) { |
| 869 TimeDelta poll(TimeDelta::FromMilliseconds(15)); | 773 TimeDelta poll(TimeDelta::FromMilliseconds(15)); |
| 870 SyncShareRecords records; | 774 SyncShareTimes times; |
| 871 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 775 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
| 872 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_)) | |
| 873 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess), | |
| 874 WithArg<1>(RecordSyncShare(&records)))) | |
| 875 .RetiresOnSaturation(); | |
| 876 | 776 |
| 877 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 777 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
| 878 | 778 |
| 879 const ModelTypeSet nudge_types(AUTOFILL); | 779 const ModelTypeSet nudge_types(AUTOFILL); |
| 880 scheduler()->ScheduleLocalNudge(zero(), nudge_types, FROM_HERE); | 780 scheduler()->ScheduleLocalNudge(zero(), nudge_types, FROM_HERE); |
| 881 scheduler()->ScheduleLocalNudge(zero(), nudge_types, FROM_HERE); | 781 scheduler()->ScheduleLocalNudge(zero(), nudge_types, FROM_HERE); |
| 882 | 782 |
| 883 const ModelTypeSet config_types(BOOKMARKS); | 783 const ModelTypeSet config_types(BOOKMARKS); |
| 884 | 784 |
| 785 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) |
| 786 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess), |
| 787 RecordSyncShare(×))) |
| 788 .RetiresOnSaturation(); |
| 885 CallbackCounter counter; | 789 CallbackCounter counter; |
| 886 ConfigurationParams params( | 790 ConfigurationParams params( |
| 887 GetUpdatesCallerInfo::RECONFIGURATION, | 791 GetUpdatesCallerInfo::RECONFIGURATION, |
| 888 config_types, | 792 config_types, |
| 889 TypesToRoutingInfo(config_types), | 793 TypesToRoutingInfo(config_types), |
| 890 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); | 794 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); |
| 891 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params)); | 795 ASSERT_TRUE(scheduler()->ScheduleConfiguration(params)); |
| 892 ASSERT_EQ(1, counter.times_called()); | 796 ASSERT_EQ(1, counter.times_called()); |
| 893 | 797 Mock::VerifyAndClearExpectations(syncer()); |
| 894 ASSERT_EQ(1U, records.snapshots.size()); | |
| 895 EXPECT_TRUE(ModelTypeSetMatchesInvalidationMap( | |
| 896 config_types, | |
| 897 records.snapshots[0].source().types)); | |
| 898 | 798 |
| 899 // Switch to NORMAL_MODE to ensure NUDGES were properly saved and run. | 799 // Switch to NORMAL_MODE to ensure NUDGES were properly saved and run. |
| 900 // SyncSchedulerWhiteboxTest also provides coverage for this, but much | |
| 901 // more targeted ('whitebox' style). | |
| 902 scheduler()->OnReceivedLongPollIntervalUpdate(TimeDelta::FromDays(1)); | 800 scheduler()->OnReceivedLongPollIntervalUpdate(TimeDelta::FromDays(1)); |
| 903 SyncShareRecords records2; | 801 SyncShareTimes times2; |
| 904 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 802 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
| 905 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 803 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), |
| 906 WithArg<2>(RecordSyncShare(&records2)))); | 804 RecordSyncShare(×2))); |
| 907 | 805 |
| 908 // TODO(tim): Figure out how to remove this dangerous need to reset | 806 // TODO(tim): Figure out how to remove this dangerous need to reset |
| 909 // routing info between mode switches. | 807 // routing info between mode switches. |
| 910 context()->set_routing_info(routing_info()); | 808 context()->set_routing_info(routing_info()); |
| 911 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 809 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
| 912 | 810 |
| 913 ASSERT_EQ(1U, records2.snapshots.size()); | |
| 914 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, | |
| 915 records2.snapshots[0].source().updates_source); | |
| 916 EXPECT_TRUE(ModelTypeSetMatchesInvalidationMap( | |
| 917 nudge_types, | |
| 918 records2.snapshots[0].source().types)); | |
| 919 PumpLoop(); | 811 PumpLoop(); |
| 920 } | 812 } |
| 921 | 813 |
| 922 class BackoffTriggersSyncSchedulerTest : public SyncSchedulerTest { | 814 class BackoffTriggersSyncSchedulerTest : public SyncSchedulerTest { |
| 923 virtual void SetUp() { | 815 virtual void SetUp() { |
| 924 SyncSchedulerTest::SetUp(); | 816 SyncSchedulerTest::SetUp(); |
| 925 UseMockDelayProvider(); | 817 UseMockDelayProvider(); |
| 926 EXPECT_CALL(*delay(), GetDelay(_)) | 818 EXPECT_CALL(*delay(), GetDelay(_)) |
| 927 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(1))); | 819 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(1))); |
| 928 } | 820 } |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 975 Return(true))) | 867 Return(true))) |
| 976 .WillRepeatedly(DoAll( | 868 .WillRepeatedly(DoAll( |
| 977 Invoke(sessions::test_util::SimulateDownloadUpdatesFailed), | 869 Invoke(sessions::test_util::SimulateDownloadUpdatesFailed), |
| 978 QuitLoopNowAction())); | 870 QuitLoopNowAction())); |
| 979 EXPECT_TRUE(RunAndGetBackoff()); | 871 EXPECT_TRUE(RunAndGetBackoff()); |
| 980 } | 872 } |
| 981 | 873 |
| 982 // Have the syncer fail to get the encryption key yet succeed in downloading | 874 // Have the syncer fail to get the encryption key yet succeed in downloading |
| 983 // updates. Expect this will leave the scheduler in backoff. | 875 // updates. Expect this will leave the scheduler in backoff. |
| 984 TEST_F(BackoffTriggersSyncSchedulerTest, FailGetEncryptionKey) { | 876 TEST_F(BackoffTriggersSyncSchedulerTest, FailGetEncryptionKey) { |
| 985 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_)) | 877 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) |
| 986 .WillOnce(DoAll( | 878 .WillOnce(DoAll( |
| 987 Invoke(sessions::test_util::SimulateGetEncryptionKeyFailed), | 879 Invoke(sessions::test_util::SimulateGetEncryptionKeyFailed), |
| 988 Return(true))) | 880 Return(true))) |
| 989 .WillRepeatedly(DoAll( | 881 .WillRepeatedly(DoAll( |
| 990 Invoke(sessions::test_util::SimulateGetEncryptionKeyFailed), | 882 Invoke(sessions::test_util::SimulateGetEncryptionKeyFailed), |
| 991 QuitLoopNowAction())); | 883 QuitLoopNowAction())); |
| 992 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 884 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
| 993 | 885 |
| 994 ModelTypeSet types(BOOKMARKS); | 886 ModelTypeSet types(BOOKMARKS); |
| 995 CallbackCounter counter; | 887 CallbackCounter counter; |
| 996 ConfigurationParams params( | 888 ConfigurationParams params( |
| 997 GetUpdatesCallerInfo::RECONFIGURATION, | 889 GetUpdatesCallerInfo::RECONFIGURATION, |
| 998 types, | 890 types, |
| 999 TypesToRoutingInfo(types), | 891 TypesToRoutingInfo(types), |
| 1000 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); | 892 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); |
| 1001 scheduler()->ScheduleConfiguration(params); | 893 scheduler()->ScheduleConfiguration(params); |
| 1002 RunLoop(); | 894 RunLoop(); |
| 1003 | 895 |
| 1004 EXPECT_TRUE(scheduler()->IsBackingOff()); | 896 EXPECT_TRUE(scheduler()->IsBackingOff()); |
| 1005 } | 897 } |
| 1006 | 898 |
| 1007 // Test that no polls or extraneous nudges occur when in backoff. | 899 // Test that no polls or extraneous nudges occur when in backoff. |
| 1008 TEST_F(SyncSchedulerTest, BackoffDropsJobs) { | 900 TEST_F(SyncSchedulerTest, BackoffDropsJobs) { |
| 1009 SyncShareRecords r; | 901 SyncShareTimes times; |
| 1010 TimeDelta poll(TimeDelta::FromMilliseconds(5)); | 902 TimeDelta poll(TimeDelta::FromMilliseconds(5)); |
| 1011 const ModelTypeSet types(BOOKMARKS); | 903 const ModelTypeSet types(BOOKMARKS); |
| 1012 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 904 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
| 1013 UseMockDelayProvider(); | 905 UseMockDelayProvider(); |
| 1014 | 906 |
| 1015 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | 907 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
| 1016 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), | 908 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), |
| 1017 WithArg<2>(RecordSyncShareMultiple(&r, 1U)))); | 909 RecordSyncShareMultiple(×, 1U))); |
| 1018 EXPECT_CALL(*delay(), GetDelay(_)). | 910 EXPECT_CALL(*delay(), GetDelay(_)). |
| 1019 WillRepeatedly(Return(TimeDelta::FromDays(1))); | 911 WillRepeatedly(Return(TimeDelta::FromDays(1))); |
| 1020 | 912 |
| 1021 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 913 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
| 1022 | 914 |
| 1023 // This nudge should fail and put us into backoff. Thanks to our mock | 915 // This nudge should fail and put us into backoff. Thanks to our mock |
| 1024 // GetDelay() setup above, this will be a long backoff. | 916 // GetDelay() setup above, this will be a long backoff. |
| 1025 scheduler()->ScheduleLocalNudge(zero(), types, FROM_HERE); | 917 scheduler()->ScheduleLocalNudge(zero(), types, FROM_HERE); |
| 1026 RunLoop(); | 918 RunLoop(); |
| 1027 | 919 |
| 920 // From this point forward, no SyncShare functions should be invoked. |
| 1028 Mock::VerifyAndClearExpectations(syncer()); | 921 Mock::VerifyAndClearExpectations(syncer()); |
| 1029 ASSERT_EQ(1U, r.snapshots.size()); | |
| 1030 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, | |
| 1031 r.snapshots[0].source().updates_source); | |
| 1032 | 922 |
| 1033 // Wait a while (10x poll interval) so a few poll jobs will be attempted. | 923 // Wait a while (10x poll interval) so a few poll jobs will be attempted. |
| 1034 PumpLoopFor(poll * 10); | 924 PumpLoopFor(poll * 10); |
| 1035 | 925 |
| 1036 // Try (and fail) to schedule a nudge. | 926 // Try (and fail) to schedule a nudge. |
| 1037 scheduler()->ScheduleLocalNudge( | 927 scheduler()->ScheduleLocalNudge( |
| 1038 base::TimeDelta::FromMilliseconds(1), | 928 base::TimeDelta::FromMilliseconds(1), |
| 1039 types, | 929 types, |
| 1040 FROM_HERE); | 930 FROM_HERE); |
| 1041 | 931 |
| 1042 Mock::VerifyAndClearExpectations(syncer()); | 932 Mock::VerifyAndClearExpectations(syncer()); |
| 1043 Mock::VerifyAndClearExpectations(delay()); | 933 Mock::VerifyAndClearExpectations(delay()); |
| 1044 | 934 |
| 1045 ASSERT_EQ(1U, r.snapshots.size()); | |
| 1046 | |
| 1047 EXPECT_CALL(*delay(), GetDelay(_)).Times(0); | 935 EXPECT_CALL(*delay(), GetDelay(_)).Times(0); |
| 1048 | 936 |
| 1049 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 937 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
| 1050 | 938 |
| 1051 CallbackCounter counter; | 939 CallbackCounter counter; |
| 1052 ConfigurationParams params( | 940 ConfigurationParams params( |
| 1053 GetUpdatesCallerInfo::RECONFIGURATION, | 941 GetUpdatesCallerInfo::RECONFIGURATION, |
| 1054 types, | 942 types, |
| 1055 TypesToRoutingInfo(types), | 943 TypesToRoutingInfo(types), |
| 1056 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); | 944 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); |
| 1057 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params)); | 945 ASSERT_FALSE(scheduler()->ScheduleConfiguration(params)); |
| 1058 ASSERT_EQ(0, counter.times_called()); | 946 ASSERT_EQ(0, counter.times_called()); |
| 1059 } | 947 } |
| 1060 | 948 |
| 1061 // Test that backoff is shaping traffic properly with consecutive errors. | 949 // Test that backoff is shaping traffic properly with consecutive errors. |
| 1062 TEST_F(SyncSchedulerTest, BackoffElevation) { | 950 TEST_F(SyncSchedulerTest, BackoffElevation) { |
| 1063 SyncShareRecords r; | 951 SyncShareTimes times; |
| 1064 UseMockDelayProvider(); | 952 UseMockDelayProvider(); |
| 1065 | 953 |
| 1066 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)).Times(kMinNumSamples) | 954 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)).Times(kMinNumSamples) |
| 1067 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), | 955 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), |
| 1068 WithArg<2>(RecordSyncShareMultiple(&r, kMinNumSamples)))); | 956 RecordSyncShareMultiple(×, kMinNumSamples))); |
| 1069 | 957 |
| 1070 const TimeDelta first = TimeDelta::FromSeconds(kInitialBackoffRetrySeconds); | 958 const TimeDelta first = TimeDelta::FromSeconds(kInitialBackoffRetrySeconds); |
| 1071 const TimeDelta second = TimeDelta::FromMilliseconds(2); | 959 const TimeDelta second = TimeDelta::FromMilliseconds(2); |
| 1072 const TimeDelta third = TimeDelta::FromMilliseconds(3); | 960 const TimeDelta third = TimeDelta::FromMilliseconds(3); |
| 1073 const TimeDelta fourth = TimeDelta::FromMilliseconds(4); | 961 const TimeDelta fourth = TimeDelta::FromMilliseconds(4); |
| 1074 const TimeDelta fifth = TimeDelta::FromMilliseconds(5); | 962 const TimeDelta fifth = TimeDelta::FromMilliseconds(5); |
| 1075 const TimeDelta sixth = TimeDelta::FromDays(1); | 963 const TimeDelta sixth = TimeDelta::FromDays(1); |
| 1076 | 964 |
| 1077 EXPECT_CALL(*delay(), GetDelay(first)).WillOnce(Return(second)) | 965 EXPECT_CALL(*delay(), GetDelay(first)).WillOnce(Return(second)) |
| 1078 .RetiresOnSaturation(); | 966 .RetiresOnSaturation(); |
| 1079 EXPECT_CALL(*delay(), GetDelay(second)).WillOnce(Return(third)) | 967 EXPECT_CALL(*delay(), GetDelay(second)).WillOnce(Return(third)) |
| 1080 .RetiresOnSaturation(); | 968 .RetiresOnSaturation(); |
| 1081 EXPECT_CALL(*delay(), GetDelay(third)).WillOnce(Return(fourth)) | 969 EXPECT_CALL(*delay(), GetDelay(third)).WillOnce(Return(fourth)) |
| 1082 .RetiresOnSaturation(); | 970 .RetiresOnSaturation(); |
| 1083 EXPECT_CALL(*delay(), GetDelay(fourth)).WillOnce(Return(fifth)) | 971 EXPECT_CALL(*delay(), GetDelay(fourth)).WillOnce(Return(fifth)) |
| 1084 .RetiresOnSaturation(); | 972 .RetiresOnSaturation(); |
| 1085 EXPECT_CALL(*delay(), GetDelay(fifth)).WillOnce(Return(sixth)); | 973 EXPECT_CALL(*delay(), GetDelay(fifth)).WillOnce(Return(sixth)); |
| 1086 | 974 |
| 1087 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 975 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
| 1088 | 976 |
| 1089 // Run again with a nudge. | 977 // Run again with a nudge. |
| 1090 scheduler()->ScheduleLocalNudge(zero(), ModelTypeSet(BOOKMARKS), FROM_HERE); | 978 scheduler()->ScheduleLocalNudge(zero(), ModelTypeSet(BOOKMARKS), FROM_HERE); |
| 1091 RunLoop(); | 979 RunLoop(); |
| 1092 | 980 |
| 1093 ASSERT_EQ(kMinNumSamples, r.snapshots.size()); | 981 ASSERT_EQ(kMinNumSamples, times.size()); |
| 1094 EXPECT_GE(r.times[1] - r.times[0], second); | 982 EXPECT_GE(times[1] - times[0], second); |
| 1095 EXPECT_GE(r.times[2] - r.times[1], third); | 983 EXPECT_GE(times[2] - times[1], third); |
| 1096 EXPECT_GE(r.times[3] - r.times[2], fourth); | 984 EXPECT_GE(times[3] - times[2], fourth); |
| 1097 EXPECT_GE(r.times[4] - r.times[3], fifth); | 985 EXPECT_GE(times[4] - times[3], fifth); |
| 1098 } | 986 } |
| 1099 | 987 |
| 1100 // Test that things go back to normal once a retry makes forward progress. | 988 // Test that things go back to normal once a retry makes forward progress. |
| 1101 TEST_F(SyncSchedulerTest, BackoffRelief) { | 989 TEST_F(SyncSchedulerTest, BackoffRelief) { |
| 1102 SyncShareRecords r; | 990 SyncShareTimes times; |
| 1103 const TimeDelta poll(TimeDelta::FromMilliseconds(10)); | 991 const TimeDelta poll(TimeDelta::FromMilliseconds(10)); |
| 1104 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 992 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
| 1105 UseMockDelayProvider(); | 993 UseMockDelayProvider(); |
| 1106 | 994 |
| 1107 const TimeDelta backoff = TimeDelta::FromMilliseconds(5); | 995 const TimeDelta backoff = TimeDelta::FromMilliseconds(5); |
| 1108 | |
| 1109 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) | |
| 1110 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), | |
| 1111 WithArg<2>(RecordSyncShareMultiple(&r, kMinNumSamples)))) | |
| 1112 .WillRepeatedly(DoAll( | |
| 1113 Invoke(sessions::test_util::SimulateNormalSuccess), | |
| 1114 WithArg<2>(RecordSyncShareMultiple(&r, kMinNumSamples)))); | |
| 1115 EXPECT_CALL(*syncer(), PollSyncShare(_,_)) | |
| 1116 .WillRepeatedly(DoAll( | |
| 1117 Invoke(sessions::test_util::SimulatePollSuccess), | |
| 1118 WithArg<1>(RecordSyncShareMultiple(&r, kMinNumSamples)))); | |
| 1119 EXPECT_CALL(*delay(), GetDelay(_)).WillOnce(Return(backoff)); | 996 EXPECT_CALL(*delay(), GetDelay(_)).WillOnce(Return(backoff)); |
| 1120 | 997 |
| 1121 // Optimal start for the post-backoff poll party. | 998 // Optimal start for the post-backoff poll party. |
| 1122 TimeTicks optimal_start = TimeTicks::Now(); | 999 TimeTicks optimal_start = TimeTicks::Now(); |
| 1123 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 1000 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
| 1124 | 1001 |
| 1125 // Run again to wait for polling. | 1002 // Kick off the test with a failed nudge. |
| 1003 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
| 1004 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), |
| 1005 RecordSyncShare(×))); |
| 1126 scheduler()->ScheduleLocalNudge(zero(), ModelTypeSet(BOOKMARKS), FROM_HERE); | 1006 scheduler()->ScheduleLocalNudge(zero(), ModelTypeSet(BOOKMARKS), FROM_HERE); |
| 1127 RunLoop(); | 1007 RunLoop(); |
| 1008 Mock::VerifyAndClearExpectations(syncer()); |
| 1009 TimeTicks optimal_job_time = optimal_start; |
| 1010 ASSERT_EQ(1U, times.size()); |
| 1011 EXPECT_GE(times[0], optimal_job_time); |
| 1012 |
| 1013 // The retry succeeds. |
| 1014 EXPECT_CALL(*syncer(), NormalSyncShare(_,_,_)) |
| 1015 .WillOnce(DoAll( |
| 1016 Invoke(sessions::test_util::SimulateNormalSuccess), |
| 1017 RecordSyncShare(×))); |
| 1018 RunLoop(); |
| 1019 Mock::VerifyAndClearExpectations(syncer()); |
| 1020 optimal_job_time = optimal_job_time + backoff; |
| 1021 ASSERT_EQ(2U, times.size()); |
| 1022 EXPECT_GE(times[1], optimal_job_time); |
| 1023 |
| 1024 // Now let the Poll timer do its thing. |
| 1025 EXPECT_CALL(*syncer(), PollSyncShare(_,_)) |
| 1026 .WillRepeatedly(DoAll( |
| 1027 Invoke(sessions::test_util::SimulatePollSuccess), |
| 1028 RecordSyncShareMultiple(×, kMinNumSamples))); |
| 1029 RunLoop(); |
| 1030 Mock::VerifyAndClearExpectations(syncer()); |
| 1031 ASSERT_EQ(kMinNumSamples, times.size()); |
| 1032 for (size_t i = 2; i < times.size(); i++) { |
| 1033 optimal_job_time = optimal_job_time + poll; |
| 1034 SCOPED_TRACE(testing::Message() << "SyncShare # (" << i << ")"); |
| 1035 EXPECT_GE(times[i], optimal_job_time); |
| 1036 } |
| 1128 | 1037 |
| 1129 StopSyncScheduler(); | 1038 StopSyncScheduler(); |
| 1130 | |
| 1131 EXPECT_EQ(kMinNumSamples, r.times.size()); | |
| 1132 | |
| 1133 // The first nudge ran as soon as possible. It failed. | |
| 1134 TimeTicks optimal_job_time = optimal_start; | |
| 1135 EXPECT_GE(r.times[0], optimal_job_time); | |
| 1136 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, | |
| 1137 r.snapshots[0].source().updates_source); | |
| 1138 | |
| 1139 // It was followed by a successful retry nudge shortly afterward. | |
| 1140 optimal_job_time = optimal_job_time + backoff; | |
| 1141 EXPECT_GE(r.times[1], optimal_job_time); | |
| 1142 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, | |
| 1143 r.snapshots[1].source().updates_source); | |
| 1144 // After that, we went back to polling. | |
| 1145 for (size_t i = 2; i < r.snapshots.size(); i++) { | |
| 1146 optimal_job_time = optimal_job_time + poll; | |
| 1147 SCOPED_TRACE(testing::Message() << "SyncShare # (" << i << ")"); | |
| 1148 EXPECT_GE(r.times[i], optimal_job_time); | |
| 1149 EXPECT_EQ(GetUpdatesCallerInfo::PERIODIC, | |
| 1150 r.snapshots[i].source().updates_source); | |
| 1151 } | |
| 1152 } | 1039 } |
| 1153 | 1040 |
| 1154 // Test that poll failures are ignored. They should have no effect on | 1041 // Test that poll failures are ignored. They should have no effect on |
| 1155 // subsequent poll attempts, nor should they trigger a backoff/retry. | 1042 // subsequent poll attempts, nor should they trigger a backoff/retry. |
| 1156 TEST_F(SyncSchedulerTest, TransientPollFailure) { | 1043 TEST_F(SyncSchedulerTest, TransientPollFailure) { |
| 1157 SyncShareRecords r; | 1044 SyncShareTimes times; |
| 1158 const TimeDelta poll_interval(TimeDelta::FromMilliseconds(1)); | 1045 const TimeDelta poll_interval(TimeDelta::FromMilliseconds(1)); |
| 1159 scheduler()->OnReceivedLongPollIntervalUpdate(poll_interval); | 1046 scheduler()->OnReceivedLongPollIntervalUpdate(poll_interval); |
| 1160 UseMockDelayProvider(); // Will cause test failure if backoff is initiated. | 1047 UseMockDelayProvider(); // Will cause test failure if backoff is initiated. |
| 1161 | 1048 |
| 1162 EXPECT_CALL(*syncer(), PollSyncShare(_,_)) | 1049 EXPECT_CALL(*syncer(), PollSyncShare(_,_)) |
| 1163 .WillOnce(DoAll(Invoke(sessions::test_util::SimulatePollFailed), | 1050 .WillOnce(DoAll(Invoke(sessions::test_util::SimulatePollFailed), |
| 1164 WithArg<1>(RecordSyncShare(&r)))) | 1051 RecordSyncShare(×))) |
| 1165 .WillOnce(DoAll(Invoke(sessions::test_util::SimulatePollSuccess), | 1052 .WillOnce(DoAll(Invoke(sessions::test_util::SimulatePollSuccess), |
| 1166 WithArg<1>(RecordSyncShare(&r)))); | 1053 RecordSyncShare(×))); |
| 1167 | 1054 |
| 1168 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 1055 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
| 1169 | 1056 |
| 1170 // Run the unsucessful poll. The failed poll should not trigger backoff. | 1057 // Run the unsucessful poll. The failed poll should not trigger backoff. |
| 1171 RunLoop(); | 1058 RunLoop(); |
| 1172 EXPECT_FALSE(scheduler()->IsBackingOff()); | 1059 EXPECT_FALSE(scheduler()->IsBackingOff()); |
| 1173 | 1060 |
| 1174 // Run the successful poll. | 1061 // Run the successful poll. |
| 1175 RunLoop(); | 1062 RunLoop(); |
| 1176 EXPECT_FALSE(scheduler()->IsBackingOff()); | 1063 EXPECT_FALSE(scheduler()->IsBackingOff()); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1254 scheduler()->OnConnectionStatusChange(); | 1141 scheduler()->OnConnectionStatusChange(); |
| 1255 connection()->SetServerReachable(); | 1142 connection()->SetServerReachable(); |
| 1256 connection()->UpdateConnectionStatus(); | 1143 connection()->UpdateConnectionStatus(); |
| 1257 scheduler()->ScheduleLocalNudge(zero(), ModelTypeSet(BOOKMARKS), FROM_HERE); | 1144 scheduler()->ScheduleLocalNudge(zero(), ModelTypeSet(BOOKMARKS), FROM_HERE); |
| 1258 base::MessageLoop::current()->RunUntilIdle(); | 1145 base::MessageLoop::current()->RunUntilIdle(); |
| 1259 } | 1146 } |
| 1260 | 1147 |
| 1261 // Tests that we don't crash trying to run two canaries at once if we receive | 1148 // 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. | 1149 // extra connection status change notifications. See crbug.com/190085. |
| 1263 TEST_F(SyncSchedulerTest, DoubleCanaryInConfigure) { | 1150 TEST_F(SyncSchedulerTest, DoubleCanaryInConfigure) { |
| 1264 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_)) | 1151 EXPECT_CALL(*syncer(), ConfigureSyncShare(_,_,_)) |
| 1265 .WillRepeatedly(DoAll( | 1152 .WillRepeatedly(DoAll( |
| 1266 Invoke(sessions::test_util::SimulateConfigureConnectionFailure), | 1153 Invoke(sessions::test_util::SimulateConfigureConnectionFailure), |
| 1267 Return(true))); | 1154 Return(true))); |
| 1268 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); | 1155 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); |
| 1269 connection()->SetServerNotReachable(); | 1156 connection()->SetServerNotReachable(); |
| 1270 connection()->UpdateConnectionStatus(); | 1157 connection()->UpdateConnectionStatus(); |
| 1271 | 1158 |
| 1272 ModelTypeSet model_types(BOOKMARKS); | 1159 ModelTypeSet model_types(BOOKMARKS); |
| 1273 CallbackCounter counter; | 1160 CallbackCounter counter; |
| 1274 ConfigurationParams params( | 1161 ConfigurationParams params( |
| 1275 GetUpdatesCallerInfo::RECONFIGURATION, | 1162 GetUpdatesCallerInfo::RECONFIGURATION, |
| 1276 model_types, | 1163 model_types, |
| 1277 TypesToRoutingInfo(model_types), | 1164 TypesToRoutingInfo(model_types), |
| 1278 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); | 1165 base::Bind(&CallbackCounter::Callback, base::Unretained(&counter))); |
| 1279 scheduler()->ScheduleConfiguration(params); | 1166 scheduler()->ScheduleConfiguration(params); |
| 1280 | 1167 |
| 1281 scheduler()->OnConnectionStatusChange(); | 1168 scheduler()->OnConnectionStatusChange(); |
| 1282 scheduler()->OnConnectionStatusChange(); | 1169 scheduler()->OnConnectionStatusChange(); |
| 1283 | 1170 |
| 1284 PumpLoop(); // Run the nudge, that will fail and schedule a quick retry. | 1171 PumpLoop(); // Run the nudge, that will fail and schedule a quick retry. |
| 1285 } | 1172 } |
| 1286 | 1173 |
| 1287 TEST_F(SyncSchedulerTest, PollFromCanaryAfterAuthError) { | 1174 TEST_F(SyncSchedulerTest, PollFromCanaryAfterAuthError) { |
| 1288 SyncShareRecords records; | 1175 SyncShareTimes times; |
| 1289 TimeDelta poll(TimeDelta::FromMilliseconds(15)); | 1176 TimeDelta poll(TimeDelta::FromMilliseconds(15)); |
| 1290 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 1177 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
| 1291 | 1178 |
| 1292 ::testing::InSequence seq; | 1179 ::testing::InSequence seq; |
| 1293 EXPECT_CALL(*syncer(), PollSyncShare(_,_)) | 1180 EXPECT_CALL(*syncer(), PollSyncShare(_,_)) |
| 1294 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulatePollSuccess), | 1181 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulatePollSuccess), |
| 1295 WithArg<1>(RecordSyncShareMultiple(&records, kMinNumSamples)))); | 1182 RecordSyncShareMultiple(×, kMinNumSamples))); |
| 1296 | 1183 |
| 1297 connection()->SetServerStatus(HttpResponse::SYNC_AUTH_ERROR); | 1184 connection()->SetServerStatus(HttpResponse::SYNC_AUTH_ERROR); |
| 1298 StartSyncScheduler(SyncScheduler::NORMAL_MODE); | 1185 StartSyncScheduler(SyncScheduler::NORMAL_MODE); |
| 1299 | 1186 |
| 1300 // Run to wait for polling. | 1187 // Run to wait for polling. |
| 1301 RunLoop(); | 1188 RunLoop(); |
| 1302 | 1189 |
| 1303 // Normally OnCredentialsUpdated calls TryCanaryJob that doesn't run Poll, | 1190 // Normally OnCredentialsUpdated calls TryCanaryJob that doesn't run Poll, |
| 1304 // but after poll finished with auth error from poll timer it should retry | 1191 // but after poll finished with auth error from poll timer it should retry |
| 1305 // poll once more | 1192 // poll once more |
| 1306 EXPECT_CALL(*syncer(), PollSyncShare(_,_)) | 1193 EXPECT_CALL(*syncer(), PollSyncShare(_,_)) |
| 1307 .WillOnce(DoAll(Invoke(sessions::test_util::SimulatePollSuccess), | 1194 .WillOnce(DoAll(Invoke(sessions::test_util::SimulatePollSuccess), |
| 1308 WithArg<1>(RecordSyncShare(&records)))); | 1195 RecordSyncShare(×))); |
| 1309 scheduler()->OnCredentialsUpdated(); | 1196 scheduler()->OnCredentialsUpdated(); |
| 1310 connection()->SetServerStatus(HttpResponse::SERVER_CONNECTION_OK); | 1197 connection()->SetServerStatus(HttpResponse::SERVER_CONNECTION_OK); |
| 1311 StopSyncScheduler(); | 1198 StopSyncScheduler(); |
| 1312 } | 1199 } |
| 1313 | 1200 |
| 1314 } // namespace syncer | 1201 } // namespace syncer |
| OLD | NEW |