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

Side by Side Diff: components/sync/engine_impl/syncer_unittest.cc

Issue 2475043002: [Sync] Sync client should to exponential backoff when receive partial failure (Closed)
Patch Set: fix backoff problem Created 4 years, 1 month 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
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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 "components/sync/engine_impl/syncer.h" 5 #include "components/sync/engine_impl/syncer.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <limits> 10 #include <limits>
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 last_client_invalidation_hint_buffer_size_(10) {} 182 last_client_invalidation_hint_buffer_size_(10) {}
183 183
184 // SyncCycle::Delegate implementation. 184 // SyncCycle::Delegate implementation.
185 void OnThrottled(const base::TimeDelta& throttle_duration) override { 185 void OnThrottled(const base::TimeDelta& throttle_duration) override {
186 FAIL() << "Should not get silenced."; 186 FAIL() << "Should not get silenced.";
187 } 187 }
188 void OnTypesThrottled(ModelTypeSet types, 188 void OnTypesThrottled(ModelTypeSet types,
189 const base::TimeDelta& throttle_duration) override { 189 const base::TimeDelta& throttle_duration) override {
190 scheduler_->OnTypesThrottled(types, throttle_duration); 190 scheduler_->OnTypesThrottled(types, throttle_duration);
191 } 191 }
192 void OnTypesBackedOff(ModelTypeSet types) override {
193 scheduler_->OnTypesBackedOff(types);
194 }
192 bool IsCurrentlyThrottled() override { return false; } 195 bool IsCurrentlyThrottled() override { return false; }
193 void OnReceivedLongPollIntervalUpdate( 196 void OnReceivedLongPollIntervalUpdate(
194 const base::TimeDelta& new_interval) override { 197 const base::TimeDelta& new_interval) override {
195 last_long_poll_interval_received_ = new_interval; 198 last_long_poll_interval_received_ = new_interval;
196 } 199 }
197 void OnReceivedShortPollIntervalUpdate( 200 void OnReceivedShortPollIntervalUpdate(
198 const base::TimeDelta& new_interval) override { 201 const base::TimeDelta& new_interval) override {
199 last_short_poll_interval_received_ = new_interval; 202 last_short_poll_interval_received_ = new_interval;
200 } 203 }
201 void OnReceivedCustomNudgeDelays( 204 void OnReceivedCustomNudgeDelays(
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 case SyncCycleEvent::SYNC_CYCLE_ENDED: 237 case SyncCycleEvent::SYNC_CYCLE_ENDED:
235 return; 238 return;
236 default: 239 default:
237 FAIL() << "Handling unknown error type in unit tests!!"; 240 FAIL() << "Handling unknown error type in unit tests!!";
238 } 241 }
239 } 242 }
240 243
241 void OnActionableError(const SyncProtocolError& error) override {} 244 void OnActionableError(const SyncProtocolError& error) override {}
242 void OnRetryTimeChanged(base::Time retry_time) override {} 245 void OnRetryTimeChanged(base::Time retry_time) override {}
243 void OnThrottledTypesChanged(ModelTypeSet throttled_types) override {} 246 void OnThrottledTypesChanged(ModelTypeSet throttled_types) override {}
247 void OnBackedOffTypesChanged(ModelTypeSet backed_off_types) override {}
244 void OnMigrationRequested(ModelTypeSet types) override {} 248 void OnMigrationRequested(ModelTypeSet types) override {}
245 249
246 void ResetCycle() { cycle_.reset(SyncCycle::Build(context_.get(), this)); } 250 void ResetCycle() { cycle_.reset(SyncCycle::Build(context_.get(), this)); }
247 251
248 bool SyncShareNudge() { 252 bool SyncShareNudge() {
249 ResetCycle(); 253 ResetCycle();
250 254
251 // Pretend we've seen a local change, to make the nudge_tracker look normal. 255 // Pretend we've seen a local change, to make the nudge_tracker look normal.
252 nudge_tracker_.RecordLocalChange(ModelTypeSet(BOOKMARKS)); 256 nudge_tracker_.RecordLocalChange(ModelTypeSet(BOOKMARKS));
253 257
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 syncable::WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 618 syncable::WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
615 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1)); 619 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1));
616 ASSERT_TRUE(A.good()); 620 ASSERT_TRUE(A.good());
617 A.PutIsUnsynced(true); 621 A.PutIsUnsynced(true);
618 A.PutSpecifics(bookmark_data); 622 A.PutSpecifics(bookmark_data);
619 A.PutNonUniqueName("bookmark"); 623 A.PutNonUniqueName("bookmark");
620 } 624 }
621 625
622 // Now sync without enabling bookmarks. 626 // Now sync without enabling bookmarks.
623 mock_server_->ExpectGetUpdatesRequestTypes( 627 mock_server_->ExpectGetUpdatesRequestTypes(
624 Difference(context_->GetEnabledTypes(), ModelTypeSet(BOOKMARKS))); 628 Difference(context_->GetEnabledTypes(), throttled_types));
625 ResetCycle(); 629 ResetCycle();
626 syncer_->NormalSyncShare( 630 syncer_->NormalSyncShare(
627 Difference(context_->GetEnabledTypes(), ModelTypeSet(BOOKMARKS)), 631 Difference(context_->GetEnabledTypes(), throttled_types), &nudge_tracker_,
628 &nudge_tracker_, cycle_.get()); 632 cycle_.get());
629 633
630 { 634 {
631 // Nothing should have been committed as bookmarks is throttled. 635 // Nothing should have been committed as bookmarks is throttled.
632 syncable::ReadTransaction rtrans(FROM_HERE, directory()); 636 syncable::ReadTransaction rtrans(FROM_HERE, directory());
633 Entry entryA(&rtrans, GET_BY_ID, ids_.FromNumber(1)); 637 Entry entryA(&rtrans, GET_BY_ID, ids_.FromNumber(1));
634 ASSERT_TRUE(entryA.good()); 638 ASSERT_TRUE(entryA.good());
635 EXPECT_TRUE(entryA.GetIsUnsynced()); 639 EXPECT_TRUE(entryA.GetIsUnsynced());
636 } 640 }
637 641
638 // Sync again with bookmarks enabled. 642 // Sync again with bookmarks enabled.
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
910 syncable::ReadTransaction rtrans(FROM_HERE, directory()); 914 syncable::ReadTransaction rtrans(FROM_HERE, directory());
911 VERIFY_ENTRY(1, false, false, false, 0, 10, 10, ids_, &rtrans); 915 VERIFY_ENTRY(1, false, false, false, 0, 10, 10, ids_, &rtrans);
912 VERIFY_ENTRY(2, false, false, false, 1, 10, 10, ids_, &rtrans); 916 VERIFY_ENTRY(2, false, false, false, 1, 10, 10, ids_, &rtrans);
913 VERIFY_ENTRY(3, false, false, false, 1, 10, 10, ids_, &rtrans); 917 VERIFY_ENTRY(3, false, false, false, 1, 10, 10, ids_, &rtrans);
914 VERIFY_ENTRY(4, false, false, false, 0, 10, 10, ids_, &rtrans); 918 VERIFY_ENTRY(4, false, false, false, 0, 10, 10, ids_, &rtrans);
915 } 919 }
916 920
917 // Set BOOKMARKS throttled but PREFERENCES not, 921 // Set BOOKMARKS throttled but PREFERENCES not,
918 // then BOOKMARKS should not get synced but PREFERENCES should. 922 // then BOOKMARKS should not get synced but PREFERENCES should.
919 ModelTypeSet throttled_types(BOOKMARKS); 923 ModelTypeSet throttled_types(BOOKMARKS);
920 mock_server_->set_partial_throttling(true); 924 mock_server_->set_throttling(true);
921 mock_server_->SetThrottledTypes(throttled_types); 925 mock_server_->SetPartialFailureTypes(throttled_types);
922 926
923 mock_server_->AddUpdateSpecifics(1, 0, "E", 20, 20, true, 0, bookmark, 927 mock_server_->AddUpdateSpecifics(1, 0, "E", 20, 20, true, 0, bookmark,
924 foreign_cache_guid(), "-1"); 928 foreign_cache_guid(), "-1");
925 mock_server_->AddUpdateSpecifics(2, 1, "F", 20, 20, false, 2, bookmark, 929 mock_server_->AddUpdateSpecifics(2, 1, "F", 20, 20, false, 2, bookmark,
926 foreign_cache_guid(), "-2"); 930 foreign_cache_guid(), "-2");
927 mock_server_->AddUpdateSpecifics(3, 1, "G", 20, 20, false, 1, bookmark, 931 mock_server_->AddUpdateSpecifics(3, 1, "G", 20, 20, false, 1, bookmark,
928 foreign_cache_guid(), "-3"); 932 foreign_cache_guid(), "-3");
929 mock_server_->AddUpdateSpecifics(4, 0, "H", 20, 20, false, 0, pref); 933 mock_server_->AddUpdateSpecifics(4, 0, "H", 20, 20, false, 0, pref);
930 { 934 {
931 syncable::WriteTransaction wtrans(FROM_HERE, UNITTEST, directory()); 935 syncable::WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
(...skipping 10 matching lines...) Expand all
942 { 946 {
943 // BOOKMARKS throttled. 947 // BOOKMARKS throttled.
944 syncable::ReadTransaction rtrans(FROM_HERE, directory()); 948 syncable::ReadTransaction rtrans(FROM_HERE, directory());
945 VERIFY_ENTRY(1, false, true, false, 0, 10, 10, ids_, &rtrans); 949 VERIFY_ENTRY(1, false, true, false, 0, 10, 10, ids_, &rtrans);
946 VERIFY_ENTRY(2, false, true, false, 1, 10, 10, ids_, &rtrans); 950 VERIFY_ENTRY(2, false, true, false, 1, 10, 10, ids_, &rtrans);
947 VERIFY_ENTRY(3, false, true, false, 1, 10, 10, ids_, &rtrans); 951 VERIFY_ENTRY(3, false, true, false, 1, 10, 10, ids_, &rtrans);
948 VERIFY_ENTRY(4, false, false, false, 0, 21, 21, ids_, &rtrans); 952 VERIFY_ENTRY(4, false, false, false, 0, 21, 21, ids_, &rtrans);
949 } 953 }
950 954
951 // Unthrottled BOOKMARKS, then BOOKMARKS should get synced now. 955 // Unthrottled BOOKMARKS, then BOOKMARKS should get synced now.
952 mock_server_->set_partial_throttling(false); 956 mock_server_->set_throttling(false);
953 957
954 mock_server_->AddUpdateSpecifics(1, 0, "E", 30, 30, true, 0, bookmark, 958 mock_server_->AddUpdateSpecifics(1, 0, "E", 30, 30, true, 0, bookmark,
955 foreign_cache_guid(), "-1"); 959 foreign_cache_guid(), "-1");
956 mock_server_->AddUpdateSpecifics(2, 1, "F", 30, 30, false, 2, bookmark, 960 mock_server_->AddUpdateSpecifics(2, 1, "F", 30, 30, false, 2, bookmark,
957 foreign_cache_guid(), "-2"); 961 foreign_cache_guid(), "-2");
958 mock_server_->AddUpdateSpecifics(3, 1, "G", 30, 30, false, 1, bookmark, 962 mock_server_->AddUpdateSpecifics(3, 1, "G", 30, 30, false, 1, bookmark,
959 foreign_cache_guid(), "-3"); 963 foreign_cache_guid(), "-3");
960 mock_server_->AddUpdateSpecifics(4, 0, "H", 30, 30, false, 0, pref); 964 mock_server_->AddUpdateSpecifics(4, 0, "H", 30, 30, false, 0, pref);
961 EXPECT_TRUE(SyncShareNudge()); 965 EXPECT_TRUE(SyncShareNudge());
962 { 966 {
963 // BOOKMARKS unthrottled. 967 // BOOKMARKS unthrottled.
964 syncable::ReadTransaction rtrans(FROM_HERE, directory()); 968 syncable::ReadTransaction rtrans(FROM_HERE, directory());
965 VERIFY_ENTRY(1, false, false, false, 0, 31, 31, ids_, &rtrans); 969 VERIFY_ENTRY(1, false, false, false, 0, 31, 31, ids_, &rtrans);
966 VERIFY_ENTRY(2, false, false, false, 1, 31, 31, ids_, &rtrans); 970 VERIFY_ENTRY(2, false, false, false, 1, 31, 31, ids_, &rtrans);
967 VERIFY_ENTRY(3, false, false, false, 1, 31, 31, ids_, &rtrans); 971 VERIFY_ENTRY(3, false, false, false, 1, 31, 31, ids_, &rtrans);
968 VERIFY_ENTRY(4, false, false, false, 0, 30, 30, ids_, &rtrans); 972 VERIFY_ENTRY(4, false, false, false, 0, 30, 30, ids_, &rtrans);
969 } 973 }
970 } 974 }
971 975
976 TEST_F(SyncerTest, GetUpdatesPartialFailure) {
977 sync_pb::EntitySpecifics bookmark, pref;
978 bookmark.mutable_bookmark()->set_title("title");
979 pref.mutable_preference()->set_name("name");
980 AddDefaultFieldValue(BOOKMARKS, &bookmark);
981 AddDefaultFieldValue(PREFERENCES, &pref);
982
983 // Normal sync, all the data types should get synced.
984 mock_server_->AddUpdateSpecifics(1, 0, "A", 10, 10, true, 0, bookmark,
985 foreign_cache_guid(), "-1");
986 mock_server_->AddUpdateSpecifics(2, 1, "B", 10, 10, false, 2, bookmark,
987 foreign_cache_guid(), "-2");
988 mock_server_->AddUpdateSpecifics(3, 1, "C", 10, 10, false, 1, bookmark,
989 foreign_cache_guid(), "-3");
990 mock_server_->AddUpdateSpecifics(4, 0, "D", 10, 10, false, 0, pref);
991
992 EXPECT_TRUE(SyncShareNudge());
993 {
994 // Initial state. Everything is normal.
995 syncable::ReadTransaction rtrans(FROM_HERE, directory());
996 VERIFY_ENTRY(1, false, false, false, 0, 10, 10, ids_, &rtrans);
997 VERIFY_ENTRY(2, false, false, false, 1, 10, 10, ids_, &rtrans);
998 VERIFY_ENTRY(3, false, false, false, 1, 10, 10, ids_, &rtrans);
999 VERIFY_ENTRY(4, false, false, false, 0, 10, 10, ids_, &rtrans);
1000 }
1001
1002 // Set BOOKMARKS failure but PREFERENCES not,
1003 // then BOOKMARKS should not get synced but PREFERENCES should.
1004 ModelTypeSet failed_types(BOOKMARKS);
1005 mock_server_->set_partial_failure(true);
1006 mock_server_->SetPartialFailureTypes(failed_types);
1007
1008 mock_server_->AddUpdateSpecifics(1, 0, "E", 20, 20, true, 0, bookmark,
1009 foreign_cache_guid(), "-1");
1010 mock_server_->AddUpdateSpecifics(2, 1, "F", 20, 20, false, 2, bookmark,
1011 foreign_cache_guid(), "-2");
1012 mock_server_->AddUpdateSpecifics(3, 1, "G", 20, 20, false, 1, bookmark,
1013 foreign_cache_guid(), "-3");
1014 mock_server_->AddUpdateSpecifics(4, 0, "H", 20, 20, false, 0, pref);
1015 {
1016 syncable::WriteTransaction wtrans(FROM_HERE, UNITTEST, directory());
1017 MutableEntry A(&wtrans, GET_BY_ID, ids_.FromNumber(1));
1018 MutableEntry B(&wtrans, GET_BY_ID, ids_.FromNumber(2));
1019 MutableEntry C(&wtrans, GET_BY_ID, ids_.FromNumber(3));
1020 MutableEntry D(&wtrans, GET_BY_ID, ids_.FromNumber(4));
1021 A.PutIsUnsynced(true);
1022 B.PutIsUnsynced(true);
1023 C.PutIsUnsynced(true);
1024 D.PutIsUnsynced(true);
1025 }
1026 EXPECT_TRUE(SyncShareNudge());
Nicolas Zea 2016/11/12 01:04:35 Shouldn't bookmarks be blocked when this happens?
Gang Wu 2016/11/14 19:14:51 Partial failure does not block whole sync cycle, a
1027 {
1028 // BOOKMARKS failed.
1029 syncable::ReadTransaction rtrans(FROM_HERE, directory());
1030 VERIFY_ENTRY(1, false, true, false, 0, 10, 10, ids_, &rtrans);
1031 VERIFY_ENTRY(2, false, true, false, 1, 10, 10, ids_, &rtrans);
1032 VERIFY_ENTRY(3, false, true, false, 1, 10, 10, ids_, &rtrans);
1033 VERIFY_ENTRY(4, false, false, false, 0, 21, 21, ids_, &rtrans);
1034 }
1035
1036 // Set BOOKMARKS not partial failed, then BOOKMARKS should get synced now.
1037 mock_server_->set_partial_failure(false);
1038
1039 mock_server_->AddUpdateSpecifics(1, 0, "E", 30, 30, true, 0, bookmark,
1040 foreign_cache_guid(), "-1");
1041 mock_server_->AddUpdateSpecifics(2, 1, "F", 30, 30, false, 2, bookmark,
1042 foreign_cache_guid(), "-2");
1043 mock_server_->AddUpdateSpecifics(3, 1, "G", 30, 30, false, 1, bookmark,
1044 foreign_cache_guid(), "-3");
1045 mock_server_->AddUpdateSpecifics(4, 0, "H", 30, 30, false, 0, pref);
1046 EXPECT_TRUE(SyncShareNudge());
1047 {
1048 // BOOKMARKS not failed.
1049 syncable::ReadTransaction rtrans(FROM_HERE, directory());
1050 VERIFY_ENTRY(1, false, false, false, 0, 31, 31, ids_, &rtrans);
1051 VERIFY_ENTRY(2, false, false, false, 1, 31, 31, ids_, &rtrans);
1052 VERIFY_ENTRY(3, false, false, false, 1, 31, 31, ids_, &rtrans);
1053 VERIFY_ENTRY(4, false, false, false, 0, 30, 30, ids_, &rtrans);
1054 }
1055 }
1056
972 // This test uses internal knowledge of the directory to test correctness of 1057 // This test uses internal knowledge of the directory to test correctness of
973 // GetCommitIds. In almost every other test, the hierarchy is created from 1058 // GetCommitIds. In almost every other test, the hierarchy is created from
974 // parent to child order, and so parents always have metahandles that are 1059 // parent to child order, and so parents always have metahandles that are
975 // smaller than those of their children. This makes it very difficult to test 1060 // smaller than those of their children. This makes it very difficult to test
976 // some GetCommitIds edge cases, since it uses metahandle ordering as 1061 // some GetCommitIds edge cases, since it uses metahandle ordering as
977 // a starting point. 1062 // a starting point.
978 TEST_F(SyncerTest, GetCommitIds_VerifyDeletionCommitOrder) { 1063 TEST_F(SyncerTest, GetCommitIds_VerifyDeletionCommitOrder) {
979 { 1064 {
980 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory()); 1065 syncable::WriteTransaction trans(FROM_HERE, UNITTEST, directory());
981 1066
(...skipping 4858 matching lines...) Expand 10 before | Expand all | Expand 10 after
5840 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id); 5925 EXPECT_EQ("xyz", final_monitor_records["xyz"].extension_id);
5841 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count); 5926 EXPECT_EQ(2049U, final_monitor_records["ABC"].bookmark_write_count);
5842 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count); 5927 EXPECT_EQ(4U, final_monitor_records["xyz"].bookmark_write_count);
5843 } else { 5928 } else {
5844 EXPECT_TRUE(final_monitor_records.empty()) 5929 EXPECT_TRUE(final_monitor_records.empty())
5845 << "Should not restore records after successful bookmark commit."; 5930 << "Should not restore records after successful bookmark commit.";
5846 } 5931 }
5847 } 5932 }
5848 5933
5849 } // namespace syncer 5934 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698