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 "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 910 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
921 | 921 |
922 // Test that backoff is shaping traffic properly with consecutive errors. | 922 // Test that backoff is shaping traffic properly with consecutive errors. |
923 TEST_F(SyncSchedulerTest, BackoffElevation) { | 923 TEST_F(SyncSchedulerTest, BackoffElevation) { |
924 SyncShareRecords r; | 924 SyncShareRecords r; |
925 UseMockDelayProvider(); | 925 UseMockDelayProvider(); |
926 | 926 |
927 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(kMinNumSamples) | 927 EXPECT_CALL(*syncer(), SyncShare(_,_,_)).Times(kMinNumSamples) |
928 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), | 928 .WillRepeatedly(DoAll(Invoke(sessions::test_util::SimulateCommitFailed), |
929 RecordSyncShareMultiple(&r, kMinNumSamples))); | 929 RecordSyncShareMultiple(&r, kMinNumSamples))); |
930 | 930 |
931 const TimeDelta first = TimeDelta::FromSeconds(1); | 931 const TimeDelta first = TimeDelta::FromSeconds(kInitialBackoffRetrySeconds); |
932 const TimeDelta second = TimeDelta::FromMilliseconds(2); | 932 const TimeDelta second = TimeDelta::FromMilliseconds(2); |
933 const TimeDelta third = TimeDelta::FromMilliseconds(3); | 933 const TimeDelta third = TimeDelta::FromMilliseconds(3); |
934 const TimeDelta fourth = TimeDelta::FromMilliseconds(4); | 934 const TimeDelta fourth = TimeDelta::FromMilliseconds(4); |
935 const TimeDelta fifth = TimeDelta::FromMilliseconds(5); | 935 const TimeDelta fifth = TimeDelta::FromMilliseconds(5); |
936 const TimeDelta sixth = TimeDelta::FromDays(1); | 936 const TimeDelta sixth = TimeDelta::FromDays(1); |
937 | 937 |
938 EXPECT_CALL(*delay(), GetDelay(Eq(first))).WillOnce(Return(second)) | 938 EXPECT_CALL(*delay(), GetDelay(Eq(first))).WillOnce(Return(second)) |
939 .RetiresOnSaturation(); | 939 .RetiresOnSaturation(); |
940 EXPECT_CALL(*delay(), GetDelay(Eq(second))).WillOnce(Return(third)) | 940 EXPECT_CALL(*delay(), GetDelay(Eq(second))).WillOnce(Return(third)) |
941 .RetiresOnSaturation(); | 941 .RetiresOnSaturation(); |
(...skipping 10 matching lines...) Expand all Loading... |
952 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(), FROM_HERE); | 952 zero(), NUDGE_SOURCE_LOCAL, ModelTypeSet(), FROM_HERE); |
953 RunLoop(); | 953 RunLoop(); |
954 | 954 |
955 ASSERT_EQ(kMinNumSamples, r.snapshots.size()); | 955 ASSERT_EQ(kMinNumSamples, r.snapshots.size()); |
956 EXPECT_GE(r.times[1] - r.times[0], second); | 956 EXPECT_GE(r.times[1] - r.times[0], second); |
957 EXPECT_GE(r.times[2] - r.times[1], third); | 957 EXPECT_GE(r.times[2] - r.times[1], third); |
958 EXPECT_GE(r.times[3] - r.times[2], fourth); | 958 EXPECT_GE(r.times[3] - r.times[2], fourth); |
959 EXPECT_GE(r.times[4] - r.times[3], fifth); | 959 EXPECT_GE(r.times[4] - r.times[3], fifth); |
960 } | 960 } |
961 | 961 |
| 962 TEST_F(SyncSchedulerTest, GetInitialBackoffDelay) { |
| 963 sessions::ModelNeutralState state; |
| 964 state.last_get_key_result = SYNC_SERVER_ERROR; |
| 965 EXPECT_EQ(kInitialBackoffRetrySeconds, |
| 966 scheduler()->GetInitialBackoffDelay(state).InSeconds()); |
| 967 |
| 968 state.last_get_key_result = UNSET; |
| 969 state.last_download_updates_result = SERVER_RETURN_MIGRATION_DONE; |
| 970 EXPECT_EQ(kInitialBackoffShortRetrySeconds, |
| 971 scheduler()->GetInitialBackoffDelay(state).InSeconds()); |
| 972 |
| 973 state.last_download_updates_result = SERVER_RETURN_TRANSIENT_ERROR; |
| 974 EXPECT_EQ(kInitialBackoffRetrySeconds, |
| 975 scheduler()->GetInitialBackoffDelay(state).InSeconds()); |
| 976 |
| 977 state.last_download_updates_result = SERVER_RESPONSE_VALIDATION_FAILED; |
| 978 EXPECT_EQ(kInitialBackoffRetrySeconds, |
| 979 scheduler()->GetInitialBackoffDelay(state).InSeconds()); |
| 980 |
| 981 state.last_download_updates_result = SYNCER_OK; |
| 982 // Note that updating credentials triggers a canary job, trumping |
| 983 // the initial delay, but in theory we still expect this function to treat |
| 984 // it like any other error in the system (except migration). |
| 985 state.commit_result = SERVER_RETURN_INVALID_CREDENTIAL; |
| 986 EXPECT_EQ(kInitialBackoffRetrySeconds, |
| 987 scheduler()->GetInitialBackoffDelay(state).InSeconds()); |
| 988 |
| 989 state.commit_result = SERVER_RETURN_MIGRATION_DONE; |
| 990 EXPECT_EQ(kInitialBackoffShortRetrySeconds, |
| 991 scheduler()->GetInitialBackoffDelay(state).InSeconds()); |
| 992 } |
| 993 |
962 // Test that things go back to normal once a retry makes forward progress. | 994 // Test that things go back to normal once a retry makes forward progress. |
963 TEST_F(SyncSchedulerTest, BackoffRelief) { | 995 TEST_F(SyncSchedulerTest, BackoffRelief) { |
964 SyncShareRecords r; | 996 SyncShareRecords r; |
965 const TimeDelta poll(TimeDelta::FromMilliseconds(10)); | 997 const TimeDelta poll(TimeDelta::FromMilliseconds(10)); |
966 scheduler()->OnReceivedLongPollIntervalUpdate(poll); | 998 scheduler()->OnReceivedLongPollIntervalUpdate(poll); |
967 UseMockDelayProvider(); | 999 UseMockDelayProvider(); |
968 | 1000 |
969 const TimeDelta backoff = TimeDelta::FromMilliseconds(5); | 1001 const TimeDelta backoff = TimeDelta::FromMilliseconds(5); |
970 | 1002 |
971 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) | 1003 EXPECT_CALL(*syncer(), SyncShare(_,_,_)) |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1126 // Should save the nudge for until after the server is reachable. | 1158 // Should save the nudge for until after the server is reachable. |
1127 MessageLoop::current()->RunAllPending(); | 1159 MessageLoop::current()->RunAllPending(); |
1128 | 1160 |
1129 connection()->SetServerReachable(); | 1161 connection()->SetServerReachable(); |
1130 connection()->UpdateConnectionStatus(); | 1162 connection()->UpdateConnectionStatus(); |
1131 scheduler()->OnConnectionStatusChange(); | 1163 scheduler()->OnConnectionStatusChange(); |
1132 MessageLoop::current()->RunAllPending(); | 1164 MessageLoop::current()->RunAllPending(); |
1133 } | 1165 } |
1134 | 1166 |
1135 } // namespace syncer | 1167 } // namespace syncer |
OLD | NEW |