OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 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 <list> | 5 #include <list> |
6 #include <map> | 6 #include <map> |
7 | 7 |
8 #include "base/lock.h" | 8 #include "base/lock.h" |
9 #include "base/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
(...skipping 24 matching lines...) Expand all Loading... |
35 using sessions::SyncerStatus; | 35 using sessions::SyncerStatus; |
36 | 36 |
37 typedef testing::Test SyncerThreadTest; | 37 typedef testing::Test SyncerThreadTest; |
38 typedef SyncerThread::WaitInterval WaitInterval; | 38 typedef SyncerThread::WaitInterval WaitInterval; |
39 | 39 |
40 ACTION_P(SignalEvent, event) { | 40 ACTION_P(SignalEvent, event) { |
41 event->Signal(); | 41 event->Signal(); |
42 } | 42 } |
43 | 43 |
44 SyncSessionSnapshot SessionSnapshotForTest( | 44 SyncSessionSnapshot SessionSnapshotForTest( |
45 int64 num_server_changes_remaining, int64 max_local_timestamp, | 45 int64 num_server_changes_remaining, |
46 int64 unsynced_count) { | 46 int64 unsynced_count) { |
| 47 std::string download_progress_markers[syncable::MODEL_TYPE_COUNT]; |
| 48 for (int i = syncable::FIRST_REAL_MODEL_TYPE; |
| 49 i < syncable::MODEL_TYPE_COUNT; |
| 50 ++i) { |
| 51 syncable::ModelType type(syncable::ModelTypeFromInt(i)); |
| 52 sync_pb::DataTypeProgressMarker token; |
| 53 token.set_data_type_id( |
| 54 syncable::GetExtensionFieldNumberFromModelType(type)); |
| 55 token.set_token("foobar"); |
| 56 token.SerializeToString(&download_progress_markers[i]); |
| 57 } |
47 return SyncSessionSnapshot(SyncerStatus(), ErrorCounters(), | 58 return SyncSessionSnapshot(SyncerStatus(), ErrorCounters(), |
48 num_server_changes_remaining, max_local_timestamp, false, | 59 num_server_changes_remaining, false, |
49 syncable::ModelTypeBitSet(), false, false, unsynced_count, 0, false); | 60 syncable::ModelTypeBitSet(), download_progress_markers, |
| 61 false, false, unsynced_count, 0, false); |
50 } | 62 } |
51 | 63 |
52 class ListenerMock : public SyncEngineEventListener { | 64 class ListenerMock : public SyncEngineEventListener { |
53 public: | 65 public: |
54 MOCK_METHOD1(OnSyncEngineEvent, void(const SyncEngineEvent&)); | 66 MOCK_METHOD1(OnSyncEngineEvent, void(const SyncEngineEvent&)); |
55 }; | 67 }; |
56 | 68 |
57 class SyncerThreadWithSyncerTest : public testing::Test, | 69 class SyncerThreadWithSyncerTest : public testing::Test, |
58 public ModelSafeWorkerRegistrar, | 70 public ModelSafeWorkerRegistrar, |
59 public SyncEngineEventListener { | 71 public SyncEngineEventListener { |
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 ASSERT_EQ(WaitInterval::NORMAL, interval.mode); | 398 ASSERT_EQ(WaitInterval::NORMAL, interval.mode); |
387 ASSERT_FALSE(interval.had_nudge_during_backoff); | 399 ASSERT_FALSE(interval.had_nudge_during_backoff); |
388 ASSERT_FALSE(continue_sync_cycle_param); | 400 ASSERT_FALSE(continue_sync_cycle_param); |
389 } | 401 } |
390 | 402 |
391 // There are two states which can cause a continuation, either the updates | 403 // There are two states which can cause a continuation, either the updates |
392 // available do not match the updates received, or the unsynced count is | 404 // available do not match the updates received, or the unsynced count is |
393 // non-zero. | 405 // non-zero. |
394 { | 406 { |
395 // More server changes remaining to download. | 407 // More server changes remaining to download. |
396 context->set_last_snapshot(SessionSnapshotForTest(1, 0, 0)); | 408 context->set_last_snapshot(SessionSnapshotForTest(1, 0)); |
397 bool continue_sync_cycle_param = false; | 409 bool continue_sync_cycle_param = false; |
398 | 410 |
399 WaitInterval interval = syncer_thread->CalculatePollingWaitTime( | 411 WaitInterval interval = syncer_thread->CalculatePollingWaitTime( |
400 0, | 412 0, |
401 &user_idle_milliseconds_param, | 413 &user_idle_milliseconds_param, |
402 &continue_sync_cycle_param, | 414 &continue_sync_cycle_param, |
403 false); | 415 false); |
404 | 416 |
405 ASSERT_LE(0, interval.poll_delta.InSeconds()); | 417 ASSERT_LE(0, interval.poll_delta.InSeconds()); |
406 ASSERT_EQ(WaitInterval::NORMAL, interval.mode); | 418 ASSERT_EQ(WaitInterval::NORMAL, interval.mode); |
(...skipping 27 matching lines...) Expand all Loading... |
434 &user_idle_milliseconds_param, | 446 &user_idle_milliseconds_param, |
435 &continue_sync_cycle_param, | 447 &continue_sync_cycle_param, |
436 false); | 448 false); |
437 | 449 |
438 ASSERT_GE(2, interval.poll_delta.InSeconds()); | 450 ASSERT_GE(2, interval.poll_delta.InSeconds()); |
439 ASSERT_EQ(WaitInterval::EXPONENTIAL_BACKOFF, interval.mode); | 451 ASSERT_EQ(WaitInterval::EXPONENTIAL_BACKOFF, interval.mode); |
440 ASSERT_FALSE(interval.had_nudge_during_backoff); | 452 ASSERT_FALSE(interval.had_nudge_during_backoff); |
441 ASSERT_TRUE(continue_sync_cycle_param); | 453 ASSERT_TRUE(continue_sync_cycle_param); |
442 | 454 |
443 // Now simulate no more server changes remaining. | 455 // Now simulate no more server changes remaining. |
444 context->set_last_snapshot(SessionSnapshotForTest(1, 1, 0)); | 456 context->set_last_snapshot(SessionSnapshotForTest(0, 0)); |
445 interval = syncer_thread->CalculatePollingWaitTime( | 457 interval = syncer_thread->CalculatePollingWaitTime( |
446 0, | 458 0, |
447 &user_idle_milliseconds_param, | 459 &user_idle_milliseconds_param, |
448 &continue_sync_cycle_param, | 460 &continue_sync_cycle_param, |
449 false); | 461 false); |
450 | 462 |
451 ASSERT_EQ(SyncerThread::kDefaultLongPollIntervalSeconds, | 463 ASSERT_EQ(SyncerThread::kDefaultLongPollIntervalSeconds, |
452 interval.poll_delta.InSeconds()); | 464 interval.poll_delta.InSeconds()); |
453 ASSERT_EQ(WaitInterval::NORMAL, interval.mode); | 465 ASSERT_EQ(WaitInterval::NORMAL, interval.mode); |
454 ASSERT_FALSE(interval.had_nudge_during_backoff); | 466 ASSERT_FALSE(interval.had_nudge_during_backoff); |
455 ASSERT_FALSE(continue_sync_cycle_param); | 467 ASSERT_FALSE(continue_sync_cycle_param); |
456 } | 468 } |
457 | 469 |
458 { | 470 { |
459 | 471 |
460 // Now try with unsynced local items. | 472 // Now try with unsynced local items. |
461 context->set_last_snapshot(SessionSnapshotForTest(0, 0, 1)); | 473 context->set_last_snapshot(SessionSnapshotForTest(0, 1)); |
462 bool continue_sync_cycle_param = false; | 474 bool continue_sync_cycle_param = false; |
463 | 475 |
464 WaitInterval interval = syncer_thread->CalculatePollingWaitTime( | 476 WaitInterval interval = syncer_thread->CalculatePollingWaitTime( |
465 0, | 477 0, |
466 &user_idle_milliseconds_param, | 478 &user_idle_milliseconds_param, |
467 &continue_sync_cycle_param, | 479 &continue_sync_cycle_param, |
468 false); | 480 false); |
469 | 481 |
470 ASSERT_LE(0, interval.poll_delta.InSeconds()); | 482 ASSERT_LE(0, interval.poll_delta.InSeconds()); |
471 ASSERT_EQ(WaitInterval::NORMAL, interval.mode); | 483 ASSERT_EQ(WaitInterval::NORMAL, interval.mode); |
472 ASSERT_FALSE(interval.had_nudge_during_backoff); | 484 ASSERT_FALSE(interval.had_nudge_during_backoff); |
473 ASSERT_TRUE(continue_sync_cycle_param); | 485 ASSERT_TRUE(continue_sync_cycle_param); |
474 | 486 |
475 continue_sync_cycle_param = false; | 487 continue_sync_cycle_param = false; |
476 interval = syncer_thread->CalculatePollingWaitTime( | 488 interval = syncer_thread->CalculatePollingWaitTime( |
477 0, | 489 0, |
478 &user_idle_milliseconds_param, | 490 &user_idle_milliseconds_param, |
479 &continue_sync_cycle_param, | 491 &continue_sync_cycle_param, |
480 false); | 492 false); |
481 | 493 |
482 ASSERT_GE(2, interval.poll_delta.InSeconds()); | 494 ASSERT_GE(2, interval.poll_delta.InSeconds()); |
483 ASSERT_EQ(WaitInterval::NORMAL, interval.mode); | 495 ASSERT_EQ(WaitInterval::NORMAL, interval.mode); |
484 ASSERT_FALSE(interval.had_nudge_during_backoff); | 496 ASSERT_FALSE(interval.had_nudge_during_backoff); |
485 ASSERT_TRUE(continue_sync_cycle_param); | 497 ASSERT_TRUE(continue_sync_cycle_param); |
486 | 498 |
487 context->set_last_snapshot(SessionSnapshotForTest(0, 0, 0)); | 499 context->set_last_snapshot(SessionSnapshotForTest(0, 0)); |
488 interval = syncer_thread->CalculatePollingWaitTime( | 500 interval = syncer_thread->CalculatePollingWaitTime( |
489 4, | 501 4, |
490 &user_idle_milliseconds_param, | 502 &user_idle_milliseconds_param, |
491 &continue_sync_cycle_param, | 503 &continue_sync_cycle_param, |
492 false); | 504 false); |
493 | 505 |
494 ASSERT_EQ(SyncerThread::kDefaultLongPollIntervalSeconds, | 506 ASSERT_EQ(SyncerThread::kDefaultLongPollIntervalSeconds, |
495 interval.poll_delta.InSeconds()); | 507 interval.poll_delta.InSeconds()); |
496 ASSERT_EQ(WaitInterval::NORMAL, interval.mode); | 508 ASSERT_EQ(WaitInterval::NORMAL, interval.mode); |
497 ASSERT_FALSE(interval.had_nudge_during_backoff); | 509 ASSERT_FALSE(interval.had_nudge_during_backoff); |
498 ASSERT_FALSE(continue_sync_cycle_param); | 510 ASSERT_FALSE(continue_sync_cycle_param); |
499 } | 511 } |
500 | 512 |
501 // Regression for exponential backoff reset when the syncer is nudged. | 513 // Regression for exponential backoff reset when the syncer is nudged. |
502 { | 514 { |
503 | 515 |
504 context->set_last_snapshot(SessionSnapshotForTest(0, 0, 1)); | 516 context->set_last_snapshot(SessionSnapshotForTest(0, 1)); |
505 bool continue_sync_cycle_param = false; | 517 bool continue_sync_cycle_param = false; |
506 | 518 |
507 // Expect move from default polling interval to exponential backoff due to | 519 // Expect move from default polling interval to exponential backoff due to |
508 // unsynced_count != 0. | 520 // unsynced_count != 0. |
509 WaitInterval interval = syncer_thread->CalculatePollingWaitTime( | 521 WaitInterval interval = syncer_thread->CalculatePollingWaitTime( |
510 3600, | 522 3600, |
511 &user_idle_milliseconds_param, | 523 &user_idle_milliseconds_param, |
512 &continue_sync_cycle_param, | 524 &continue_sync_cycle_param, |
513 false); | 525 false); |
514 | 526 |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 &user_idle_milliseconds_param, | 628 &user_idle_milliseconds_param, |
617 &continue_sync_cycle_param, | 629 &continue_sync_cycle_param, |
618 true); | 630 true); |
619 | 631 |
620 ASSERT_GE(2, interval.poll_delta.InSeconds()); | 632 ASSERT_GE(2, interval.poll_delta.InSeconds()); |
621 ASSERT_EQ(WaitInterval::NORMAL, interval.mode); | 633 ASSERT_EQ(WaitInterval::NORMAL, interval.mode); |
622 ASSERT_FALSE(interval.had_nudge_during_backoff); | 634 ASSERT_FALSE(interval.had_nudge_during_backoff); |
623 ASSERT_TRUE(continue_sync_cycle_param); | 635 ASSERT_TRUE(continue_sync_cycle_param); |
624 | 636 |
625 // Setting unsynced_count = 0 returns us to the default polling interval. | 637 // Setting unsynced_count = 0 returns us to the default polling interval. |
626 context->set_last_snapshot(SessionSnapshotForTest(0, 0, 0)); | 638 context->set_last_snapshot(SessionSnapshotForTest(0, 0)); |
627 interval = syncer_thread->CalculatePollingWaitTime( | 639 interval = syncer_thread->CalculatePollingWaitTime( |
628 4, | 640 4, |
629 &user_idle_milliseconds_param, | 641 &user_idle_milliseconds_param, |
630 &continue_sync_cycle_param, | 642 &continue_sync_cycle_param, |
631 true); | 643 true); |
632 | 644 |
633 ASSERT_EQ(SyncerThread::kDefaultLongPollIntervalSeconds, | 645 ASSERT_EQ(SyncerThread::kDefaultLongPollIntervalSeconds, |
634 interval.poll_delta.InSeconds()); | 646 interval.poll_delta.InSeconds()); |
635 ASSERT_EQ(WaitInterval::NORMAL, interval.mode); | 647 ASSERT_EQ(WaitInterval::NORMAL, interval.mode); |
636 ASSERT_FALSE(interval.had_nudge_during_backoff); | 648 ASSERT_FALSE(interval.had_nudge_during_backoff); |
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1114 EXPECT_CALL(listener, OnSyncEngineEvent( | 1126 EXPECT_CALL(listener, OnSyncEngineEvent( |
1115 Field(&SyncEngineEvent::what_happened, | 1127 Field(&SyncEngineEvent::what_happened, |
1116 SyncEngineEvent::SYNCER_THREAD_EXITING))); | 1128 SyncEngineEvent::SYNCER_THREAD_EXITING))); |
1117 | 1129 |
1118 ASSERT_TRUE(Resume(&listener)); | 1130 ASSERT_TRUE(Resume(&listener)); |
1119 ASSERT_TRUE(sync_cycle_ended_event.TimedWait(max_wait_time_)); | 1131 ASSERT_TRUE(sync_cycle_ended_event.TimedWait(max_wait_time_)); |
1120 EXPECT_TRUE(syncer_thread()->Stop(2000)); | 1132 EXPECT_TRUE(syncer_thread()->Stop(2000)); |
1121 } | 1133 } |
1122 | 1134 |
1123 } // namespace browser_sync | 1135 } // namespace browser_sync |
OLD | NEW |