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/message_loop.h" | 5 #include "base/message_loop.h" |
6 #include "base/time.h" | 6 #include "base/time.h" |
7 #include "sync/engine/backoff_delay_provider.h" | 7 #include "sync/engine/backoff_delay_provider.h" |
8 #include "sync/engine/sync_scheduler_impl.h" | 8 #include "sync/engine/sync_scheduler_impl.h" |
9 #include "sync/engine/throttled_data_type_tracker.h" | 9 #include "sync/engine/throttled_data_type_tracker.h" |
10 #include "sync/internal_api/public/engine/polling_constants.h" | 10 #include "sync/internal_api/public/engine/polling_constants.h" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 SyncSchedulerImpl::WaitInterval::THROTTLED, TimeDelta::FromSeconds(1))); | 81 SyncSchedulerImpl::WaitInterval::THROTTLED, TimeDelta::FromSeconds(1))); |
82 } | 82 } |
83 | 83 |
84 void SetWaitIntervalToExponentialBackoff() { | 84 void SetWaitIntervalToExponentialBackoff() { |
85 scheduler_->wait_interval_.reset( | 85 scheduler_->wait_interval_.reset( |
86 new SyncSchedulerImpl::WaitInterval( | 86 new SyncSchedulerImpl::WaitInterval( |
87 SyncSchedulerImpl::WaitInterval::EXPONENTIAL_BACKOFF, | 87 SyncSchedulerImpl::WaitInterval::EXPONENTIAL_BACKOFF, |
88 TimeDelta::FromSeconds(1))); | 88 TimeDelta::FromSeconds(1))); |
89 } | 89 } |
90 | 90 |
91 void SetWaitIntervalHadNudge(bool had_nudge) { | |
92 scheduler_->wait_interval_->had_nudge = had_nudge; | |
93 } | |
94 | |
95 SyncSchedulerImpl::JobProcessDecision DecideOnJob( | 91 SyncSchedulerImpl::JobProcessDecision DecideOnJob( |
96 const SyncSessionJob& job, | 92 const SyncSessionJob& job, |
97 SyncSchedulerImpl::JobPriority priority) { | 93 SyncSchedulerImpl::JobPriority priority) { |
98 return scheduler_->DecideOnJob(job, priority); | 94 return scheduler_->DecideOnJob(job, priority); |
99 } | 95 } |
100 | 96 |
101 void InitializeSyncerOnNormalMode() { | 97 void InitializeSyncerOnNormalMode() { |
102 SetMode(SyncScheduler::NORMAL_MODE); | 98 SetMode(SyncScheduler::NORMAL_MODE); |
103 ResetWaitInterval(); | 99 ResetWaitInterval(); |
104 } | 100 } |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 SetMode(SyncScheduler::CONFIGURATION_MODE); | 222 SetMode(SyncScheduler::CONFIGURATION_MODE); |
227 | 223 |
228 SetWaitIntervalToThrottled(); | 224 SetWaitIntervalToThrottled(); |
229 | 225 |
230 SyncSchedulerImpl::JobProcessDecision decision = CreateAndDecideJob( | 226 SyncSchedulerImpl::JobProcessDecision decision = CreateAndDecideJob( |
231 SyncSessionJob::NUDGE); | 227 SyncSessionJob::NUDGE); |
232 | 228 |
233 EXPECT_EQ(decision, SyncSchedulerImpl::SAVE); | 229 EXPECT_EQ(decision, SyncSchedulerImpl::SAVE); |
234 } | 230 } |
235 | 231 |
236 TEST_F(SyncSchedulerWhiteboxTest, ContinueNudgeWhileExponentialBackOff) { | 232 TEST_F(SyncSchedulerWhiteboxTest, DropNudgeWhileExponentialBackOff) { |
237 InitializeSyncerOnNormalMode(); | 233 InitializeSyncerOnNormalMode(); |
238 SetMode(SyncScheduler::NORMAL_MODE); | 234 SetMode(SyncScheduler::NORMAL_MODE); |
239 SetWaitIntervalToExponentialBackoff(); | 235 SetWaitIntervalToExponentialBackoff(); |
240 | 236 |
241 SyncSchedulerImpl::JobProcessDecision decision = CreateAndDecideJob( | 237 SyncSchedulerImpl::JobProcessDecision decision = CreateAndDecideJob( |
242 SyncSessionJob::NUDGE); | 238 SyncSessionJob::NUDGE); |
243 | |
244 EXPECT_EQ(decision, SyncSchedulerImpl::CONTINUE); | |
245 } | |
246 | |
247 TEST_F(SyncSchedulerWhiteboxTest, DropNudgeWhileExponentialBackOff) { | |
248 InitializeSyncerOnNormalMode(); | |
249 SetMode(SyncScheduler::NORMAL_MODE); | |
250 SetWaitIntervalToExponentialBackoff(); | |
251 SetWaitIntervalHadNudge(true); | |
252 | |
253 SyncSchedulerImpl::JobProcessDecision decision = CreateAndDecideJob( | |
254 SyncSessionJob::NUDGE); | |
255 | 239 |
256 EXPECT_EQ(decision, SyncSchedulerImpl::DROP); | 240 EXPECT_EQ(decision, SyncSchedulerImpl::DROP); |
257 } | 241 } |
258 | 242 |
259 TEST_F(SyncSchedulerWhiteboxTest, ContinueCanaryJobConfig) { | 243 TEST_F(SyncSchedulerWhiteboxTest, ContinueCanaryJobConfig) { |
260 InitializeSyncerOnNormalMode(); | 244 InitializeSyncerOnNormalMode(); |
261 SetMode(SyncScheduler::CONFIGURATION_MODE); | 245 SetMode(SyncScheduler::CONFIGURATION_MODE); |
262 SetWaitIntervalToExponentialBackoff(); | 246 SetWaitIntervalToExponentialBackoff(); |
263 | 247 |
264 SyncSessionJob job(SyncSessionJob::CONFIGURATION, | 248 SyncSessionJob job(SyncSessionJob::CONFIGURATION, |
265 TimeTicks::Now(), SyncSourceInfo(), | 249 TimeTicks::Now(), SyncSourceInfo(), |
266 ConfigurationParams()); | 250 ConfigurationParams()); |
267 | 251 |
268 SyncSchedulerImpl::JobProcessDecision decision = | 252 SyncSchedulerImpl::JobProcessDecision decision = |
269 DecideOnJob(job, SyncSchedulerImpl::CANARY_PRIORITY); | 253 DecideOnJob(job, SyncSchedulerImpl::CANARY_PRIORITY); |
270 | 254 |
271 EXPECT_EQ(decision, SyncSchedulerImpl::CONTINUE); | 255 EXPECT_EQ(decision, SyncSchedulerImpl::CONTINUE); |
272 } | 256 } |
273 | 257 |
274 } // namespace syncer | 258 } // namespace syncer |
OLD | NEW |