| 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 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 false); | 449 false); |
| 450 | 450 |
| 451 ASSERT_EQ(SyncerThread::kDefaultLongPollIntervalSeconds, | 451 ASSERT_EQ(SyncerThread::kDefaultLongPollIntervalSeconds, |
| 452 interval.poll_delta.InSeconds()); | 452 interval.poll_delta.InSeconds()); |
| 453 ASSERT_EQ(WaitInterval::NORMAL, interval.mode); | 453 ASSERT_EQ(WaitInterval::NORMAL, interval.mode); |
| 454 ASSERT_FALSE(interval.had_nudge_during_backoff); | 454 ASSERT_FALSE(interval.had_nudge_during_backoff); |
| 455 ASSERT_FALSE(continue_sync_cycle_param); | 455 ASSERT_FALSE(continue_sync_cycle_param); |
| 456 } | 456 } |
| 457 | 457 |
| 458 { | 458 { |
| 459 | |
| 460 // Now try with unsynced local items. | 459 // Now try with unsynced local items. |
| 461 context->set_last_snapshot(SessionSnapshotForTest(0, 0, 1)); | 460 context->set_last_snapshot(SessionSnapshotForTest(0, 0, 1)); |
| 462 bool continue_sync_cycle_param = false; | 461 bool continue_sync_cycle_param = false; |
| 463 | 462 |
| 464 WaitInterval interval = syncer_thread->CalculatePollingWaitTime( | 463 WaitInterval interval = syncer_thread->CalculatePollingWaitTime( |
| 465 0, | 464 0, |
| 466 &user_idle_milliseconds_param, | 465 &user_idle_milliseconds_param, |
| 467 &continue_sync_cycle_param, | 466 &continue_sync_cycle_param, |
| 468 false); | 467 false); |
| 469 | 468 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 493 | 492 |
| 494 ASSERT_EQ(SyncerThread::kDefaultLongPollIntervalSeconds, | 493 ASSERT_EQ(SyncerThread::kDefaultLongPollIntervalSeconds, |
| 495 interval.poll_delta.InSeconds()); | 494 interval.poll_delta.InSeconds()); |
| 496 ASSERT_EQ(WaitInterval::NORMAL, interval.mode); | 495 ASSERT_EQ(WaitInterval::NORMAL, interval.mode); |
| 497 ASSERT_FALSE(interval.had_nudge_during_backoff); | 496 ASSERT_FALSE(interval.had_nudge_during_backoff); |
| 498 ASSERT_FALSE(continue_sync_cycle_param); | 497 ASSERT_FALSE(continue_sync_cycle_param); |
| 499 } | 498 } |
| 500 | 499 |
| 501 // Regression for exponential backoff reset when the syncer is nudged. | 500 // Regression for exponential backoff reset when the syncer is nudged. |
| 502 { | 501 { |
| 503 | |
| 504 context->set_last_snapshot(SessionSnapshotForTest(0, 0, 1)); | 502 context->set_last_snapshot(SessionSnapshotForTest(0, 0, 1)); |
| 505 bool continue_sync_cycle_param = false; | 503 bool continue_sync_cycle_param = false; |
| 506 | 504 |
| 507 // Expect move from default polling interval to exponential backoff due to | 505 // Expect move from default polling interval to exponential backoff due to |
| 508 // unsynced_count != 0. | 506 // unsynced_count != 0. |
| 509 WaitInterval interval = syncer_thread->CalculatePollingWaitTime( | 507 WaitInterval interval = syncer_thread->CalculatePollingWaitTime( |
| 510 3600, | 508 3600, |
| 511 &user_idle_milliseconds_param, | 509 &user_idle_milliseconds_param, |
| 512 &continue_sync_cycle_param, | 510 &continue_sync_cycle_param, |
| 513 false); | 511 false); |
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 771 | 769 |
| 772 interceptor.WaitForSyncShare(1, TimeDelta::FromSeconds(1)); | 770 interceptor.WaitForSyncShare(1, TimeDelta::FromSeconds(1)); |
| 773 EXPECT_EQ(static_cast<unsigned int>(2), | 771 EXPECT_EQ(static_cast<unsigned int>(2), |
| 774 interceptor.times_sync_occured().size()); | 772 interceptor.times_sync_occured().size()); |
| 775 | 773 |
| 776 // SyncerThread should be waiting again. Signal it to stop. | 774 // SyncerThread should be waiting again. Signal it to stop. |
| 777 EXPECT_TRUE(syncer_thread()->Stop(2000)); | 775 EXPECT_TRUE(syncer_thread()->Stop(2000)); |
| 778 EXPECT_TRUE(syncer_thread()->vault_.pending_nudge_types_.none()); | 776 EXPECT_TRUE(syncer_thread()->vault_.pending_nudge_types_.none()); |
| 779 } | 777 } |
| 780 | 778 |
| 779 TEST_F(SyncerThreadWithSyncerTest, NudgeWithPayloads) { |
| 780 SyncShareIntercept interceptor; |
| 781 connection()->SetMidCommitObserver(&interceptor); |
| 782 // We don't want a poll to happen during this test (except the first one). |
| 783 PreventThreadFromPolling(); |
| 784 EXPECT_TRUE(syncer_thread()->Start()); |
| 785 metadb()->Open(); |
| 786 syncer_thread()->CreateSyncer(metadb()->name()); |
| 787 const TimeDelta poll_interval = TimeDelta::FromMinutes(5); |
| 788 interceptor.WaitForSyncShare(1, poll_interval + poll_interval); |
| 789 EXPECT_EQ(static_cast<unsigned int>(1), |
| 790 interceptor.times_sync_occured().size()); |
| 791 |
| 792 // The SyncerThread should be waiting for the poll now. Nudge it to sync |
| 793 // immediately (5ms). |
| 794 std::vector<std::string> payloads(syncable::MODEL_TYPE_COUNT); |
| 795 payloads[syncable::BOOKMARKS] = "test"; |
| 796 |
| 797 // Paused so we can verify the nudge types safely. |
| 798 syncer_thread()->RequestPause(); |
| 799 syncer_thread()->NudgeSyncerWithPayloads(5, |
| 800 SyncerThread::kUnknown, |
| 801 payloads); |
| 802 EXPECT_EQ(payloads, syncer_thread()->vault_.datatype_payloads_); |
| 803 syncable::ModelTypeBitSet model_types; |
| 804 model_types[syncable::BOOKMARKS] = true; |
| 805 EXPECT_EQ(model_types, syncer_thread()->vault_.pending_nudge_types_); |
| 806 syncer_thread()->RequestResume(); |
| 807 |
| 808 interceptor.WaitForSyncShare(1, TimeDelta::FromSeconds(1)); |
| 809 EXPECT_EQ(static_cast<unsigned int>(2), |
| 810 interceptor.times_sync_occured().size()); |
| 811 |
| 812 // SyncerThread should be waiting again. Signal it to stop. |
| 813 EXPECT_TRUE(syncer_thread()->Stop(2000)); |
| 814 EXPECT_TRUE(syncer_thread()->vault_.pending_nudge_types_.none()); |
| 815 EXPECT_TRUE(syncer_thread()->vault_.datatype_payloads_.empty()); |
| 816 } |
| 817 |
| 818 TEST_F(SyncerThreadWithSyncerTest, NudgeWithPayloadsCoalesced) { |
| 819 SyncShareIntercept interceptor; |
| 820 connection()->SetMidCommitObserver(&interceptor); |
| 821 // We don't want a poll to happen during this test (except the first one). |
| 822 PreventThreadFromPolling(); |
| 823 EXPECT_TRUE(syncer_thread()->Start()); |
| 824 metadb()->Open(); |
| 825 syncer_thread()->CreateSyncer(metadb()->name()); |
| 826 const TimeDelta poll_interval = TimeDelta::FromMinutes(5); |
| 827 interceptor.WaitForSyncShare(1, poll_interval + poll_interval); |
| 828 EXPECT_EQ(static_cast<unsigned int>(1), |
| 829 interceptor.times_sync_occured().size()); |
| 830 |
| 831 // The SyncerThread should be waiting for the poll now. Nudge it to sync |
| 832 // immediately (5ms). |
| 833 std::vector<std::string> payloads(syncable::MODEL_TYPE_COUNT); |
| 834 payloads[syncable::BOOKMARKS] = "books"; |
| 835 syncable::ModelTypeBitSet model_types; |
| 836 model_types[syncable::BOOKMARKS] = true; |
| 837 |
| 838 // Paused so we can verify the nudge types safely. |
| 839 syncer_thread()->RequestPause(); |
| 840 syncer_thread()->NudgeSyncerWithPayloads(100, |
| 841 SyncerThread::kUnknown, |
| 842 payloads); |
| 843 EXPECT_EQ(model_types, syncer_thread()->vault_.pending_nudge_types_); |
| 844 EXPECT_EQ(payloads, syncer_thread()->vault_.datatype_payloads_); |
| 845 |
| 846 payloads[syncable::BOOKMARKS] = ""; |
| 847 payloads[syncable::AUTOFILL] = "auto"; |
| 848 model_types[syncable::AUTOFILL] = true; |
| 849 syncer_thread()->NudgeSyncerWithPayloads(0, |
| 850 SyncerThread::kUnknown, |
| 851 payloads); |
| 852 |
| 853 // Reset BOOKMARKS for expectations. |
| 854 payloads[syncable::BOOKMARKS] = "books"; |
| 855 EXPECT_EQ(model_types, syncer_thread()->vault_.pending_nudge_types_); |
| 856 EXPECT_EQ(payloads, syncer_thread()->vault_.datatype_payloads_); |
| 857 |
| 858 syncer_thread()->RequestResume(); |
| 859 |
| 860 interceptor.WaitForSyncShare(1, TimeDelta::FromSeconds(1)); |
| 861 EXPECT_EQ(static_cast<unsigned int>(2), |
| 862 interceptor.times_sync_occured().size()); |
| 863 |
| 864 // SyncerThread should be waiting again. Signal it to stop. |
| 865 EXPECT_TRUE(syncer_thread()->Stop(2000)); |
| 866 EXPECT_TRUE(syncer_thread()->vault_.pending_nudge_types_.none()); |
| 867 EXPECT_TRUE(syncer_thread()->vault_.datatype_payloads_.empty()); |
| 868 } |
| 869 |
| 781 TEST_F(SyncerThreadWithSyncerTest, Throttling) { | 870 TEST_F(SyncerThreadWithSyncerTest, Throttling) { |
| 782 SyncShareIntercept interceptor; | 871 SyncShareIntercept interceptor; |
| 783 connection()->SetMidCommitObserver(&interceptor); | 872 connection()->SetMidCommitObserver(&interceptor); |
| 784 const TimeDelta poll_interval = TimeDelta::FromMilliseconds(10); | 873 const TimeDelta poll_interval = TimeDelta::FromMilliseconds(10); |
| 785 syncer_thread()->SetSyncerShortPollInterval(poll_interval); | 874 syncer_thread()->SetSyncerShortPollInterval(poll_interval); |
| 786 | 875 |
| 787 EXPECT_TRUE(syncer_thread()->Start()); | 876 EXPECT_TRUE(syncer_thread()->Start()); |
| 788 metadb()->Open(); | 877 metadb()->Open(); |
| 789 syncer_thread()->CreateSyncer(metadb()->name()); | 878 syncer_thread()->CreateSyncer(metadb()->name()); |
| 790 | 879 |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1114 EXPECT_CALL(listener, OnSyncEngineEvent( | 1203 EXPECT_CALL(listener, OnSyncEngineEvent( |
| 1115 Field(&SyncEngineEvent::what_happened, | 1204 Field(&SyncEngineEvent::what_happened, |
| 1116 SyncEngineEvent::SYNCER_THREAD_EXITING))); | 1205 SyncEngineEvent::SYNCER_THREAD_EXITING))); |
| 1117 | 1206 |
| 1118 ASSERT_TRUE(Resume(&listener)); | 1207 ASSERT_TRUE(Resume(&listener)); |
| 1119 ASSERT_TRUE(sync_cycle_ended_event.TimedWait(max_wait_time_)); | 1208 ASSERT_TRUE(sync_cycle_ended_event.TimedWait(max_wait_time_)); |
| 1120 EXPECT_TRUE(syncer_thread()->Stop(2000)); | 1209 EXPECT_TRUE(syncer_thread()->Stop(2000)); |
| 1121 } | 1210 } |
| 1122 | 1211 |
| 1123 } // namespace browser_sync | 1212 } // namespace browser_sync |
| OLD | NEW |