Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(27)

Side by Side Diff: chrome/browser/sync/engine/syncer_thread_unittest.cc

Issue 194065: Initial commit of sync engine code to browser/sync.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Fixes to gtest include path, reverted syncapi. Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <list>
6 #include <map>
7 #include <set>
8 #include <strstream>
9
10 #include "base/scoped_ptr.h"
11 #include "chrome/browser/sync/engine/syncer_thread.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 namespace browser_sync {
15
16 class SyncerThreadTest : public testing::Test {
17 protected:
18 SyncerThreadTest() {}
19 virtual ~SyncerThreadTest() {}
20 virtual void SetUp() {}
21 virtual void TearDown() {}
22
23 private:
24 DISALLOW_COPY_AND_ASSIGN(SyncerThreadTest);
25 };
26
27 TEST_F(SyncerThreadTest, Construction) {
28 SyncerThread syncer_thread(NULL, NULL, NULL, NULL, NULL);
29 }
30
31 TEST_F(SyncerThreadTest, CalculateSyncWaitTime) {
32 SyncerThread syncer_thread(NULL, NULL, NULL, NULL, NULL);
33 syncer_thread.DisableIdleDetection();
34
35 // Syncer_polling_interval_ is less than max poll interval
36 int syncer_polling_interval = 1; // Needed since AssertionResult is not a
37 // friend of SyncerThread
38 syncer_thread.syncer_polling_interval_ = syncer_polling_interval;
39
40 // user_idle_ms is less than 10 * (syncer_polling_interval*1000).
41 ASSERT_EQ(syncer_polling_interval * 1000,
42 syncer_thread.CalculateSyncWaitTime(1000, 0));
43 ASSERT_EQ(syncer_polling_interval * 1000,
44 syncer_thread.CalculateSyncWaitTime(1000, 1));
45
46 // user_idle_ms is ge than 10 * (syncer_polling_interval*1000).
47 int last_poll_time = 2000;
48 ASSERT_LE(last_poll_time,
49 syncer_thread.CalculateSyncWaitTime(last_poll_time, 10000));
50 ASSERT_GE(last_poll_time*3,
51 syncer_thread.CalculateSyncWaitTime(last_poll_time, 10000));
52 ASSERT_LE(last_poll_time,
53 syncer_thread.CalculateSyncWaitTime(last_poll_time, 100000));
54 ASSERT_GE(last_poll_time*3,
55 syncer_thread.CalculateSyncWaitTime(last_poll_time, 100000));
56
57 // Maximum backoff time should be syncer_max_interval.
58 int near_threshold = SyncerThread::kDefaultMaxPollIntervalMs / 2 - 1;
59 int threshold = SyncerThread::kDefaultMaxPollIntervalMs;
60 int over_threshold = SyncerThread::kDefaultMaxPollIntervalMs + 1;
61 ASSERT_LE(near_threshold,
62 syncer_thread.CalculateSyncWaitTime(near_threshold, 10000));
63 ASSERT_GE(SyncerThread::kDefaultMaxPollIntervalMs,
64 syncer_thread.CalculateSyncWaitTime(near_threshold, 10000));
65 ASSERT_EQ(SyncerThread::kDefaultMaxPollIntervalMs,
66 syncer_thread.CalculateSyncWaitTime(threshold, 10000));
67 ASSERT_EQ(SyncerThread::kDefaultMaxPollIntervalMs,
68 syncer_thread.CalculateSyncWaitTime(over_threshold, 10000));
69
70 // Possible idle time must be capped by syncer_max_interval.
71 int over_sync_max_interval =
72 SyncerThread::kDefaultMaxPollIntervalMs + 1;
73 syncer_polling_interval = over_sync_max_interval / 100; // so 1000* is right
74 syncer_thread.syncer_polling_interval_ = syncer_polling_interval;
75 ASSERT_EQ(syncer_polling_interval * 1000,
76 syncer_thread.CalculateSyncWaitTime(1000, over_sync_max_interval));
77 syncer_polling_interval = 1;
78 syncer_thread.syncer_polling_interval_ = syncer_polling_interval;
79 ASSERT_LE(last_poll_time,
80 syncer_thread.CalculateSyncWaitTime(last_poll_time,
81 over_sync_max_interval));
82 ASSERT_GE(last_poll_time * 3,
83 syncer_thread.CalculateSyncWaitTime(last_poll_time,
84 over_sync_max_interval));
85 }
86
87 TEST_F(SyncerThreadTest, CalculatePollingWaitTime) {
88 // Set up the environment
89 int user_idle_milliseconds_param = 0;
90
91 SyncerThread syncer_thread(NULL, NULL, NULL, NULL, NULL);
92 syncer_thread.DisableIdleDetection();
93
94 // Notifications disabled should result in a polling interval of
95 // kDefaultShortPollInterval
96 {
97 AllStatus::Status status = {};
98 status.notifications_enabled = 0;
99 bool continue_sync_cycle_param = false;
100
101 // No work and no backoff.
102 ASSERT_EQ(SyncerThread::kDefaultShortPollIntervalSeconds,
103 syncer_thread.CalculatePollingWaitTime(
104 status,
105 0,
106 &user_idle_milliseconds_param,
107 &continue_sync_cycle_param));
108 ASSERT_FALSE(continue_sync_cycle_param);
109
110 // In this case the continue_sync_cycle is turned off.
111 continue_sync_cycle_param = true;
112 ASSERT_EQ(SyncerThread::kDefaultShortPollIntervalSeconds,
113 syncer_thread.CalculatePollingWaitTime(
114 status,
115 0,
116 &user_idle_milliseconds_param,
117 &continue_sync_cycle_param));
118 ASSERT_FALSE(continue_sync_cycle_param);
119
120 // TODO(brg) : Find a way to test exponential backoff is inoperable.
121 // Exponential backoff should be turned on when notifications are disabled
122 // but this can not be tested since we can not set the last input info.
123 }
124
125 // Notifications enabled should result in a polling interval of
126 // SyncerThread::kDefaultLongPollIntervalSeconds
127 {
128 AllStatus::Status status = {};
129 status.notifications_enabled = 1;
130 bool continue_sync_cycle_param = false;
131
132 // No work and no backoff.
133 ASSERT_EQ(SyncerThread::kDefaultLongPollIntervalSeconds,
134 syncer_thread.CalculatePollingWaitTime(
135 status,
136 0,
137 &user_idle_milliseconds_param,
138 &continue_sync_cycle_param));
139 ASSERT_FALSE(continue_sync_cycle_param);
140
141 // In this case the continue_sync_cycle is turned off.
142 continue_sync_cycle_param = true;
143 ASSERT_EQ(SyncerThread::kDefaultLongPollIntervalSeconds,
144 syncer_thread.CalculatePollingWaitTime(
145 status,
146 0,
147 &user_idle_milliseconds_param,
148 &continue_sync_cycle_param));
149 ASSERT_FALSE(continue_sync_cycle_param);
150
151 // TODO(brg) : Find a way to test exponential backoff.
152 // Exponential backoff should be turned off when notifications are enabled,
153 // but this can not be tested since we can not set the last input info.
154 }
155
156 // There are two states which can cause a continuation, either the updates
157 // available do not match the updates received, or the unsynced count is
158 // non-zero.
159 {
160 AllStatus::Status status = {};
161 status.updates_available = 1;
162 status.updates_received = 0;
163 bool continue_sync_cycle_param = false;
164
165 ASSERT_LE(0, syncer_thread.CalculatePollingWaitTime(
166 status,
167 0,
168 &user_idle_milliseconds_param,
169 &continue_sync_cycle_param));
170 ASSERT_TRUE(continue_sync_cycle_param);
171
172 continue_sync_cycle_param = false;
173 ASSERT_GE(3, syncer_thread.CalculatePollingWaitTime(
174 status,
175 0,
176 &user_idle_milliseconds_param,
177 &continue_sync_cycle_param));
178 ASSERT_TRUE(continue_sync_cycle_param);
179
180 ASSERT_LE(0, syncer_thread.CalculatePollingWaitTime(
181 status,
182 0,
183 &user_idle_milliseconds_param,
184 &continue_sync_cycle_param));
185 ASSERT_GE(2, syncer_thread.CalculatePollingWaitTime(
186 status,
187 0,
188 &user_idle_milliseconds_param,
189 &continue_sync_cycle_param));
190 ASSERT_TRUE(continue_sync_cycle_param);
191
192 status.updates_received = 1;
193 ASSERT_EQ(SyncerThread::kDefaultShortPollIntervalSeconds,
194 syncer_thread.CalculatePollingWaitTime(
195 status,
196 10,
197 &user_idle_milliseconds_param,
198 &continue_sync_cycle_param));
199 ASSERT_FALSE(continue_sync_cycle_param);
200 }
201
202 {
203 AllStatus::Status status = {};
204 status.unsynced_count = 1;
205 bool continue_sync_cycle_param = false;
206
207 ASSERT_LE(0, syncer_thread.CalculatePollingWaitTime(
208 status,
209 0,
210 &user_idle_milliseconds_param,
211 &continue_sync_cycle_param));
212 ASSERT_TRUE(continue_sync_cycle_param);
213
214 continue_sync_cycle_param = false;
215 ASSERT_GE(2, syncer_thread.CalculatePollingWaitTime(
216 status,
217 0,
218 &user_idle_milliseconds_param,
219 &continue_sync_cycle_param));
220 ASSERT_TRUE(continue_sync_cycle_param);
221
222 status.unsynced_count = 0;
223 ASSERT_EQ(SyncerThread::kDefaultShortPollIntervalSeconds,
224 syncer_thread.CalculatePollingWaitTime(
225 status,
226 4,
227 &user_idle_milliseconds_param,
228 &continue_sync_cycle_param));
229 ASSERT_FALSE(continue_sync_cycle_param);
230 }
231
232 // Regression for exponential backoff reset when the
233 // syncer is nudged.
234 {
235 AllStatus::Status status = {};
236 status.unsynced_count = 1;
237 bool continue_sync_cycle_param = false;
238
239 // Expect move from default polling interval to exponential backoff due to
240 // unsynced_count != 0.
241 ASSERT_LE(0, syncer_thread.CalculatePollingWaitTime(
242 status,
243 3600,
244 &user_idle_milliseconds_param,
245 &continue_sync_cycle_param));
246 ASSERT_TRUE(continue_sync_cycle_param);
247
248 continue_sync_cycle_param = false;
249 ASSERT_GE(2, syncer_thread.CalculatePollingWaitTime(
250 status,
251 3600,
252 &user_idle_milliseconds_param,
253 &continue_sync_cycle_param));
254 ASSERT_TRUE(continue_sync_cycle_param);
255
256 // Expect exponential backoff.
257 ASSERT_LE(2, syncer_thread.CalculatePollingWaitTime(
258 status,
259 2,
260 &user_idle_milliseconds_param,
261 &continue_sync_cycle_param));
262 ASSERT_GE(6, syncer_thread.CalculatePollingWaitTime(
263 status,
264 2,
265 &user_idle_milliseconds_param,
266 &continue_sync_cycle_param));
267 ASSERT_TRUE(continue_sync_cycle_param);
268
269 // A nudge resets the continue_sync_cycle_param value, so our backoff
270 // should return to the minimum.
271 continue_sync_cycle_param = false;
272 ASSERT_LE(0, syncer_thread.CalculatePollingWaitTime(
273 status,
274 3600,
275 &user_idle_milliseconds_param,
276 &continue_sync_cycle_param));
277 ASSERT_TRUE(continue_sync_cycle_param);
278
279 continue_sync_cycle_param = false;
280 ASSERT_GE(2, syncer_thread.CalculatePollingWaitTime(
281 status,
282 3600,
283 &user_idle_milliseconds_param,
284 &continue_sync_cycle_param));
285 ASSERT_TRUE(continue_sync_cycle_param);
286
287 // Setting unsynced_count = 0 returns us to the default polling interval.
288 status.unsynced_count = 0;
289 ASSERT_EQ(SyncerThread::kDefaultShortPollIntervalSeconds,
290 syncer_thread.CalculatePollingWaitTime(
291 status,
292 4,
293 &user_idle_milliseconds_param,
294 &continue_sync_cycle_param));
295 ASSERT_FALSE(continue_sync_cycle_param);
296 }
297 }
298
299 } // namespace browser_sync
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698