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

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

Issue 9372051: Don't retry failed attempts to poll sync server (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years, 9 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
« no previous file with comments | « chrome/browser/sync/engine/sync_scheduler.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/callback.h" 6 #include "base/callback.h"
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/memory/weak_ptr.h" 8 #include "base/memory/weak_ptr.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/test/test_timeouts.h" 10 #include "base/test/test_timeouts.h"
(...skipping 841 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 852
853 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(1) 853 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(1)
854 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), 854 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateCommitFailed),
855 RecordSyncShareMultiple(&r, 1U))); 855 RecordSyncShareMultiple(&r, 1U)));
856 EXPECT_CALL(*delay(), GetDelay(_)). 856 EXPECT_CALL(*delay(), GetDelay(_)).
857 WillRepeatedly(Return(TimeDelta::FromDays(1))); 857 WillRepeatedly(Return(TimeDelta::FromDays(1)));
858 858
859 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 859 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
860 RunLoop(); 860 RunLoop();
861 861
862 // Run again to wait for polling. 862 // This nudge should fail and put us into backoff. Thanks to our mock
863 // GetDelay() setup above, this will be a long backoff.
864 scheduler()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL, types, FROM_HERE);
863 RunLoop(); 865 RunLoop();
864 866
865 // Pump loop to get rid of nudge.
866 PumpLoop();
867
868 Mock::VerifyAndClearExpectations(syncer()); 867 Mock::VerifyAndClearExpectations(syncer());
869 ASSERT_EQ(1U, r.snapshots.size()); 868 ASSERT_EQ(1U, r.snapshots.size());
870 EXPECT_EQ(GetUpdatesCallerInfo::PERIODIC, 869 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, r.snapshots[0]->source.updates_source);
871 r.snapshots[0]->source.updates_source);
872 870
873 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(1) 871 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(1)
874 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), 872 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed),
875 RecordSyncShare(&r))); 873 RecordSyncShare(&r)));
876 874
877 // We schedule a nudge with enough delay (10X poll interval) that at least 875 // We schedule a nudge with enough delay (10X poll interval) that at least
878 // one or two polls would have taken place. The nudge should succeed. 876 // one or two polls would have taken place. The nudge should succeed.
879 scheduler()->ScheduleNudge( 877 scheduler()->ScheduleNudge(poll * 10, NUDGE_SOURCE_LOCAL, types, FROM_HERE);
880 poll * 10, NUDGE_SOURCE_LOCAL, types, FROM_HERE);
881 RunLoop(); 878 RunLoop();
882 879
883 Mock::VerifyAndClearExpectations(syncer()); 880 Mock::VerifyAndClearExpectations(syncer());
884 Mock::VerifyAndClearExpectations(delay()); 881 Mock::VerifyAndClearExpectations(delay());
885 ASSERT_EQ(2U, r.snapshots.size()); 882 ASSERT_EQ(2U, r.snapshots.size());
886 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, 883 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL, r.snapshots[1]->source.updates_source);
887 r.snapshots[1]->source.updates_source);
888 884
889 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(0); 885 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(0);
890 EXPECT_CALL(*delay(), GetDelay(_)).Times(0); 886 EXPECT_CALL(*delay(), GetDelay(_)).Times(0);
891 887
892 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE); 888 StartSyncScheduler(SyncScheduler::CONFIGURATION_MODE);
893 RunLoop(); 889 RunLoop();
894 890
895 scheduler()->ScheduleConfig( 891 scheduler()->ScheduleConfig(
896 types, GetUpdatesCallerInfo::RECONFIGURATION); 892 types, GetUpdatesCallerInfo::RECONFIGURATION);
897 PumpLoop(); 893 PumpLoop();
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
940 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(), FROM_HERE); 936 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(), FROM_HERE);
941 RunLoop(); 937 RunLoop();
942 938
943 ASSERT_EQ(kMinNumSamples, r.snapshots.size()); 939 ASSERT_EQ(kMinNumSamples, r.snapshots.size());
944 EXPECT_GE(r.times[1] - r.times[0], second); 940 EXPECT_GE(r.times[1] - r.times[0], second);
945 EXPECT_GE(r.times[2] - r.times[1], third); 941 EXPECT_GE(r.times[2] - r.times[1], third);
946 EXPECT_GE(r.times[3] - r.times[2], fourth); 942 EXPECT_GE(r.times[3] - r.times[2], fourth);
947 EXPECT_GE(r.times[4] - r.times[3], fifth); 943 EXPECT_GE(r.times[4] - r.times[3], fifth);
948 } 944 }
949 945
950 // Test that things go back to normal once a canary task makes forward progress 946 // Test that things go back to normal once a retry makes forward progress.
951 // following a succession of failures. 947 TEST_F(SyncSchedulerTest, BackoffRelief) {
952 //
953 // TODO(rlarocque, 112954): The code this was intended to test is broken.
954 TEST_F(SyncSchedulerTest, DISABLED_BackoffRelief) {
955 SyncShareRecords r; 948 SyncShareRecords r;
956 const TimeDelta poll(TimeDelta::FromMilliseconds(10)); 949 const TimeDelta poll(TimeDelta::FromMilliseconds(10));
957 scheduler()->OnReceivedLongPollIntervalUpdate(poll); 950 scheduler()->OnReceivedLongPollIntervalUpdate(poll);
958 UseMockDelayProvider(); 951 UseMockDelayProvider();
959 952
960 const TimeDelta backoff = TimeDelta::FromMilliseconds(100); 953 const TimeDelta backoff = TimeDelta::FromMilliseconds(5);
961 954
962 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) 955 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
963 .WillOnce(Invoke(sessions::test_util::SimulateCommitFailed)) 956 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed),
964 .WillOnce(Invoke(sessions::test_util::SimulateCommitFailed)) 957 RecordSyncShareMultiple(&r, kMinNumSamples)))
965 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess), 958 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateSuccess),
966 RecordSyncShareMultiple(&r, kMinNumSamples))); 959 RecordSyncShareMultiple(&r, kMinNumSamples)));
967 EXPECT_CALL(*delay(), GetDelay(_)).WillOnce(Return(backoff)); 960 EXPECT_CALL(*delay(), GetDelay(_)).WillOnce(Return(backoff));
968 961
969 // Optimal start for the post-backoff poll party. 962 // Optimal start for the post-backoff poll party.
970 TimeTicks optimal_start = TimeTicks::Now() + poll + backoff; 963 TimeTicks optimal_start = TimeTicks::Now();
971 StartSyncScheduler(SyncScheduler::NORMAL_MODE); 964 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
972 RunLoop(); 965 RunLoop();
973 966
974 // Run again to wait for polling. 967 // Run again to wait for polling.
968 scheduler()->ScheduleNudge(zero(), NUDGE_SOURCE_LOCAL,
969 ModelTypeSet(), FROM_HERE);
975 RunLoop(); 970 RunLoop();
976 971
977 StopSyncScheduler(); 972 StopSyncScheduler();
978 973
979 // Check for healthy polling after backoff is relieved. 974 EXPECT_EQ(kMinNumSamples, r.times.size());
980 // Can't use AnalyzePollRun because first sync is a continuation. Bleh. 975
981 for (size_t i = 0; i < r.times.size(); i++) { 976 // The first nudge ran as soon as possible. It failed.
977 TimeTicks optimal_job_time = optimal_start;
978 EXPECT_GE(r.times[0], optimal_job_time);
979 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL,
980 r.snapshots[0]->source.updates_source);
981
982 // It was followed by a successful retry nudge shortly afterward.
983 optimal_job_time = optimal_job_time + backoff;
984 EXPECT_GE(r.times[1], optimal_job_time);
985 EXPECT_EQ(GetUpdatesCallerInfo::LOCAL,
986 r.snapshots[1]->source.updates_source);
987 // After that, we went back to polling.
988 for (size_t i = 2; i < r.snapshots.size(); i++) {
989 optimal_job_time = optimal_job_time + poll;
982 SCOPED_TRACE(testing::Message() << "SyncShare # (" << i << ")"); 990 SCOPED_TRACE(testing::Message() << "SyncShare # (" << i << ")");
983 TimeTicks optimal_next_sync = optimal_start + poll * i; 991 EXPECT_GE(r.times[i], optimal_job_time);
984 EXPECT_GE(r.times[i], optimal_next_sync); 992 EXPECT_EQ(GetUpdatesCallerInfo::PERIODIC,
985 EXPECT_EQ(i == 0 ? GetUpdatesCallerInfo::SYNC_CYCLE_CONTINUATION
986 : GetUpdatesCallerInfo::PERIODIC,
987 r.snapshots[i]->source.updates_source); 993 r.snapshots[i]->source.updates_source);
988 } 994 }
989 } 995 }
990 996
997 // Test that poll failures are ignored. They should have no effect on
998 // subsequent poll attempts, nor should they trigger a backoff/retry.
999 TEST_F(SyncSchedulerTest, TransientPollFailure) {
1000 SyncShareRecords r;
1001 const TimeDelta poll_interval(TimeDelta::FromMilliseconds(10));
1002 scheduler()->OnReceivedLongPollIntervalUpdate(poll_interval);
1003 UseMockDelayProvider(); // Will cause test failure if backoff is initiated.
1004
1005 EXPECT_CALL(*syncer(), SyncShare(_,_,_))
1006 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateCommitFailed),
1007 RecordSyncShare(&r)))
1008 .WillOnce(DoAll(Invoke(sessions::test_util::SimulateSuccess),
1009 RecordSyncShare(&r)));
1010
1011 StartSyncScheduler(SyncScheduler::NORMAL_MODE);
1012 RunLoop();
1013
1014 // Run the unsucessful poll. The failed poll should not trigger backoff.
1015 RunLoop();
1016 EXPECT_FALSE(scheduler()->IsBackingOff());
1017
1018 // Run the successful poll.
1019 RunLoop();
1020 EXPECT_FALSE(scheduler()->IsBackingOff());
1021
1022 // Verify the the two SyncShare() calls were made one poll interval apart.
1023 ASSERT_EQ(2U, r.snapshots.size());
1024 EXPECT_GE(r.times[1] - r.times[0], poll_interval);
1025 }
1026
991 TEST_F(SyncSchedulerTest, GetRecommendedDelay) { 1027 TEST_F(SyncSchedulerTest, GetRecommendedDelay) {
992 EXPECT_LE(TimeDelta::FromSeconds(0), 1028 EXPECT_LE(TimeDelta::FromSeconds(0),
993 SyncScheduler::GetRecommendedDelay(TimeDelta::FromSeconds(0))); 1029 SyncScheduler::GetRecommendedDelay(TimeDelta::FromSeconds(0)));
994 EXPECT_LE(TimeDelta::FromSeconds(1), 1030 EXPECT_LE(TimeDelta::FromSeconds(1),
995 SyncScheduler::GetRecommendedDelay(TimeDelta::FromSeconds(1))); 1031 SyncScheduler::GetRecommendedDelay(TimeDelta::FromSeconds(1)));
996 EXPECT_LE(TimeDelta::FromSeconds(50), 1032 EXPECT_LE(TimeDelta::FromSeconds(50),
997 SyncScheduler::GetRecommendedDelay(TimeDelta::FromSeconds(50))); 1033 SyncScheduler::GetRecommendedDelay(TimeDelta::FromSeconds(50)));
998 EXPECT_LE(TimeDelta::FromSeconds(10), 1034 EXPECT_LE(TimeDelta::FromSeconds(10),
999 SyncScheduler::GetRecommendedDelay(TimeDelta::FromSeconds(10))); 1035 SyncScheduler::GetRecommendedDelay(TimeDelta::FromSeconds(10)));
1000 EXPECT_EQ(TimeDelta::FromSeconds(kMaxBackoffSeconds), 1036 EXPECT_EQ(TimeDelta::FromSeconds(kMaxBackoffSeconds),
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
1120 PumpLoop(); 1156 PumpLoop();
1121 // Pump again to run job. 1157 // Pump again to run job.
1122 PumpLoop(); 1158 PumpLoop();
1123 1159
1124 StopSyncScheduler(); 1160 StopSyncScheduler();
1125 1161
1126 EXPECT_TRUE(expected == context()->previous_session_routing_info()); 1162 EXPECT_TRUE(expected == context()->previous_session_routing_info());
1127 } 1163 }
1128 1164
1129 } // namespace browser_sync 1165 } // namespace browser_sync
OLDNEW
« no previous file with comments | « chrome/browser/sync/engine/sync_scheduler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698