| 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 <stddef.h> | 5 #include <stddef.h> |
| 6 #include <stdint.h> | 6 #include <stdint.h> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/location.h" | 11 #include "base/location.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
| 14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
| 15 #include "base/test/test_timeouts.h" | 15 #include "base/test/test_timeouts.h" |
| 16 #include "base/threading/thread_task_runner_handle.h" | 16 #include "base/threading/thread_task_runner_handle.h" |
| 17 #include "sync/engine/backoff_delay_provider.h" | 17 #include "components/sync/base/cancelation_signal.h" |
| 18 #include "sync/engine/sync_scheduler_impl.h" | 18 #include "components/sync/base/extensions_activity.h" |
| 19 #include "sync/engine/syncer.h" | 19 #include "components/sync/base/model_type_test_util.h" |
| 20 #include "sync/internal_api/public/base/cancelation_signal.h" | 20 #include "components/sync/engine_impl/backoff_delay_provider.h" |
| 21 #include "sync/internal_api/public/base/model_type_test_util.h" | 21 #include "components/sync/engine_impl/sync_scheduler_impl.h" |
| 22 #include "sync/sessions/test_util.h" | 22 #include "components/sync/engine_impl/syncer.h" |
| 23 #include "sync/test/callback_counter.h" | 23 #include "components/sync/sessions_impl/test_util.h" |
| 24 #include "sync/test/engine/fake_model_worker.h" | 24 #include "components/sync/test/callback_counter.h" |
| 25 #include "sync/test/engine/mock_connection_manager.h" | 25 #include "components/sync/test/engine/fake_model_worker.h" |
| 26 #include "sync/test/engine/mock_nudge_handler.h" | 26 #include "components/sync/test/engine/mock_connection_manager.h" |
| 27 #include "sync/test/engine/test_directory_setter_upper.h" | 27 #include "components/sync/test/engine/mock_nudge_handler.h" |
| 28 #include "sync/test/mock_invalidation.h" | 28 #include "components/sync/test/engine/test_directory_setter_upper.h" |
| 29 #include "sync/util/extensions_activity.h" | 29 #include "components/sync/test/mock_invalidation.h" |
| 30 #include "testing/gmock/include/gmock/gmock.h" | 30 #include "testing/gmock/include/gmock/gmock.h" |
| 31 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
| 32 | 32 |
| 33 using base::TimeDelta; | 33 using base::TimeDelta; |
| 34 using base::TimeTicks; | 34 using base::TimeTicks; |
| 35 using testing::_; | 35 using testing::_; |
| 36 using testing::AtLeast; | 36 using testing::AtLeast; |
| 37 using testing::DoAll; | 37 using testing::DoAll; |
| 38 using testing::Invoke; | 38 using testing::Invoke; |
| 39 using testing::Mock; | 39 using testing::Mock; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 54 bool(ModelTypeSet, | 54 bool(ModelTypeSet, |
| 55 sessions::NudgeTracker*, | 55 sessions::NudgeTracker*, |
| 56 sessions::SyncSession*)); | 56 sessions::SyncSession*)); |
| 57 MOCK_METHOD3(ConfigureSyncShare, | 57 MOCK_METHOD3(ConfigureSyncShare, |
| 58 bool(ModelTypeSet, | 58 bool(ModelTypeSet, |
| 59 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource, | 59 sync_pb::GetUpdatesCallerInfo::GetUpdatesSource, |
| 60 SyncSession*)); | 60 SyncSession*)); |
| 61 MOCK_METHOD2(PollSyncShare, bool(ModelTypeSet, sessions::SyncSession*)); | 61 MOCK_METHOD2(PollSyncShare, bool(ModelTypeSet, sessions::SyncSession*)); |
| 62 }; | 62 }; |
| 63 | 63 |
| 64 MockSyncer::MockSyncer() | 64 MockSyncer::MockSyncer() : Syncer(NULL) {} |
| 65 : Syncer(NULL) {} | |
| 66 | 65 |
| 67 typedef std::vector<TimeTicks> SyncShareTimes; | 66 typedef std::vector<TimeTicks> SyncShareTimes; |
| 68 | 67 |
| 69 void QuitLoopNow() { | 68 void QuitLoopNow() { |
| 70 // We use QuitNow() instead of Quit() as the latter may get stalled | 69 // We use QuitNow() instead of Quit() as the latter may get stalled |
| 71 // indefinitely in the presence of repeated timers with low delays | 70 // indefinitely in the presence of repeated timers with low delays |
| 72 // and a slow test (e.g., ThrottlingDoesThrottle [which has a poll | 71 // and a slow test (e.g., ThrottlingDoesThrottle [which has a poll |
| 73 // delay of 5ms] run under TSAN on the trybots). | 72 // delay of 5ms] run under TSAN on the trybots). |
| 74 base::MessageLoop::current()->QuitNow(); | 73 base::MessageLoop::current()->QuitNow(); |
| 75 } | 74 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 95 } | 94 } |
| 96 | 95 |
| 97 ModelSafeRoutingInfo TypesToRoutingInfo(ModelTypeSet types) { | 96 ModelSafeRoutingInfo TypesToRoutingInfo(ModelTypeSet types) { |
| 98 ModelSafeRoutingInfo routes; | 97 ModelSafeRoutingInfo routes; |
| 99 for (ModelTypeSet::Iterator iter = types.First(); iter.Good(); iter.Inc()) { | 98 for (ModelTypeSet::Iterator iter = types.First(); iter.Good(); iter.Inc()) { |
| 100 routes[iter.Get()] = GROUP_PASSIVE; | 99 routes[iter.Get()] = GROUP_PASSIVE; |
| 101 } | 100 } |
| 102 return routes; | 101 return routes; |
| 103 } | 102 } |
| 104 | 103 |
| 105 | |
| 106 static const size_t kMinNumSamples = 5; | 104 static const size_t kMinNumSamples = 5; |
| 107 | 105 |
| 108 // Test harness for the SyncScheduler. Test the delays and backoff timers used | 106 // Test harness for the SyncScheduler. Test the delays and backoff timers used |
| 109 // in response to various events. | 107 // in response to various events. |
| 110 // | 108 // |
| 111 // These tests execute in real time with real timers. We try to keep the | 109 // These tests execute in real time with real timers. We try to keep the |
| 112 // delays short, but there is a limit to how short we can make them. The | 110 // delays short, but there is a limit to how short we can make them. The |
| 113 // timers on some platforms (ie. Windows) have a timer resolution greater than | 111 // timers on some platforms (ie. Windows) have a timer resolution greater than |
| 114 // 1ms. Using 1ms delays may result in test flakiness. | 112 // 1ms. Using 1ms delays may result in test flakiness. |
| 115 // | 113 // |
| 116 // See crbug.com/402212 for more info. | 114 // See crbug.com/402212 for more info. |
| 117 class SyncSchedulerTest : public testing::Test { | 115 class SyncSchedulerTest : public testing::Test { |
| 118 public: | 116 public: |
| 119 SyncSchedulerTest() : syncer_(NULL), delay_(NULL), weak_ptr_factory_(this) {} | 117 SyncSchedulerTest() : syncer_(NULL), delay_(NULL), weak_ptr_factory_(this) {} |
| 120 | 118 |
| 121 class MockDelayProvider : public BackoffDelayProvider { | 119 class MockDelayProvider : public BackoffDelayProvider { |
| 122 public: | 120 public: |
| 123 MockDelayProvider() : BackoffDelayProvider( | 121 MockDelayProvider() |
| 124 TimeDelta::FromSeconds(kInitialBackoffRetrySeconds), | 122 : BackoffDelayProvider( |
| 125 TimeDelta::FromSeconds(kInitialBackoffImmediateRetrySeconds)) { | 123 TimeDelta::FromSeconds(kInitialBackoffRetrySeconds), |
| 126 } | 124 TimeDelta::FromSeconds(kInitialBackoffImmediateRetrySeconds)) {} |
| 127 | 125 |
| 128 MOCK_METHOD1(GetDelay, TimeDelta(const TimeDelta&)); | 126 MOCK_METHOD1(GetDelay, TimeDelta(const TimeDelta&)); |
| 129 }; | 127 }; |
| 130 | 128 |
| 131 void SetUp() override { | 129 void SetUp() override { |
| 132 dir_maker_.SetUp(); | 130 dir_maker_.SetUp(); |
| 133 syncer_ = new testing::StrictMock<MockSyncer>(); | 131 syncer_ = new testing::StrictMock<MockSyncer>(); |
| 134 delay_ = NULL; | 132 delay_ = NULL; |
| 135 extensions_activity_ = new ExtensionsActivity(); | 133 extensions_activity_ = new ExtensionsActivity(); |
| 136 | 134 |
| 137 routing_info_[THEMES] = GROUP_UI; | 135 routing_info_[THEMES] = GROUP_UI; |
| 138 routing_info_[TYPED_URLS] = GROUP_DB; | 136 routing_info_[TYPED_URLS] = GROUP_DB; |
| 139 routing_info_[THEMES] = GROUP_UI; | 137 routing_info_[THEMES] = GROUP_UI; |
| 140 routing_info_[NIGORI] = GROUP_PASSIVE; | 138 routing_info_[NIGORI] = GROUP_PASSIVE; |
| 141 | 139 |
| 142 workers_.clear(); | 140 workers_.clear(); |
| 143 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_UI))); | 141 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_UI))); |
| 144 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_DB))); | 142 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_DB))); |
| 145 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_PASSIVE))); | 143 workers_.push_back(make_scoped_refptr(new FakeModelWorker(GROUP_PASSIVE))); |
| 146 | 144 |
| 147 connection_.reset(new MockConnectionManager(directory(), | 145 connection_.reset( |
| 148 &cancelation_signal_)); | 146 new MockConnectionManager(directory(), &cancelation_signal_)); |
| 149 connection_->SetServerReachable(); | 147 connection_->SetServerReachable(); |
| 150 | 148 |
| 151 model_type_registry_.reset( | 149 model_type_registry_.reset( |
| 152 new ModelTypeRegistry(workers_, directory(), &mock_nudge_handler_)); | 150 new ModelTypeRegistry(workers_, directory(), &mock_nudge_handler_)); |
| 153 | 151 |
| 154 context_.reset(new SyncSessionContext( | 152 context_.reset(new SyncSessionContext( |
| 155 connection_.get(), directory(), | 153 connection_.get(), directory(), extensions_activity_.get(), |
| 156 extensions_activity_.get(), | 154 std::vector<SyncEngineEventListener*>(), NULL, |
| 157 std::vector<SyncEngineEventListener*>(), NULL, | 155 model_type_registry_.get(), |
| 158 model_type_registry_.get(), | 156 true, // enable keystore encryption |
| 159 true, // enable keystore encryption | 157 false, // force enable pre-commit GU avoidance |
| 160 false, // force enable pre-commit GU avoidance | 158 "fake_invalidator_client_id")); |
| 161 "fake_invalidator_client_id")); | |
| 162 context_->SetRoutingInfo(routing_info_); | 159 context_->SetRoutingInfo(routing_info_); |
| 163 context_->set_notifications_enabled(true); | 160 context_->set_notifications_enabled(true); |
| 164 context_->set_account_name("Test"); | 161 context_->set_account_name("Test"); |
| 165 scheduler_.reset( | 162 scheduler_.reset(new SyncSchedulerImpl("TestSyncScheduler", |
| 166 new SyncSchedulerImpl("TestSyncScheduler", | 163 BackoffDelayProvider::FromDefaults(), |
| 167 BackoffDelayProvider::FromDefaults(), | 164 context(), syncer_)); |
| 168 context(), | |
| 169 syncer_)); | |
| 170 scheduler_->SetDefaultNudgeDelay(default_delay()); | 165 scheduler_->SetDefaultNudgeDelay(default_delay()); |
| 171 } | 166 } |
| 172 | 167 |
| 173 SyncSchedulerImpl* scheduler() { return scheduler_.get(); } | 168 SyncSchedulerImpl* scheduler() { return scheduler_.get(); } |
| 174 const ModelSafeRoutingInfo& routing_info() { return routing_info_; } | 169 const ModelSafeRoutingInfo& routing_info() { return routing_info_; } |
| 175 MockSyncer* syncer() { return syncer_; } | 170 MockSyncer* syncer() { return syncer_; } |
| 176 MockDelayProvider* delay() { return delay_; } | 171 MockDelayProvider* delay() { return delay_; } |
| 177 MockConnectionManager* connection() { return connection_.get(); } | 172 MockConnectionManager* connection() { return connection_.get(); } |
| 178 TimeDelta default_delay() { return TimeDelta::FromSeconds(0); } | 173 TimeDelta default_delay() { return TimeDelta::FromSeconds(0); } |
| 179 TimeDelta timeout() { | 174 TimeDelta timeout() { return TestTimeouts::action_timeout(); } |
| 180 return TestTimeouts::action_timeout(); | |
| 181 } | |
| 182 | 175 |
| 183 void TearDown() override { | 176 void TearDown() override { |
| 184 PumpLoop(); | 177 PumpLoop(); |
| 185 scheduler_.reset(); | 178 scheduler_.reset(); |
| 186 PumpLoop(); | 179 PumpLoop(); |
| 187 dir_maker_.TearDown(); | 180 dir_maker_.TearDown(); |
| 188 } | 181 } |
| 189 | 182 |
| 190 void AnalyzePollRun(const SyncShareTimes& times, size_t min_num_samples, | 183 void AnalyzePollRun(const SyncShareTimes& times, |
| 191 const TimeTicks& optimal_start, const TimeDelta& poll_interval) { | 184 size_t min_num_samples, |
| 185 const TimeTicks& optimal_start, |
| 186 const TimeDelta& poll_interval) { |
| 192 EXPECT_GE(times.size(), min_num_samples); | 187 EXPECT_GE(times.size(), min_num_samples); |
| 193 for (size_t i = 0; i < times.size(); i++) { | 188 for (size_t i = 0; i < times.size(); i++) { |
| 194 SCOPED_TRACE(testing::Message() << "SyncShare # (" << i << ")"); | 189 SCOPED_TRACE(testing::Message() << "SyncShare # (" << i << ")"); |
| 195 TimeTicks optimal_next_sync = optimal_start + poll_interval * i; | 190 TimeTicks optimal_next_sync = optimal_start + poll_interval * i; |
| 196 EXPECT_GE(times[i], optimal_next_sync); | 191 EXPECT_GE(times[i], optimal_next_sync); |
| 197 } | 192 } |
| 198 } | 193 } |
| 199 | 194 |
| 200 void DoQuitLoopNow() { | 195 void DoQuitLoopNow() { QuitLoopNow(); } |
| 201 QuitLoopNow(); | |
| 202 } | |
| 203 | 196 |
| 204 void StartSyncConfiguration() { | 197 void StartSyncConfiguration() { |
| 205 scheduler()->Start(SyncScheduler::CONFIGURATION_MODE, base::Time()); | 198 scheduler()->Start(SyncScheduler::CONFIGURATION_MODE, base::Time()); |
| 206 } | 199 } |
| 207 | 200 |
| 208 void StartSyncScheduler(base::Time last_poll_time) { | 201 void StartSyncScheduler(base::Time last_poll_time) { |
| 209 scheduler()->Start(SyncScheduler::NORMAL_MODE, last_poll_time); | 202 scheduler()->Start(SyncScheduler::NORMAL_MODE, last_poll_time); |
| 210 } | 203 } |
| 211 | 204 |
| 212 // This stops the scheduler synchronously. | 205 // This stops the scheduler synchronously. |
| (...skipping 30 matching lines...) Expand all Loading... |
| 243 return scheduler_->retry_timer_.GetCurrentDelay(); | 236 return scheduler_->retry_timer_.GetCurrentDelay(); |
| 244 } | 237 } |
| 245 | 238 |
| 246 static std::unique_ptr<InvalidationInterface> BuildInvalidation( | 239 static std::unique_ptr<InvalidationInterface> BuildInvalidation( |
| 247 int64_t version, | 240 int64_t version, |
| 248 const std::string& payload) { | 241 const std::string& payload) { |
| 249 return MockInvalidation::Build(version, payload); | 242 return MockInvalidation::Build(version, payload); |
| 250 } | 243 } |
| 251 | 244 |
| 252 private: | 245 private: |
| 253 syncable::Directory* directory() { | 246 syncable::Directory* directory() { return dir_maker_.directory(); } |
| 254 return dir_maker_.directory(); | |
| 255 } | |
| 256 | 247 |
| 257 base::MessageLoop loop_; | 248 base::MessageLoop loop_; |
| 258 TestDirectorySetterUpper dir_maker_; | 249 TestDirectorySetterUpper dir_maker_; |
| 259 CancelationSignal cancelation_signal_; | 250 CancelationSignal cancelation_signal_; |
| 260 std::unique_ptr<MockConnectionManager> connection_; | 251 std::unique_ptr<MockConnectionManager> connection_; |
| 261 std::unique_ptr<ModelTypeRegistry> model_type_registry_; | 252 std::unique_ptr<ModelTypeRegistry> model_type_registry_; |
| 262 std::unique_ptr<SyncSessionContext> context_; | 253 std::unique_ptr<SyncSessionContext> context_; |
| 263 std::unique_ptr<SyncSchedulerImpl> scheduler_; | 254 std::unique_ptr<SyncSchedulerImpl> scheduler_; |
| 264 MockNudgeHandler mock_nudge_handler_; | 255 MockNudgeHandler mock_nudge_handler_; |
| 265 MockSyncer* syncer_; | 256 MockSyncer* syncer_; |
| 266 MockDelayProvider* delay_; | 257 MockDelayProvider* delay_; |
| 267 std::vector<scoped_refptr<ModelSafeWorker> > workers_; | 258 std::vector<scoped_refptr<ModelSafeWorker>> workers_; |
| 268 scoped_refptr<ExtensionsActivity> extensions_activity_; | 259 scoped_refptr<ExtensionsActivity> extensions_activity_; |
| 269 ModelSafeRoutingInfo routing_info_; | 260 ModelSafeRoutingInfo routing_info_; |
| 270 base::WeakPtrFactory<SyncSchedulerTest> weak_ptr_factory_; | 261 base::WeakPtrFactory<SyncSchedulerTest> weak_ptr_factory_; |
| 271 }; | 262 }; |
| 272 | 263 |
| 273 void RecordSyncShareImpl(SyncShareTimes* times) { | 264 void RecordSyncShareImpl(SyncShareTimes* times) { |
| 274 times->push_back(TimeTicks::Now()); | 265 times->push_back(TimeTicks::Now()); |
| 275 } | 266 } |
| 276 | 267 |
| 277 ACTION_P2(RecordSyncShare, times, success) { | 268 ACTION_P2(RecordSyncShare, times, success) { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 | 333 |
| 343 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) | 334 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) |
| 344 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess), | 335 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess), |
| 345 RecordSyncShare(×, true))); | 336 RecordSyncShare(×, true))); |
| 346 | 337 |
| 347 StartSyncConfiguration(); | 338 StartSyncConfiguration(); |
| 348 | 339 |
| 349 CallbackCounter ready_counter; | 340 CallbackCounter ready_counter; |
| 350 CallbackCounter retry_counter; | 341 CallbackCounter retry_counter; |
| 351 ConfigurationParams params( | 342 ConfigurationParams params( |
| 352 GetUpdatesCallerInfo::RECONFIGURATION, | 343 GetUpdatesCallerInfo::RECONFIGURATION, model_types, |
| 353 model_types, | |
| 354 TypesToRoutingInfo(model_types), | 344 TypesToRoutingInfo(model_types), |
| 355 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), | 345 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), |
| 356 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); | 346 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); |
| 357 scheduler()->ScheduleConfiguration(params); | 347 scheduler()->ScheduleConfiguration(params); |
| 358 PumpLoop(); | 348 PumpLoop(); |
| 359 ASSERT_EQ(1, ready_counter.times_called()); | 349 ASSERT_EQ(1, ready_counter.times_called()); |
| 360 ASSERT_EQ(0, retry_counter.times_called()); | 350 ASSERT_EQ(0, retry_counter.times_called()); |
| 361 } | 351 } |
| 362 | 352 |
| 363 // Simulate a failure and make sure the config request is retried. | 353 // Simulate a failure and make sure the config request is retried. |
| 364 TEST_F(SyncSchedulerTest, ConfigWithBackingOff) { | 354 TEST_F(SyncSchedulerTest, ConfigWithBackingOff) { |
| 365 UseMockDelayProvider(); | 355 UseMockDelayProvider(); |
| 366 EXPECT_CALL(*delay(), GetDelay(_)) | 356 EXPECT_CALL(*delay(), GetDelay(_)) |
| 367 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(20))); | 357 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(20))); |
| 368 SyncShareTimes times; | 358 SyncShareTimes times; |
| 369 const ModelTypeSet model_types(THEMES); | 359 const ModelTypeSet model_types(THEMES); |
| 370 | 360 |
| 371 StartSyncConfiguration(); | 361 StartSyncConfiguration(); |
| 372 | 362 |
| 373 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) | 363 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) |
| 374 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureFailed), | 364 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureFailed), |
| 375 RecordSyncShare(×, false))) | 365 RecordSyncShare(×, false))) |
| 376 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureFailed), | 366 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureFailed), |
| 377 RecordSyncShare(×, false))); | 367 RecordSyncShare(×, false))); |
| 378 | 368 |
| 379 CallbackCounter ready_counter; | 369 CallbackCounter ready_counter; |
| 380 CallbackCounter retry_counter; | 370 CallbackCounter retry_counter; |
| 381 ConfigurationParams params( | 371 ConfigurationParams params( |
| 382 GetUpdatesCallerInfo::RECONFIGURATION, | 372 GetUpdatesCallerInfo::RECONFIGURATION, model_types, |
| 383 model_types, | |
| 384 TypesToRoutingInfo(model_types), | 373 TypesToRoutingInfo(model_types), |
| 385 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), | 374 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), |
| 386 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); | 375 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); |
| 387 scheduler()->ScheduleConfiguration(params); | 376 scheduler()->ScheduleConfiguration(params); |
| 388 RunLoop(); | 377 RunLoop(); |
| 389 ASSERT_EQ(0, ready_counter.times_called()); | 378 ASSERT_EQ(0, ready_counter.times_called()); |
| 390 ASSERT_EQ(1, retry_counter.times_called()); | 379 ASSERT_EQ(1, retry_counter.times_called()); |
| 391 | 380 |
| 392 // RunLoop() will trigger TryCanaryJob which will retry configuration. | 381 // RunLoop() will trigger TryCanaryJob which will retry configuration. |
| 393 // Since retry_task was already called it shouldn't be called again. | 382 // Since retry_task was already called it shouldn't be called again. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 419 // Make ConfigureSyncShare call scheduler->Stop(). It is not supposed to call | 408 // Make ConfigureSyncShare call scheduler->Stop(). It is not supposed to call |
| 420 // retry_task or dereference configuration params. | 409 // retry_task or dereference configuration params. |
| 421 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) | 410 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) |
| 422 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureFailed), | 411 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureFailed), |
| 423 StopScheduler(scheduler()), | 412 StopScheduler(scheduler()), |
| 424 RecordSyncShare(×, false))); | 413 RecordSyncShare(×, false))); |
| 425 | 414 |
| 426 CallbackCounter ready_counter; | 415 CallbackCounter ready_counter; |
| 427 CallbackCounter retry_counter; | 416 CallbackCounter retry_counter; |
| 428 ConfigurationParams params( | 417 ConfigurationParams params( |
| 429 GetUpdatesCallerInfo::RECONFIGURATION, | 418 GetUpdatesCallerInfo::RECONFIGURATION, model_types, |
| 430 model_types, | |
| 431 TypesToRoutingInfo(model_types), | 419 TypesToRoutingInfo(model_types), |
| 432 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), | 420 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), |
| 433 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); | 421 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); |
| 434 scheduler()->ScheduleConfiguration(params); | 422 scheduler()->ScheduleConfiguration(params); |
| 435 PumpLoop(); | 423 PumpLoop(); |
| 436 ASSERT_EQ(0, ready_counter.times_called()); | 424 ASSERT_EQ(0, ready_counter.times_called()); |
| 437 ASSERT_EQ(0, retry_counter.times_called()); | 425 ASSERT_EQ(0, retry_counter.times_called()); |
| 438 } | 426 } |
| 439 | 427 |
| 440 // Issue a nudge when the config has failed. Make sure both the config and | 428 // Issue a nudge when the config has failed. Make sure both the config and |
| 441 // nudge are executed. | 429 // nudge are executed. |
| 442 TEST_F(SyncSchedulerTest, NudgeWithConfigWithBackingOff) { | 430 TEST_F(SyncSchedulerTest, NudgeWithConfigWithBackingOff) { |
| 443 const ModelTypeSet model_types(THEMES); | 431 const ModelTypeSet model_types(THEMES); |
| 444 UseMockDelayProvider(); | 432 UseMockDelayProvider(); |
| 445 EXPECT_CALL(*delay(), GetDelay(_)) | 433 EXPECT_CALL(*delay(), GetDelay(_)) |
| 446 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(50))); | 434 .WillRepeatedly(Return(TimeDelta::FromMilliseconds(50))); |
| 447 SyncShareTimes times; | 435 SyncShareTimes times; |
| 448 | 436 |
| 449 StartSyncConfiguration(); | 437 StartSyncConfiguration(); |
| 450 | 438 |
| 451 // Request a configure and make sure it fails. | 439 // Request a configure and make sure it fails. |
| 452 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) | 440 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) |
| 453 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureFailed), | 441 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureFailed), |
| 454 RecordSyncShare(×, false))); | 442 RecordSyncShare(×, false))); |
| 455 CallbackCounter ready_counter; | 443 CallbackCounter ready_counter; |
| 456 CallbackCounter retry_counter; | 444 CallbackCounter retry_counter; |
| 457 ConfigurationParams params( | 445 ConfigurationParams params( |
| 458 GetUpdatesCallerInfo::RECONFIGURATION, | 446 GetUpdatesCallerInfo::RECONFIGURATION, model_types, |
| 459 model_types, | |
| 460 TypesToRoutingInfo(model_types), | 447 TypesToRoutingInfo(model_types), |
| 461 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), | 448 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), |
| 462 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); | 449 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); |
| 463 scheduler()->ScheduleConfiguration(params); | 450 scheduler()->ScheduleConfiguration(params); |
| 464 RunLoop(); | 451 RunLoop(); |
| 465 ASSERT_EQ(0, ready_counter.times_called()); | 452 ASSERT_EQ(0, ready_counter.times_called()); |
| 466 ASSERT_EQ(1, retry_counter.times_called()); | 453 ASSERT_EQ(1, retry_counter.times_called()); |
| 467 Mock::VerifyAndClearExpectations(syncer()); | 454 Mock::VerifyAndClearExpectations(syncer()); |
| 468 | 455 |
| 469 // Ask for a nudge while dealing with repeated configure failure. | 456 // Ask for a nudge while dealing with repeated configure failure. |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 | 539 |
| 553 // Test nudge scheduling. | 540 // Test nudge scheduling. |
| 554 TEST_F(SyncSchedulerTest, NudgeWithStates) { | 541 TEST_F(SyncSchedulerTest, NudgeWithStates) { |
| 555 StartSyncScheduler(base::Time()); | 542 StartSyncScheduler(base::Time()); |
| 556 | 543 |
| 557 SyncShareTimes times1; | 544 SyncShareTimes times1; |
| 558 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 545 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 559 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 546 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), |
| 560 RecordSyncShare(×1, true))) | 547 RecordSyncShare(×1, true))) |
| 561 .RetiresOnSaturation(); | 548 .RetiresOnSaturation(); |
| 562 scheduler()->ScheduleInvalidationNudge( | 549 scheduler()->ScheduleInvalidationNudge(THEMES, BuildInvalidation(10, "test"), |
| 563 THEMES, BuildInvalidation(10, "test"), FROM_HERE); | 550 FROM_HERE); |
| 564 RunLoop(); | 551 RunLoop(); |
| 565 | 552 |
| 566 Mock::VerifyAndClearExpectations(syncer()); | 553 Mock::VerifyAndClearExpectations(syncer()); |
| 567 | 554 |
| 568 // Make sure a second, later, nudge is unaffected by first (no coalescing). | 555 // Make sure a second, later, nudge is unaffected by first (no coalescing). |
| 569 SyncShareTimes times2; | 556 SyncShareTimes times2; |
| 570 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 557 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 571 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), | 558 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateNormalSuccess), |
| 572 RecordSyncShare(×2, true))); | 559 RecordSyncShare(×2, true))); |
| 573 scheduler()->ScheduleInvalidationNudge( | 560 scheduler()->ScheduleInvalidationNudge( |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 713 StartSyncScheduler(base::Time()); | 700 StartSyncScheduler(base::Time()); |
| 714 | 701 |
| 715 scheduler()->ScheduleLocalNudge(types, FROM_HERE); | 702 scheduler()->ScheduleLocalNudge(types, FROM_HERE); |
| 716 PumpLoop(); | 703 PumpLoop(); |
| 717 | 704 |
| 718 StartSyncConfiguration(); | 705 StartSyncConfiguration(); |
| 719 | 706 |
| 720 CallbackCounter ready_counter; | 707 CallbackCounter ready_counter; |
| 721 CallbackCounter retry_counter; | 708 CallbackCounter retry_counter; |
| 722 ConfigurationParams params( | 709 ConfigurationParams params( |
| 723 GetUpdatesCallerInfo::RECONFIGURATION, | 710 GetUpdatesCallerInfo::RECONFIGURATION, types, TypesToRoutingInfo(types), |
| 724 types, | |
| 725 TypesToRoutingInfo(types), | |
| 726 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), | 711 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), |
| 727 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); | 712 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); |
| 728 scheduler()->ScheduleConfiguration(params); | 713 scheduler()->ScheduleConfiguration(params); |
| 729 PumpLoop(); | 714 PumpLoop(); |
| 730 ASSERT_EQ(0, ready_counter.times_called()); | 715 ASSERT_EQ(0, ready_counter.times_called()); |
| 731 ASSERT_EQ(1, retry_counter.times_called()); | 716 ASSERT_EQ(1, retry_counter.times_called()); |
| 732 } | 717 } |
| 733 | 718 |
| 734 TEST_F(SyncSchedulerTest, ThrottlingExpiresFromPoll) { | 719 TEST_F(SyncSchedulerTest, ThrottlingExpiresFromPoll) { |
| 735 SyncShareTimes times; | 720 SyncShareTimes times; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 802 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) | 787 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) |
| 803 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess), | 788 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess), |
| 804 QuitLoopNowAction(true))); | 789 QuitLoopNowAction(true))); |
| 805 | 790 |
| 806 const ModelTypeSet types(THEMES); | 791 const ModelTypeSet types(THEMES); |
| 807 StartSyncConfiguration(); | 792 StartSyncConfiguration(); |
| 808 | 793 |
| 809 CallbackCounter ready_counter; | 794 CallbackCounter ready_counter; |
| 810 CallbackCounter retry_counter; | 795 CallbackCounter retry_counter; |
| 811 ConfigurationParams params( | 796 ConfigurationParams params( |
| 812 GetUpdatesCallerInfo::RECONFIGURATION, | 797 GetUpdatesCallerInfo::RECONFIGURATION, types, TypesToRoutingInfo(types), |
| 813 types, | |
| 814 TypesToRoutingInfo(types), | |
| 815 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), | 798 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), |
| 816 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); | 799 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); |
| 817 scheduler()->ScheduleConfiguration(params); | 800 scheduler()->ScheduleConfiguration(params); |
| 818 PumpLoop(); | 801 PumpLoop(); |
| 819 EXPECT_EQ(0, ready_counter.times_called()); | 802 EXPECT_EQ(0, ready_counter.times_called()); |
| 820 EXPECT_EQ(1, retry_counter.times_called()); | 803 EXPECT_EQ(1, retry_counter.times_called()); |
| 821 EXPECT_TRUE(scheduler()->IsCurrentlyThrottled()); | 804 EXPECT_TRUE(scheduler()->IsCurrentlyThrottled()); |
| 822 | 805 |
| 823 RunLoop(); | 806 RunLoop(); |
| 824 EXPECT_FALSE(scheduler()->IsCurrentlyThrottled()); | 807 EXPECT_FALSE(scheduler()->IsCurrentlyThrottled()); |
| 825 | 808 |
| 826 StopSyncScheduler(); | 809 StopSyncScheduler(); |
| 827 } | 810 } |
| 828 | 811 |
| 829 TEST_F(SyncSchedulerTest, TypeThrottlingBlocksNudge) { | 812 TEST_F(SyncSchedulerTest, TypeThrottlingBlocksNudge) { |
| 830 UseMockDelayProvider(); | 813 UseMockDelayProvider(); |
| 831 EXPECT_CALL(*delay(), GetDelay(_)) | 814 EXPECT_CALL(*delay(), GetDelay(_)).WillRepeatedly(Return(default_delay())); |
| 832 .WillRepeatedly(Return(default_delay())); | |
| 833 | 815 |
| 834 TimeDelta poll(TimeDelta::FromDays(1)); | 816 TimeDelta poll(TimeDelta::FromDays(1)); |
| 835 TimeDelta throttle1(TimeDelta::FromSeconds(60)); | 817 TimeDelta throttle1(TimeDelta::FromSeconds(60)); |
| 836 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 818 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
| 837 | 819 |
| 838 const ModelTypeSet types(THEMES); | 820 const ModelTypeSet types(THEMES); |
| 839 | 821 |
| 840 ::testing::InSequence seq; | 822 ::testing::InSequence seq; |
| 841 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 823 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 842 .WillOnce(DoAll(WithArg<2>(sessions::test_util::SimulateTypesThrottled( | 824 .WillOnce(DoAll(WithArg<2>(sessions::test_util::SimulateTypesThrottled( |
| 843 types, throttle1)), | 825 types, throttle1)), |
| 844 Return(false))) | 826 Return(false))) |
| 845 .RetiresOnSaturation(); | 827 .RetiresOnSaturation(); |
| 846 | 828 |
| 847 StartSyncScheduler(base::Time()); | 829 StartSyncScheduler(base::Time()); |
| 848 scheduler()->ScheduleLocalNudge(types, FROM_HERE); | 830 scheduler()->ScheduleLocalNudge(types, FROM_HERE); |
| 849 PumpLoop(); // To get PerformDelayedNudge called. | 831 PumpLoop(); // To get PerformDelayedNudge called. |
| 850 PumpLoop(); // To get TrySyncSessionJob called | 832 PumpLoop(); // To get TrySyncSessionJob called |
| 851 EXPECT_TRUE(GetThrottledTypes().HasAll(types)); | 833 EXPECT_TRUE(GetThrottledTypes().HasAll(types)); |
| 852 | 834 |
| 853 // This won't cause a sync cycle because the types are throttled. | 835 // This won't cause a sync cycle because the types are throttled. |
| 854 scheduler()->ScheduleLocalNudge(types, FROM_HERE); | 836 scheduler()->ScheduleLocalNudge(types, FROM_HERE); |
| 855 PumpLoop(); | 837 PumpLoop(); |
| 856 | 838 |
| 857 StopSyncScheduler(); | 839 StopSyncScheduler(); |
| 858 } | 840 } |
| 859 | 841 |
| 860 TEST_F(SyncSchedulerTest, TypeThrottlingDoesBlockOtherSources) { | 842 TEST_F(SyncSchedulerTest, TypeThrottlingDoesBlockOtherSources) { |
| 861 UseMockDelayProvider(); | 843 UseMockDelayProvider(); |
| 862 EXPECT_CALL(*delay(), GetDelay(_)) | 844 EXPECT_CALL(*delay(), GetDelay(_)).WillRepeatedly(Return(default_delay())); |
| 863 .WillRepeatedly(Return(default_delay())); | |
| 864 | 845 |
| 865 SyncShareTimes times; | 846 SyncShareTimes times; |
| 866 TimeDelta poll(TimeDelta::FromDays(1)); | 847 TimeDelta poll(TimeDelta::FromDays(1)); |
| 867 TimeDelta throttle1(TimeDelta::FromSeconds(60)); | 848 TimeDelta throttle1(TimeDelta::FromSeconds(60)); |
| 868 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 849 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
| 869 | 850 |
| 870 const ModelTypeSet throttled_types(THEMES); | 851 const ModelTypeSet throttled_types(THEMES); |
| 871 const ModelTypeSet unthrottled_types(PREFERENCES); | 852 const ModelTypeSet unthrottled_types(PREFERENCES); |
| 872 | 853 |
| 873 ::testing::InSequence seq; | 854 ::testing::InSequence seq; |
| 874 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 855 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 875 .WillOnce(DoAll(WithArg<2>(sessions::test_util::SimulateTypesThrottled( | 856 .WillOnce(DoAll(WithArg<2>(sessions::test_util::SimulateTypesThrottled( |
| 876 throttled_types, throttle1)), | 857 throttled_types, throttle1)), |
| 877 Return(false))) | 858 Return(false))) |
| 878 .RetiresOnSaturation(); | 859 .RetiresOnSaturation(); |
| 879 | 860 |
| 880 StartSyncScheduler(base::Time()); | 861 StartSyncScheduler(base::Time()); |
| 881 scheduler()->ScheduleLocalNudge(throttled_types, FROM_HERE); | 862 scheduler()->ScheduleLocalNudge(throttled_types, FROM_HERE); |
| 882 PumpLoop(); // To get PerformDelayedNudge called. | 863 PumpLoop(); // To get PerformDelayedNudge called. |
| 883 PumpLoop(); // To get TrySyncSessionJob called | 864 PumpLoop(); // To get TrySyncSessionJob called |
| 884 EXPECT_TRUE(GetThrottledTypes().HasAll(throttled_types)); | 865 EXPECT_TRUE(GetThrottledTypes().HasAll(throttled_types)); |
| 885 | 866 |
| 886 // Ignore invalidations for throttled types. | 867 // Ignore invalidations for throttled types. |
| 887 scheduler()->ScheduleInvalidationNudge( | 868 scheduler()->ScheduleInvalidationNudge(THEMES, BuildInvalidation(10, "test"), |
| 888 THEMES, BuildInvalidation(10, "test"), FROM_HERE); | 869 FROM_HERE); |
| 889 PumpLoop(); | 870 PumpLoop(); |
| 890 | 871 |
| 891 // Ignore refresh requests for throttled types. | 872 // Ignore refresh requests for throttled types. |
| 892 scheduler()->ScheduleLocalRefreshRequest(throttled_types, FROM_HERE); | 873 scheduler()->ScheduleLocalRefreshRequest(throttled_types, FROM_HERE); |
| 893 PumpLoop(); | 874 PumpLoop(); |
| 894 | 875 |
| 895 Mock::VerifyAndClearExpectations(syncer()); | 876 Mock::VerifyAndClearExpectations(syncer()); |
| 896 | 877 |
| 897 // Local nudges for non-throttled types will trigger a sync. | 878 // Local nudges for non-throttled types will trigger a sync. |
| 898 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 879 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| (...skipping 20 matching lines...) Expand all Loading... |
| 919 | 900 |
| 920 const ModelTypeSet config_types(THEMES); | 901 const ModelTypeSet config_types(THEMES); |
| 921 | 902 |
| 922 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) | 903 EXPECT_CALL(*syncer(), ConfigureSyncShare(_, _, _)) |
| 923 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess), | 904 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateConfigureSuccess), |
| 924 RecordSyncShare(×, true))) | 905 RecordSyncShare(×, true))) |
| 925 .RetiresOnSaturation(); | 906 .RetiresOnSaturation(); |
| 926 CallbackCounter ready_counter; | 907 CallbackCounter ready_counter; |
| 927 CallbackCounter retry_counter; | 908 CallbackCounter retry_counter; |
| 928 ConfigurationParams params( | 909 ConfigurationParams params( |
| 929 GetUpdatesCallerInfo::RECONFIGURATION, | 910 GetUpdatesCallerInfo::RECONFIGURATION, config_types, |
| 930 config_types, | |
| 931 TypesToRoutingInfo(config_types), | 911 TypesToRoutingInfo(config_types), |
| 932 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), | 912 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), |
| 933 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); | 913 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); |
| 934 scheduler()->ScheduleConfiguration(params); | 914 scheduler()->ScheduleConfiguration(params); |
| 935 RunLoop(); | 915 RunLoop(); |
| 936 ASSERT_EQ(1, ready_counter.times_called()); | 916 ASSERT_EQ(1, ready_counter.times_called()); |
| 937 ASSERT_EQ(0, retry_counter.times_called()); | 917 ASSERT_EQ(0, retry_counter.times_called()); |
| 938 | 918 |
| 939 Mock::VerifyAndClearExpectations(syncer()); | 919 Mock::VerifyAndClearExpectations(syncer()); |
| 940 | 920 |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1022 Return(false))) | 1002 Return(false))) |
| 1023 .WillRepeatedly( | 1003 .WillRepeatedly( |
| 1024 DoAll(Invoke(sessions::test_util::SimulateGetEncryptionKeyFailed), | 1004 DoAll(Invoke(sessions::test_util::SimulateGetEncryptionKeyFailed), |
| 1025 QuitLoopNowAction(false))); | 1005 QuitLoopNowAction(false))); |
| 1026 StartSyncConfiguration(); | 1006 StartSyncConfiguration(); |
| 1027 | 1007 |
| 1028 ModelTypeSet types(THEMES); | 1008 ModelTypeSet types(THEMES); |
| 1029 CallbackCounter ready_counter; | 1009 CallbackCounter ready_counter; |
| 1030 CallbackCounter retry_counter; | 1010 CallbackCounter retry_counter; |
| 1031 ConfigurationParams params( | 1011 ConfigurationParams params( |
| 1032 GetUpdatesCallerInfo::RECONFIGURATION, | 1012 GetUpdatesCallerInfo::RECONFIGURATION, types, TypesToRoutingInfo(types), |
| 1033 types, | |
| 1034 TypesToRoutingInfo(types), | |
| 1035 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), | 1013 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), |
| 1036 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); | 1014 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); |
| 1037 scheduler()->ScheduleConfiguration(params); | 1015 scheduler()->ScheduleConfiguration(params); |
| 1038 RunLoop(); | 1016 RunLoop(); |
| 1039 | 1017 |
| 1040 EXPECT_TRUE(scheduler()->IsBackingOff()); | 1018 EXPECT_TRUE(scheduler()->IsBackingOff()); |
| 1041 } | 1019 } |
| 1042 | 1020 |
| 1043 // Test that no polls or extraneous nudges occur when in backoff. | 1021 // Test that no polls or extraneous nudges occur when in backoff. |
| 1044 TEST_F(SyncSchedulerTest, BackoffDropsJobs) { | 1022 TEST_F(SyncSchedulerTest, BackoffDropsJobs) { |
| 1045 SyncShareTimes times; | 1023 SyncShareTimes times; |
| 1046 TimeDelta poll(TimeDelta::FromMilliseconds(10)); | 1024 TimeDelta poll(TimeDelta::FromMilliseconds(10)); |
| 1047 const ModelTypeSet types(THEMES); | 1025 const ModelTypeSet types(THEMES); |
| 1048 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 1026 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
| 1049 UseMockDelayProvider(); | 1027 UseMockDelayProvider(); |
| 1050 | 1028 |
| 1051 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 1029 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 1052 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), | 1030 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), |
| 1053 RecordSyncShareMultiple(×, 1U, false))); | 1031 RecordSyncShareMultiple(×, 1U, false))); |
| 1054 EXPECT_CALL(*delay(), GetDelay(_)). | 1032 EXPECT_CALL(*delay(), GetDelay(_)) |
| 1055 WillRepeatedly(Return(TimeDelta::FromDays(1))); | 1033 .WillRepeatedly(Return(TimeDelta::FromDays(1))); |
| 1056 | 1034 |
| 1057 StartSyncScheduler(base::Time()); | 1035 StartSyncScheduler(base::Time()); |
| 1058 | 1036 |
| 1059 // This nudge should fail and put us into backoff. Thanks to our mock | 1037 // This nudge should fail and put us into backoff. Thanks to our mock |
| 1060 // GetDelay() setup above, this will be a long backoff. | 1038 // GetDelay() setup above, this will be a long backoff. |
| 1061 scheduler()->ScheduleLocalNudge(types, FROM_HERE); | 1039 scheduler()->ScheduleLocalNudge(types, FROM_HERE); |
| 1062 RunLoop(); | 1040 RunLoop(); |
| 1063 | 1041 |
| 1064 // From this point forward, no SyncShare functions should be invoked. | 1042 // From this point forward, no SyncShare functions should be invoked. |
| 1065 Mock::VerifyAndClearExpectations(syncer()); | 1043 Mock::VerifyAndClearExpectations(syncer()); |
| 1066 | 1044 |
| 1067 // Wait a while (10x poll interval) so a few poll jobs will be attempted. | 1045 // Wait a while (10x poll interval) so a few poll jobs will be attempted. |
| 1068 PumpLoopFor(poll * 10); | 1046 PumpLoopFor(poll * 10); |
| 1069 | 1047 |
| 1070 // Try (and fail) to schedule a nudge. | 1048 // Try (and fail) to schedule a nudge. |
| 1071 scheduler()->ScheduleLocalNudge(types, FROM_HERE); | 1049 scheduler()->ScheduleLocalNudge(types, FROM_HERE); |
| 1072 | 1050 |
| 1073 Mock::VerifyAndClearExpectations(syncer()); | 1051 Mock::VerifyAndClearExpectations(syncer()); |
| 1074 Mock::VerifyAndClearExpectations(delay()); | 1052 Mock::VerifyAndClearExpectations(delay()); |
| 1075 | 1053 |
| 1076 EXPECT_CALL(*delay(), GetDelay(_)).Times(0); | 1054 EXPECT_CALL(*delay(), GetDelay(_)).Times(0); |
| 1077 | 1055 |
| 1078 StartSyncConfiguration(); | 1056 StartSyncConfiguration(); |
| 1079 | 1057 |
| 1080 CallbackCounter ready_counter; | 1058 CallbackCounter ready_counter; |
| 1081 CallbackCounter retry_counter; | 1059 CallbackCounter retry_counter; |
| 1082 ConfigurationParams params( | 1060 ConfigurationParams params( |
| 1083 GetUpdatesCallerInfo::RECONFIGURATION, | 1061 GetUpdatesCallerInfo::RECONFIGURATION, types, TypesToRoutingInfo(types), |
| 1084 types, | |
| 1085 TypesToRoutingInfo(types), | |
| 1086 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), | 1062 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), |
| 1087 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); | 1063 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); |
| 1088 scheduler()->ScheduleConfiguration(params); | 1064 scheduler()->ScheduleConfiguration(params); |
| 1089 PumpLoop(); | 1065 PumpLoop(); |
| 1090 ASSERT_EQ(0, ready_counter.times_called()); | 1066 ASSERT_EQ(0, ready_counter.times_called()); |
| 1091 ASSERT_EQ(1, retry_counter.times_called()); | 1067 ASSERT_EQ(1, retry_counter.times_called()); |
| 1092 } | 1068 } |
| 1093 | 1069 |
| 1094 // Test that backoff is shaping traffic properly with consecutive errors. | 1070 // Test that backoff is shaping traffic properly with consecutive errors. |
| 1095 TEST_F(SyncSchedulerTest, BackoffElevation) { | 1071 TEST_F(SyncSchedulerTest, BackoffElevation) { |
| 1096 SyncShareTimes times; | 1072 SyncShareTimes times; |
| 1097 UseMockDelayProvider(); | 1073 UseMockDelayProvider(); |
| 1098 | 1074 |
| 1099 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) | 1075 EXPECT_CALL(*syncer(), NormalSyncShare(_, _, _)) |
| 1100 .Times(kMinNumSamples) | 1076 .Times(kMinNumSamples) |
| 1101 .WillRepeatedly( | 1077 .WillRepeatedly( |
| 1102 DoAll(Invoke(sessions::test_util::SimulateCommitFailed), | 1078 DoAll(Invoke(sessions::test_util::SimulateCommitFailed), |
| 1103 RecordSyncShareMultiple(×, kMinNumSamples, false))); | 1079 RecordSyncShareMultiple(×, kMinNumSamples, false))); |
| 1104 | 1080 |
| 1105 const TimeDelta first = TimeDelta::FromSeconds(kInitialBackoffRetrySeconds); | 1081 const TimeDelta first = TimeDelta::FromSeconds(kInitialBackoffRetrySeconds); |
| 1106 const TimeDelta second = TimeDelta::FromMilliseconds(20); | 1082 const TimeDelta second = TimeDelta::FromMilliseconds(20); |
| 1107 const TimeDelta third = TimeDelta::FromMilliseconds(30); | 1083 const TimeDelta third = TimeDelta::FromMilliseconds(30); |
| 1108 const TimeDelta fourth = TimeDelta::FromMilliseconds(40); | 1084 const TimeDelta fourth = TimeDelta::FromMilliseconds(40); |
| 1109 const TimeDelta fifth = TimeDelta::FromMilliseconds(50); | 1085 const TimeDelta fifth = TimeDelta::FromMilliseconds(50); |
| 1110 const TimeDelta sixth = TimeDelta::FromDays(1); | 1086 const TimeDelta sixth = TimeDelta::FromDays(1); |
| 1111 | 1087 |
| 1112 EXPECT_CALL(*delay(), GetDelay(first)).WillOnce(Return(second)) | 1088 EXPECT_CALL(*delay(), GetDelay(first)) |
| 1113 .RetiresOnSaturation(); | 1089 .WillOnce(Return(second)) |
| 1114 EXPECT_CALL(*delay(), GetDelay(second)).WillOnce(Return(third)) | 1090 .RetiresOnSaturation(); |
| 1115 .RetiresOnSaturation(); | 1091 EXPECT_CALL(*delay(), GetDelay(second)) |
| 1116 EXPECT_CALL(*delay(), GetDelay(third)).WillOnce(Return(fourth)) | 1092 .WillOnce(Return(third)) |
| 1117 .RetiresOnSaturation(); | 1093 .RetiresOnSaturation(); |
| 1118 EXPECT_CALL(*delay(), GetDelay(fourth)).WillOnce(Return(fifth)) | 1094 EXPECT_CALL(*delay(), GetDelay(third)) |
| 1119 .RetiresOnSaturation(); | 1095 .WillOnce(Return(fourth)) |
| 1096 .RetiresOnSaturation(); |
| 1097 EXPECT_CALL(*delay(), GetDelay(fourth)) |
| 1098 .WillOnce(Return(fifth)) |
| 1099 .RetiresOnSaturation(); |
| 1120 EXPECT_CALL(*delay(), GetDelay(fifth)).WillOnce(Return(sixth)); | 1100 EXPECT_CALL(*delay(), GetDelay(fifth)).WillOnce(Return(sixth)); |
| 1121 | 1101 |
| 1122 StartSyncScheduler(base::Time()); | 1102 StartSyncScheduler(base::Time()); |
| 1123 | 1103 |
| 1124 // Run again with a nudge. | 1104 // Run again with a nudge. |
| 1125 scheduler()->ScheduleLocalNudge(ModelTypeSet(THEMES), FROM_HERE); | 1105 scheduler()->ScheduleLocalNudge(ModelTypeSet(THEMES), FROM_HERE); |
| 1126 RunLoop(); | 1106 RunLoop(); |
| 1127 | 1107 |
| 1128 ASSERT_EQ(kMinNumSamples, times.size()); | 1108 ASSERT_EQ(kMinNumSamples, times.size()); |
| 1129 EXPECT_GE(times[1] - times[0], second); | 1109 EXPECT_GE(times[1] - times[0], second); |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1307 DoAll(Invoke(sessions::test_util::SimulateConfigureConnectionFailure), | 1287 DoAll(Invoke(sessions::test_util::SimulateConfigureConnectionFailure), |
| 1308 Return(true))); | 1288 Return(true))); |
| 1309 StartSyncConfiguration(); | 1289 StartSyncConfiguration(); |
| 1310 connection()->SetServerNotReachable(); | 1290 connection()->SetServerNotReachable(); |
| 1311 connection()->UpdateConnectionStatus(); | 1291 connection()->UpdateConnectionStatus(); |
| 1312 | 1292 |
| 1313 ModelTypeSet model_types(THEMES); | 1293 ModelTypeSet model_types(THEMES); |
| 1314 CallbackCounter ready_counter; | 1294 CallbackCounter ready_counter; |
| 1315 CallbackCounter retry_counter; | 1295 CallbackCounter retry_counter; |
| 1316 ConfigurationParams params( | 1296 ConfigurationParams params( |
| 1317 GetUpdatesCallerInfo::RECONFIGURATION, | 1297 GetUpdatesCallerInfo::RECONFIGURATION, model_types, |
| 1318 model_types, | |
| 1319 TypesToRoutingInfo(model_types), | 1298 TypesToRoutingInfo(model_types), |
| 1320 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), | 1299 base::Bind(&CallbackCounter::Callback, base::Unretained(&ready_counter)), |
| 1321 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); | 1300 base::Bind(&CallbackCounter::Callback, base::Unretained(&retry_counter))); |
| 1322 scheduler()->ScheduleConfiguration(params); | 1301 scheduler()->ScheduleConfiguration(params); |
| 1323 | 1302 |
| 1324 scheduler()->OnConnectionStatusChange(); | 1303 scheduler()->OnConnectionStatusChange(); |
| 1325 scheduler()->OnConnectionStatusChange(); | 1304 scheduler()->OnConnectionStatusChange(); |
| 1326 | 1305 |
| 1327 PumpLoop(); // Run the nudge, that will fail and schedule a quick retry. | 1306 PumpLoop(); // Run the nudge, that will fail and schedule a quick retry. |
| 1328 } | 1307 } |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1470 ASSERT_TRUE(scheduler()->IsBackingOff()); | 1449 ASSERT_TRUE(scheduler()->IsBackingOff()); |
| 1471 | 1450 |
| 1472 // Now succeed. | 1451 // Now succeed. |
| 1473 connection()->SetServerReachable(); | 1452 connection()->SetServerReachable(); |
| 1474 PumpLoopFor(2 * delta); | 1453 PumpLoopFor(2 * delta); |
| 1475 ASSERT_EQ(1, success_counter.times_called()); | 1454 ASSERT_EQ(1, success_counter.times_called()); |
| 1476 ASSERT_FALSE(scheduler()->IsBackingOff()); | 1455 ASSERT_FALSE(scheduler()->IsBackingOff()); |
| 1477 } | 1456 } |
| 1478 | 1457 |
| 1479 } // namespace syncer | 1458 } // namespace syncer |
| OLD | NEW |