Chromium Code Reviews
Help | Chromium Project | Sign in
(956)

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

Issue 10917234: sync: make scheduling logic and job ownership more obvious. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address review Created 1 year, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 new SyncSchedulerImpl::WaitInterval( 85 new SyncSchedulerImpl::WaitInterval(
86 SyncSchedulerImpl::WaitInterval::EXPONENTIAL_BACKOFF, 86 SyncSchedulerImpl::WaitInterval::EXPONENTIAL_BACKOFF,
87 TimeDelta::FromSeconds(1))); 87 TimeDelta::FromSeconds(1)));
88 } 88 }
89 89
90 void SetWaitIntervalHadNudge(bool had_nudge) { 90 void SetWaitIntervalHadNudge(bool had_nudge) {
91 scheduler_->wait_interval_->had_nudge = had_nudge; 91 scheduler_->wait_interval_->had_nudge = had_nudge;
92 } 92 }
93 93
94 SyncSchedulerImpl::JobProcessDecision DecideOnJob( 94 SyncSchedulerImpl::JobProcessDecision DecideOnJob(
95 const SyncSchedulerImpl::SyncSessionJob& job) { 95 const SyncSessionJob* job) {
akalin 2012/10/26 06:52:29 const ref please
96 return scheduler_->DecideOnJob(job); 96 return scheduler_->DecideOnJob(*job);
97 } 97 }
98 98
99 void InitializeSyncerOnNormalMode() { 99 void InitializeSyncerOnNormalMode() {
100 SetMode(SyncScheduler::NORMAL_MODE); 100 SetMode(SyncScheduler::NORMAL_MODE);
101 ResetWaitInterval(); 101 ResetWaitInterval();
102 } 102 }
103 103
104 SyncSchedulerImpl::JobProcessDecision CreateAndDecideJob( 104 SyncSchedulerImpl::JobProcessDecision CreateAndDecideJob(
105 SyncSchedulerImpl::SyncSessionJob::SyncSessionJobPurpose purpose) { 105 SyncSessionJob::Purpose purpose) {
106 SyncSession* s = scheduler_->CreateSyncSession(SyncSourceInfo()); 106 scoped_ptr<SyncSession> s(scheduler_->CreateSyncSession(SyncSourceInfo()));
107 SyncSchedulerImpl::SyncSessionJob job(purpose, TimeTicks::Now(), 107 SyncSessionJob job(purpose, TimeTicks::Now(), s.Pass(),
108 make_linked_ptr(s), 108 ConfigurationParams(), FROM_HERE);
109 false, 109 return DecideOnJob(&job);
110 ConfigurationParams(),
111 FROM_HERE);
112 return DecideOnJob(job);
113 } 110 }
114 111
115 SyncSessionContext* context() { return context_.get(); } 112 SyncSessionContext* context() { return context_.get(); }
116 113
117 private: 114 private:
118 MessageLoop message_loop_; 115 MessageLoop message_loop_;
119 scoped_ptr<MockConnectionManager> connection_; 116 scoped_ptr<MockConnectionManager> connection_;
120 scoped_ptr<SyncSessionContext> context_; 117 scoped_ptr<SyncSessionContext> context_;
121 std::vector<scoped_refptr<FakeModelWorker> > workers_; 118 std::vector<scoped_refptr<FakeModelWorker> > workers_;
122 FakeExtensionsActivityMonitor extensions_activity_monitor_; 119 FakeExtensionsActivityMonitor extensions_activity_monitor_;
123 scoped_ptr<ThrottledDataTypeTracker> throttled_data_type_tracker_; 120 scoped_ptr<ThrottledDataTypeTracker> throttled_data_type_tracker_;
124 TestDirectorySetterUpper dir_maker_; 121 TestDirectorySetterUpper dir_maker_;
125 122
126 protected: 123 protected:
127 // Declared here to ensure it is destructed before the objects it references. 124 // Declared here to ensure it is destructed before the objects it references.
128 scoped_ptr<SyncSchedulerImpl> scheduler_; 125 scoped_ptr<SyncSchedulerImpl> scheduler_;
129 }; 126 };
130 127
131 TEST_F(SyncSchedulerWhiteboxTest, SaveNudge) { 128 TEST_F(SyncSchedulerWhiteboxTest, SaveNudge) {
132 InitializeSyncerOnNormalMode(); 129 InitializeSyncerOnNormalMode();
133 130
134 // Now set the mode to configure. 131 // Now set the mode to configure.
135 SetMode(SyncScheduler::CONFIGURATION_MODE); 132 SetMode(SyncScheduler::CONFIGURATION_MODE);
136 133
137 SyncSchedulerImpl::JobProcessDecision decision = 134 SyncSchedulerImpl::JobProcessDecision decision =
138 CreateAndDecideJob(SyncSchedulerImpl::SyncSessionJob::NUDGE); 135 CreateAndDecideJob(SyncSessionJob::NUDGE);
139 136
140 EXPECT_EQ(decision, SyncSchedulerImpl::SAVE); 137 EXPECT_EQ(decision, SyncSchedulerImpl::SAVE);
141 } 138 }
142 139
143 TEST_F(SyncSchedulerWhiteboxTest, SaveNudgeWhileTypeThrottled) { 140 TEST_F(SyncSchedulerWhiteboxTest, SaveNudgeWhileTypeThrottled) {
144 InitializeSyncerOnNormalMode(); 141 InitializeSyncerOnNormalMode();
145 142
146 const ModelTypeSet types(BOOKMARKS); 143 const ModelTypeSet types(BOOKMARKS);
147 144
148 // Mark bookmarks as throttled. 145 // Mark bookmarks as throttled.
149 context()->throttled_data_type_tracker()->SetUnthrottleTime( 146 context()->throttled_data_type_tracker()->SetUnthrottleTime(
150 types, base::TimeTicks::Now() + base::TimeDelta::FromHours(2)); 147 types, base::TimeTicks::Now() + base::TimeDelta::FromHours(2));
151 148
152 const ModelTypeInvalidationMap& invalidation_map = 149 const ModelTypeInvalidationMap& invalidation_map =
153 ModelTypeSetToInvalidationMap(types, std::string()); 150 ModelTypeSetToInvalidationMap(types, std::string());
154 151
155 SyncSourceInfo info(GetUpdatesCallerInfo::LOCAL, invalidation_map); 152 SyncSourceInfo info(GetUpdatesCallerInfo::LOCAL, invalidation_map);
156 SyncSession* s = scheduler_->CreateSyncSession(info); 153 scoped_ptr<SyncSession> s(scheduler_->CreateSyncSession(info));
157 154
158 // Now schedule a nudge with just bookmarks and the change is local. 155 // Now schedule a nudge with just bookmarks and the change is local.
159 SyncSchedulerImpl::SyncSessionJob job( 156 SyncSessionJob job(SyncSessionJob::NUDGE,
160 SyncSchedulerImpl::SyncSessionJob::NUDGE, 157 TimeTicks::Now(),
161 TimeTicks::Now(), 158 s.Pass(),
162 make_linked_ptr(s), 159 ConfigurationParams(),
163 false, 160 FROM_HERE);
164 ConfigurationParams(), 161 SyncSchedulerImpl::JobProcessDecision decision = DecideOnJob(&job);
165 FROM_HERE);
166
167 SyncSchedulerImpl::JobProcessDecision decision = DecideOnJob(job);
168 EXPECT_EQ(decision, SyncSchedulerImpl::SAVE); 162 EXPECT_EQ(decision, SyncSchedulerImpl::SAVE);
169 } 163 }
170 164
171 TEST_F(SyncSchedulerWhiteboxTest, ContinueNudge) { 165 TEST_F(SyncSchedulerWhiteboxTest, ContinueNudge) {
172 InitializeSyncerOnNormalMode(); 166 InitializeSyncerOnNormalMode();
173 167
174 SyncSchedulerImpl::JobProcessDecision decision = CreateAndDecideJob( 168 SyncSchedulerImpl::JobProcessDecision decision = CreateAndDecideJob(
175 SyncSchedulerImpl::SyncSessionJob::NUDGE); 169 SyncSessionJob::NUDGE);
176 170
177 EXPECT_EQ(decision, SyncSchedulerImpl::CONTINUE); 171 EXPECT_EQ(decision, SyncSchedulerImpl::CONTINUE);
178 } 172 }
179 173
180 TEST_F(SyncSchedulerWhiteboxTest, DropPoll) { 174 TEST_F(SyncSchedulerWhiteboxTest, DropPoll) {
181 InitializeSyncerOnNormalMode(); 175 InitializeSyncerOnNormalMode();
182 SetMode(SyncScheduler::CONFIGURATION_MODE); 176 SetMode(SyncScheduler::CONFIGURATION_MODE);
183 177
184 SyncSchedulerImpl::JobProcessDecision decision = CreateAndDecideJob( 178 SyncSchedulerImpl::JobProcessDecision decision = CreateAndDecideJob(
185 SyncSchedulerImpl::SyncSessionJob::POLL); 179 SyncSessionJob::POLL);
186 180
187 EXPECT_EQ(decision, SyncSchedulerImpl::DROP); 181 EXPECT_EQ(decision, SyncSchedulerImpl::DROP);
188 } 182 }
189 183
190 TEST_F(SyncSchedulerWhiteboxTest, ContinuePoll) { 184 TEST_F(SyncSchedulerWhiteboxTest, ContinuePoll) {
191 InitializeSyncerOnNormalMode(); 185 InitializeSyncerOnNormalMode();
192 186
193 SyncSchedulerImpl::JobProcessDecision decision = CreateAndDecideJob( 187 SyncSchedulerImpl::JobProcessDecision decision = CreateAndDecideJob(
194 SyncSchedulerImpl::SyncSessionJob::POLL); 188 SyncSessionJob::POLL);
195 189
196 EXPECT_EQ(decision, SyncSchedulerImpl::CONTINUE); 190 EXPECT_EQ(decision, SyncSchedulerImpl::CONTINUE);
197 } 191 }
198 192
199 TEST_F(SyncSchedulerWhiteboxTest, ContinueConfiguration) { 193 TEST_F(SyncSchedulerWhiteboxTest, ContinueConfiguration) {
200 InitializeSyncerOnNormalMode(); 194 InitializeSyncerOnNormalMode();
201 SetMode(SyncScheduler::CONFIGURATION_MODE); 195 SetMode(SyncScheduler::CONFIGURATION_MODE);
202 196
203 SyncSchedulerImpl::JobProcessDecision decision = CreateAndDecideJob( 197 SyncSchedulerImpl::JobProcessDecision decision = CreateAndDecideJob(
204 SyncSchedulerImpl::SyncSessionJob::CONFIGURATION); 198 SyncSessionJob::CONFIGURATION);
205 199
206 EXPECT_EQ(decision, SyncSchedulerImpl::CONTINUE); 200 EXPECT_EQ(decision, SyncSchedulerImpl::CONTINUE);
207 } 201 }
208 202
209 TEST_F(SyncSchedulerWhiteboxTest, SaveConfigurationWhileThrottled) { 203 TEST_F(SyncSchedulerWhiteboxTest, SaveConfigurationWhileThrottled) {
210 InitializeSyncerOnNormalMode(); 204 InitializeSyncerOnNormalMode();
211 SetMode(SyncScheduler::CONFIGURATION_MODE); 205 SetMode(SyncScheduler::CONFIGURATION_MODE);
212 206
213 SetWaitIntervalToThrottled(); 207 SetWaitIntervalToThrottled();
214 208
215 SyncSchedulerImpl::JobProcessDecision decision = CreateAndDecideJob( 209 SyncSchedulerImpl::JobProcessDecision decision = CreateAndDecideJob(
216 SyncSchedulerImpl::SyncSessionJob::CONFIGURATION); 210 SyncSessionJob::CONFIGURATION);
217 211
218 EXPECT_EQ(decision, SyncSchedulerImpl::SAVE); 212 EXPECT_EQ(decision, SyncSchedulerImpl::SAVE);
219 } 213 }
220 214
221 TEST_F(SyncSchedulerWhiteboxTest, SaveNudgeWhileThrottled) { 215 TEST_F(SyncSchedulerWhiteboxTest, SaveNudgeWhileThrottled) {
222 InitializeSyncerOnNormalMode(); 216 InitializeSyncerOnNormalMode();
223 SetMode(SyncScheduler::CONFIGURATION_MODE); 217 SetMode(SyncScheduler::CONFIGURATION_MODE);
224 218
225 SetWaitIntervalToThrottled(); 219 SetWaitIntervalToThrottled();
226 220
227 SyncSchedulerImpl::JobProcessDecision decision = CreateAndDecideJob( 221 SyncSchedulerImpl::JobProcessDecision decision = CreateAndDecideJob(
228 SyncSchedulerImpl::SyncSessionJob::NUDGE); 222 SyncSessionJob::NUDGE);
229 223
230 EXPECT_EQ(decision, SyncSchedulerImpl::SAVE); 224 EXPECT_EQ(decision, SyncSchedulerImpl::SAVE);
231 } 225 }
232 226
233 TEST_F(SyncSchedulerWhiteboxTest, ContinueNudgeWhileExponentialBackOff) { 227 TEST_F(SyncSchedulerWhiteboxTest, ContinueNudgeWhileExponentialBackOff) {
234 InitializeSyncerOnNormalMode(); 228 InitializeSyncerOnNormalMode();
235 SetMode(SyncScheduler::NORMAL_MODE); 229 SetMode(SyncScheduler::NORMAL_MODE);
236 SetWaitIntervalToExponentialBackoff(); 230 SetWaitIntervalToExponentialBackoff();
237 231
238 SyncSchedulerImpl::JobProcessDecision decision = CreateAndDecideJob( 232 SyncSchedulerImpl::JobProcessDecision decision = CreateAndDecideJob(
239 SyncSchedulerImpl::SyncSessionJob::NUDGE); 233 SyncSessionJob::NUDGE);
240 234
241 EXPECT_EQ(decision, SyncSchedulerImpl::CONTINUE); 235 EXPECT_EQ(decision, SyncSchedulerImpl::CONTINUE);
242 } 236 }
243 237
244 TEST_F(SyncSchedulerWhiteboxTest, DropNudgeWhileExponentialBackOff) { 238 TEST_F(SyncSchedulerWhiteboxTest, DropNudgeWhileExponentialBackOff) {
245 InitializeSyncerOnNormalMode(); 239 InitializeSyncerOnNormalMode();
246 SetMode(SyncScheduler::NORMAL_MODE); 240 SetMode(SyncScheduler::NORMAL_MODE);
247 SetWaitIntervalToExponentialBackoff(); 241 SetWaitIntervalToExponentialBackoff();
248 SetWaitIntervalHadNudge(true); 242 SetWaitIntervalHadNudge(true);
249 243
250 SyncSchedulerImpl::JobProcessDecision decision = CreateAndDecideJob( 244 SyncSchedulerImpl::JobProcessDecision decision = CreateAndDecideJob(
251 SyncSchedulerImpl::SyncSessionJob::NUDGE); 245 SyncSessionJob::NUDGE);
252 246
253 EXPECT_EQ(decision, SyncSchedulerImpl::DROP); 247 EXPECT_EQ(decision, SyncSchedulerImpl::DROP);
254 } 248 }
255 249
256 TEST_F(SyncSchedulerWhiteboxTest, ContinueCanaryJobConfig) { 250 TEST_F(SyncSchedulerWhiteboxTest, ContinueCanaryJobConfig) {
257 InitializeSyncerOnNormalMode(); 251 InitializeSyncerOnNormalMode();
258 SetMode(SyncScheduler::CONFIGURATION_MODE); 252 SetMode(SyncScheduler::CONFIGURATION_MODE);
259 SetWaitIntervalToExponentialBackoff(); 253 SetWaitIntervalToExponentialBackoff();
260 254
261 struct SyncSchedulerImpl::SyncSessionJob job; 255 SyncSessionJob job(SyncSessionJob::CONFIGURATION,
262 job.purpose = SyncSchedulerImpl::SyncSessionJob::CONFIGURATION; 256 TimeTicks::Now(), scoped_ptr<SyncSession>(),
263 job.scheduled_start = TimeTicks::Now(); 257 ConfigurationParams(), FROM_HERE);
264 job.is_canary_job = true; 258
265 SyncSchedulerImpl::JobProcessDecision decision = DecideOnJob(job); 259 job.GrantCanaryPrivilege();
260 SyncSchedulerImpl::JobProcessDecision decision = DecideOnJob(&job);
266 261
267 EXPECT_EQ(decision, SyncSchedulerImpl::CONTINUE); 262 EXPECT_EQ(decision, SyncSchedulerImpl::CONTINUE);
268 } 263 }
269 264
270 } // namespace syncer 265 } // namespace syncer
OLDNEW

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld 1280:2d3e6564b7b6