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 "sync/notifier/registration_manager.h" | 5 #include "sync/notifier/registration_manager.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <cstddef> | 9 #include <cstddef> |
10 #include <deque> | 10 #include <deque> |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 ++it) { | 165 ++it) { |
166 fake_invalidation_client_.LoseRegistration(*it); | 166 fake_invalidation_client_.LoseRegistration(*it); |
167 fake_registration_manager_.DisableId(*it); | 167 fake_registration_manager_.DisableId(*it); |
168 } | 168 } |
169 } | 169 } |
170 | 170 |
171 // Used by MarkRegistrationLostBackoff* tests. | 171 // Used by MarkRegistrationLostBackoff* tests. |
172 void RunBackoffTest(double jitter) { | 172 void RunBackoffTest(double jitter) { |
173 fake_registration_manager_.SetJitter(jitter); | 173 fake_registration_manager_.SetJitter(jitter); |
174 ObjectIdSet ids = GetSequenceOfIds(kObjectIdsCount); | 174 ObjectIdSet ids = GetSequenceOfIds(kObjectIdsCount); |
175 fake_registration_manager_.SetRegisteredIds(ids); | 175 fake_registration_manager_.UpdateRegisteredIds(ids); |
176 | 176 |
177 // Lose some ids. | 177 // Lose some ids. |
178 ObjectIdSet lost_ids = GetSequenceOfIds(2); | 178 ObjectIdSet lost_ids = GetSequenceOfIds(2); |
179 LoseRegistrations(lost_ids); | 179 LoseRegistrations(lost_ids); |
180 ExpectPendingRegistrations( | 180 ExpectPendingRegistrations( |
181 lost_ids, 0.0, | 181 lost_ids, 0.0, |
182 fake_registration_manager_.GetPendingRegistrationsForTest()); | 182 fake_registration_manager_.GetPendingRegistrationsForTest()); |
183 | 183 |
184 // Trigger another failure to start delaying. | 184 // Trigger another failure to start delaying. |
185 fake_registration_manager_.FirePendingRegistrationsForTest(); | 185 fake_registration_manager_.FirePendingRegistrationsForTest(); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 FakeInvalidationClient fake_invalidation_client_; | 223 FakeInvalidationClient fake_invalidation_client_; |
224 FakeRegistrationManager fake_registration_manager_; | 224 FakeRegistrationManager fake_registration_manager_; |
225 | 225 |
226 private: | 226 private: |
227 // Needed by timers in RegistrationManager. | 227 // Needed by timers in RegistrationManager. |
228 MessageLoop message_loop_; | 228 MessageLoop message_loop_; |
229 | 229 |
230 DISALLOW_COPY_AND_ASSIGN(RegistrationManagerTest); | 230 DISALLOW_COPY_AND_ASSIGN(RegistrationManagerTest); |
231 }; | 231 }; |
232 | 232 |
233 // Basic test of SetRegisteredIds to make sure we properly register new IDs and | 233 // Basic test of UpdateRegisteredIds to make sure we properly register |
234 // unregister any IDs no longer in the set. | 234 // new IDs and unregister any IDs no longer in the set. |
235 TEST_F(RegistrationManagerTest, SetRegisteredIds) { | 235 TEST_F(RegistrationManagerTest, UpdateRegisteredIds) { |
236 ObjectIdSet ids = GetSequenceOfIds(kObjectIdsCount - 1); | 236 ObjectIdSet ids = GetSequenceOfIds(kObjectIdsCount - 1); |
237 | 237 |
238 EXPECT_TRUE(fake_registration_manager_.GetRegisteredIdsForTest().empty()); | 238 EXPECT_TRUE(fake_registration_manager_.GetRegisteredIdsForTest().empty()); |
239 EXPECT_TRUE(fake_invalidation_client_.GetRegisteredIdsForTest().empty()); | 239 EXPECT_TRUE(fake_invalidation_client_.GetRegisteredIdsForTest().empty()); |
240 | 240 |
241 fake_registration_manager_.SetRegisteredIds(ids); | 241 fake_registration_manager_.UpdateRegisteredIds(ids); |
242 EXPECT_EQ(ids, fake_registration_manager_.GetRegisteredIdsForTest()); | 242 EXPECT_EQ(ids, fake_registration_manager_.GetRegisteredIdsForTest()); |
243 EXPECT_EQ(ids, fake_invalidation_client_.GetRegisteredIdsForTest()); | 243 EXPECT_EQ(ids, fake_invalidation_client_.GetRegisteredIdsForTest()); |
244 | 244 |
245 ids.insert(GetIdForIndex(kObjectIdsCount - 1)); | 245 ids.insert(GetIdForIndex(kObjectIdsCount - 1)); |
246 ids.erase(GetIdForIndex(kObjectIdsCount - 2)); | 246 ids.erase(GetIdForIndex(kObjectIdsCount - 2)); |
247 fake_registration_manager_.SetRegisteredIds(ids); | 247 fake_registration_manager_.UpdateRegisteredIds(ids); |
248 EXPECT_EQ(ids, fake_registration_manager_.GetRegisteredIdsForTest()); | 248 EXPECT_EQ(ids, fake_registration_manager_.GetRegisteredIdsForTest()); |
249 EXPECT_EQ(ids, fake_invalidation_client_.GetRegisteredIdsForTest()); | 249 EXPECT_EQ(ids, fake_invalidation_client_.GetRegisteredIdsForTest()); |
250 } | 250 } |
251 | 251 |
252 int GetRoundedBackoff(double retry_interval, double jitter) { | 252 int GetRoundedBackoff(double retry_interval, double jitter) { |
253 const double kInitialRetryInterval = 3.0; | 253 const double kInitialRetryInterval = 3.0; |
254 const double kMinRetryInterval = 2.0; | 254 const double kMinRetryInterval = 2.0; |
255 const double kMaxRetryInterval = 20.0; | 255 const double kMaxRetryInterval = 20.0; |
256 const double kBackoffExponent = 2.0; | 256 const double kBackoffExponent = 2.0; |
257 const double kMaxJitter = 0.5; | 257 const double kMaxJitter = 0.5; |
(...skipping 26 matching lines...) Expand all Loading... |
284 // Test ceiling. | 284 // Test ceiling. |
285 EXPECT_EQ(19, GetRoundedBackoff(13.0, -1.0)); | 285 EXPECT_EQ(19, GetRoundedBackoff(13.0, -1.0)); |
286 EXPECT_EQ(20, GetRoundedBackoff(13.0, 0.0)); | 286 EXPECT_EQ(20, GetRoundedBackoff(13.0, 0.0)); |
287 EXPECT_EQ(20, GetRoundedBackoff(13.0, +1.0)); | 287 EXPECT_EQ(20, GetRoundedBackoff(13.0, +1.0)); |
288 } | 288 } |
289 | 289 |
290 // Losing a registration should queue automatic re-registration. | 290 // Losing a registration should queue automatic re-registration. |
291 TEST_F(RegistrationManagerTest, MarkRegistrationLost) { | 291 TEST_F(RegistrationManagerTest, MarkRegistrationLost) { |
292 ObjectIdSet ids = GetSequenceOfIds(kObjectIdsCount); | 292 ObjectIdSet ids = GetSequenceOfIds(kObjectIdsCount); |
293 | 293 |
294 fake_registration_manager_.SetRegisteredIds(ids); | 294 fake_registration_manager_.UpdateRegisteredIds(ids); |
295 EXPECT_TRUE( | 295 EXPECT_TRUE( |
296 fake_registration_manager_.GetPendingRegistrationsForTest().empty()); | 296 fake_registration_manager_.GetPendingRegistrationsForTest().empty()); |
297 | 297 |
298 // Lose some ids. | 298 // Lose some ids. |
299 ObjectIdSet lost_ids = GetSequenceOfIds(3); | 299 ObjectIdSet lost_ids = GetSequenceOfIds(3); |
300 ObjectIdSet non_lost_ids = GetSequenceOfIdsStartingAt(3, kObjectIdsCount - 3); | 300 ObjectIdSet non_lost_ids = GetSequenceOfIdsStartingAt(3, kObjectIdsCount - 3); |
301 LoseRegistrations(lost_ids); | 301 LoseRegistrations(lost_ids); |
302 ExpectPendingRegistrations( | 302 ExpectPendingRegistrations( |
303 lost_ids, 0.0, | 303 lost_ids, 0.0, |
304 fake_registration_manager_.GetPendingRegistrationsForTest()); | 304 fake_registration_manager_.GetPendingRegistrationsForTest()); |
(...skipping 12 matching lines...) Expand all Loading... |
317 | 317 |
318 TEST_F(RegistrationManagerTest, MarkRegistrationLostBackoffMid) { | 318 TEST_F(RegistrationManagerTest, MarkRegistrationLostBackoffMid) { |
319 RunBackoffTest(0.0); | 319 RunBackoffTest(0.0); |
320 } | 320 } |
321 | 321 |
322 TEST_F(RegistrationManagerTest, MarkRegistrationLostBackoffHigh) { | 322 TEST_F(RegistrationManagerTest, MarkRegistrationLostBackoffHigh) { |
323 RunBackoffTest(+1.0); | 323 RunBackoffTest(+1.0); |
324 } | 324 } |
325 | 325 |
326 // Exponential backoff on lost registrations should be reset to zero if | 326 // Exponential backoff on lost registrations should be reset to zero if |
327 // SetRegisteredIds is called. | 327 // UpdateRegisteredIds is called. |
328 TEST_F(RegistrationManagerTest, MarkRegistrationLostBackoffReset) { | 328 TEST_F(RegistrationManagerTest, MarkRegistrationLostBackoffReset) { |
329 ObjectIdSet ids = GetSequenceOfIds(kObjectIdsCount); | 329 ObjectIdSet ids = GetSequenceOfIds(kObjectIdsCount); |
330 | 330 |
331 fake_registration_manager_.SetRegisteredIds(ids); | 331 fake_registration_manager_.UpdateRegisteredIds(ids); |
332 | 332 |
333 // Lose some ids. | 333 // Lose some ids. |
334 ObjectIdSet lost_ids = GetSequenceOfIds(2); | 334 ObjectIdSet lost_ids = GetSequenceOfIds(2); |
335 LoseRegistrations(lost_ids); | 335 LoseRegistrations(lost_ids); |
336 ExpectPendingRegistrations( | 336 ExpectPendingRegistrations( |
337 lost_ids, 0.0, | 337 lost_ids, 0.0, |
338 fake_registration_manager_.GetPendingRegistrationsForTest()); | 338 fake_registration_manager_.GetPendingRegistrationsForTest()); |
339 | 339 |
340 // Trigger another failure to start delaying. | 340 // Trigger another failure to start delaying. |
341 fake_registration_manager_.FirePendingRegistrationsForTest(); | 341 fake_registration_manager_.FirePendingRegistrationsForTest(); |
342 LoseRegistrations(lost_ids); | 342 LoseRegistrations(lost_ids); |
343 double expected_delay = | 343 double expected_delay = |
344 RegistrationManager::kInitialRegistrationDelaySeconds; | 344 RegistrationManager::kInitialRegistrationDelaySeconds; |
345 ExpectPendingRegistrations( | 345 ExpectPendingRegistrations( |
346 lost_ids, expected_delay, | 346 lost_ids, expected_delay, |
347 fake_registration_manager_.GetPendingRegistrationsForTest()); | 347 fake_registration_manager_.GetPendingRegistrationsForTest()); |
348 | 348 |
349 // Set ids again. | 349 // Set ids again. |
350 fake_registration_manager_.SetRegisteredIds(ids); | 350 fake_registration_manager_.UpdateRegisteredIds(ids); |
351 ExpectPendingRegistrations( | 351 ExpectPendingRegistrations( |
352 ObjectIdSet(), | 352 ObjectIdSet(), |
353 0.0, | 353 0.0, |
354 fake_registration_manager_.GetPendingRegistrationsForTest()); | 354 fake_registration_manager_.GetPendingRegistrationsForTest()); |
355 } | 355 } |
356 | 356 |
357 TEST_F(RegistrationManagerTest, MarkAllRegistrationsLost) { | 357 TEST_F(RegistrationManagerTest, MarkAllRegistrationsLost) { |
358 ObjectIdSet ids = GetSequenceOfIds(kObjectIdsCount); | 358 ObjectIdSet ids = GetSequenceOfIds(kObjectIdsCount); |
359 | 359 |
360 fake_registration_manager_.SetRegisteredIds(ids); | 360 fake_registration_manager_.UpdateRegisteredIds(ids); |
361 | 361 |
362 fake_invalidation_client_.LoseAllRegistrations(); | 362 fake_invalidation_client_.LoseAllRegistrations(); |
363 fake_registration_manager_.MarkAllRegistrationsLost(); | 363 fake_registration_manager_.MarkAllRegistrationsLost(); |
364 | 364 |
365 EXPECT_TRUE(fake_registration_manager_.GetRegisteredIdsForTest().empty()); | 365 EXPECT_TRUE(fake_registration_manager_.GetRegisteredIdsForTest().empty()); |
366 EXPECT_TRUE(fake_invalidation_client_.GetRegisteredIdsForTest().empty()); | 366 EXPECT_TRUE(fake_invalidation_client_.GetRegisteredIdsForTest().empty()); |
367 | 367 |
368 ExpectPendingRegistrations( | 368 ExpectPendingRegistrations( |
369 ids, 0.0, | 369 ids, 0.0, |
370 fake_registration_manager_.GetPendingRegistrationsForTest()); | 370 fake_registration_manager_.GetPendingRegistrationsForTest()); |
371 | 371 |
372 // Trigger another failure to start delaying. | 372 // Trigger another failure to start delaying. |
373 fake_registration_manager_.FirePendingRegistrationsForTest(); | 373 fake_registration_manager_.FirePendingRegistrationsForTest(); |
374 fake_invalidation_client_.LoseAllRegistrations(); | 374 fake_invalidation_client_.LoseAllRegistrations(); |
375 fake_registration_manager_.MarkAllRegistrationsLost(); | 375 fake_registration_manager_.MarkAllRegistrationsLost(); |
376 double expected_delay = | 376 double expected_delay = |
377 RegistrationManager::kInitialRegistrationDelaySeconds; | 377 RegistrationManager::kInitialRegistrationDelaySeconds; |
378 ExpectPendingRegistrations( | 378 ExpectPendingRegistrations( |
379 ids, expected_delay, | 379 ids, expected_delay, |
380 fake_registration_manager_.GetPendingRegistrationsForTest()); | 380 fake_registration_manager_.GetPendingRegistrationsForTest()); |
381 | 381 |
382 // Pretend we waited long enough to re-register. | 382 // Pretend we waited long enough to re-register. |
383 fake_registration_manager_.FirePendingRegistrationsForTest(); | 383 fake_registration_manager_.FirePendingRegistrationsForTest(); |
384 EXPECT_EQ(ids, fake_registration_manager_.GetRegisteredIdsForTest()); | 384 EXPECT_EQ(ids, fake_registration_manager_.GetRegisteredIdsForTest()); |
385 EXPECT_EQ(ids, fake_invalidation_client_.GetRegisteredIdsForTest()); | 385 EXPECT_EQ(ids, fake_invalidation_client_.GetRegisteredIdsForTest()); |
386 } | 386 } |
387 | 387 |
388 // IDs that are disabled should not be re-registered by SetRegisteredIds or | 388 // IDs that are disabled should not be re-registered by UpdateRegisteredIds or |
389 // automatic re-registration if that registration is lost. | 389 // automatic re-registration if that registration is lost. |
390 TEST_F(RegistrationManagerTest, DisableId) { | 390 TEST_F(RegistrationManagerTest, DisableId) { |
391 ObjectIdSet ids = GetSequenceOfIds(kObjectIdsCount); | 391 ObjectIdSet ids = GetSequenceOfIds(kObjectIdsCount); |
392 | 392 |
393 fake_registration_manager_.SetRegisteredIds(ids); | 393 fake_registration_manager_.UpdateRegisteredIds(ids); |
394 EXPECT_TRUE( | 394 EXPECT_TRUE( |
395 fake_registration_manager_.GetPendingRegistrationsForTest().empty()); | 395 fake_registration_manager_.GetPendingRegistrationsForTest().empty()); |
396 | 396 |
397 // Disable some ids. | 397 // Disable some ids. |
398 ObjectIdSet disabled_ids = GetSequenceOfIds(3); | 398 ObjectIdSet disabled_ids = GetSequenceOfIds(3); |
399 ObjectIdSet enabled_ids = GetSequenceOfIdsStartingAt(3, kObjectIdsCount - 3); | 399 ObjectIdSet enabled_ids = GetSequenceOfIdsStartingAt(3, kObjectIdsCount - 3); |
400 DisableIds(disabled_ids); | 400 DisableIds(disabled_ids); |
401 ExpectPendingRegistrations( | 401 ExpectPendingRegistrations( |
402 ObjectIdSet(), | 402 ObjectIdSet(), |
403 0.0, | 403 0.0, |
404 fake_registration_manager_.GetPendingRegistrationsForTest()); | 404 fake_registration_manager_.GetPendingRegistrationsForTest()); |
405 EXPECT_EQ(enabled_ids, fake_registration_manager_.GetRegisteredIdsForTest()); | 405 EXPECT_EQ(enabled_ids, fake_registration_manager_.GetRegisteredIdsForTest()); |
406 EXPECT_EQ(enabled_ids, fake_invalidation_client_.GetRegisteredIdsForTest()); | 406 EXPECT_EQ(enabled_ids, fake_invalidation_client_.GetRegisteredIdsForTest()); |
407 | 407 |
408 fake_registration_manager_.SetRegisteredIds(ids); | 408 fake_registration_manager_.UpdateRegisteredIds(ids); |
409 EXPECT_EQ(enabled_ids, fake_registration_manager_.GetRegisteredIdsForTest()); | 409 EXPECT_EQ(enabled_ids, fake_registration_manager_.GetRegisteredIdsForTest()); |
410 | 410 |
411 fake_registration_manager_.MarkRegistrationLost( | 411 fake_registration_manager_.MarkRegistrationLost( |
412 *disabled_ids.begin()); | 412 *disabled_ids.begin()); |
413 ExpectPendingRegistrations( | 413 ExpectPendingRegistrations( |
414 ObjectIdSet(), | 414 ObjectIdSet(), |
415 0.0, | 415 0.0, |
416 fake_registration_manager_.GetPendingRegistrationsForTest()); | 416 fake_registration_manager_.GetPendingRegistrationsForTest()); |
417 | 417 |
418 fake_registration_manager_.MarkAllRegistrationsLost(); | 418 fake_registration_manager_.MarkAllRegistrationsLost(); |
419 ExpectPendingRegistrations( | 419 ExpectPendingRegistrations( |
420 enabled_ids, 0.0, | 420 enabled_ids, 0.0, |
421 fake_registration_manager_.GetPendingRegistrationsForTest()); | 421 fake_registration_manager_.GetPendingRegistrationsForTest()); |
422 } | 422 } |
423 | 423 |
424 } // namespace | 424 } // namespace |
425 } // namespace syncer | 425 } // namespace syncer |
OLD | NEW |