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

Side by Side Diff: sync/engine/backoff_delay_provider_unittest.cc

Issue 2130453004: [Sync] Move //sync to //components/sync. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. Created 4 years, 4 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
« no previous file with comments | « sync/engine/backoff_delay_provider.cc ('k') | sync/engine/clear_server_data.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "sync/engine/backoff_delay_provider.h"
6
7 #include <memory>
8
9 #include "base/time/time.h"
10 #include "sync/internal_api/public/engine/polling_constants.h"
11 #include "sync/internal_api/public/sessions/model_neutral_state.h"
12 #include "sync/internal_api/public/util/syncer_error.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 using base::TimeDelta;
16
17 namespace syncer {
18
19 class BackoffDelayProviderTest : public testing::Test {};
20
21 TEST_F(BackoffDelayProviderTest, GetRecommendedDelay) {
22 std::unique_ptr<BackoffDelayProvider> delay(
23 BackoffDelayProvider::FromDefaults());
24 EXPECT_EQ(TimeDelta::FromSeconds(1),
25 delay->GetDelay(TimeDelta::FromSeconds(0)));
26 EXPECT_LE(TimeDelta::FromSeconds(1),
27 delay->GetDelay(TimeDelta::FromSeconds(1)));
28 EXPECT_LE(TimeDelta::FromSeconds(50),
29 delay->GetDelay(TimeDelta::FromSeconds(50)));
30 EXPECT_LE(TimeDelta::FromSeconds(10),
31 delay->GetDelay(TimeDelta::FromSeconds(10)));
32 EXPECT_EQ(TimeDelta::FromSeconds(kMaxBackoffSeconds),
33 delay->GetDelay(TimeDelta::FromSeconds(kMaxBackoffSeconds)));
34 EXPECT_EQ(TimeDelta::FromSeconds(kMaxBackoffSeconds),
35 delay->GetDelay(TimeDelta::FromSeconds(kMaxBackoffSeconds + 1)));
36 }
37
38 TEST_F(BackoffDelayProviderTest, GetInitialDelay) {
39 std::unique_ptr<BackoffDelayProvider> delay(
40 BackoffDelayProvider::FromDefaults());
41 sessions::ModelNeutralState state;
42 state.last_get_key_result = SYNC_SERVER_ERROR;
43 EXPECT_EQ(kInitialBackoffRetrySeconds,
44 delay->GetInitialDelay(state).InSeconds());
45
46 state.last_get_key_result = UNSET;
47 state.last_download_updates_result = SERVER_RETURN_MIGRATION_DONE;
48 EXPECT_EQ(kInitialBackoffImmediateRetrySeconds,
49 delay->GetInitialDelay(state).InSeconds());
50
51 state.last_download_updates_result = NETWORK_CONNECTION_UNAVAILABLE;
52 EXPECT_EQ(kInitialBackoffRetrySeconds,
53 delay->GetInitialDelay(state).InSeconds());
54
55 state.last_download_updates_result = SERVER_RETURN_TRANSIENT_ERROR;
56 EXPECT_EQ(kInitialBackoffRetrySeconds,
57 delay->GetInitialDelay(state).InSeconds());
58
59 state.last_download_updates_result = SERVER_RESPONSE_VALIDATION_FAILED;
60 EXPECT_EQ(kInitialBackoffRetrySeconds,
61 delay->GetInitialDelay(state).InSeconds());
62
63 state.last_download_updates_result = DATATYPE_TRIGGERED_RETRY;
64 EXPECT_EQ(kInitialBackoffImmediateRetrySeconds,
65 delay->GetInitialDelay(state).InSeconds());
66
67 state.last_download_updates_result = SYNCER_OK;
68 // Note that updating credentials triggers a canary job, trumping
69 // the initial delay, but in theory we still expect this function to treat
70 // it like any other error in the system (except migration).
71 state.commit_result = SERVER_RETURN_INVALID_CREDENTIAL;
72 EXPECT_EQ(kInitialBackoffRetrySeconds,
73 delay->GetInitialDelay(state).InSeconds());
74
75 state.commit_result = SERVER_RETURN_MIGRATION_DONE;
76 EXPECT_EQ(kInitialBackoffImmediateRetrySeconds,
77 delay->GetInitialDelay(state).InSeconds());
78
79 state.commit_result = NETWORK_CONNECTION_UNAVAILABLE;
80 EXPECT_EQ(kInitialBackoffRetrySeconds,
81 delay->GetInitialDelay(state).InSeconds());
82
83 state.commit_result = SERVER_RETURN_CONFLICT;
84 EXPECT_EQ(kInitialBackoffImmediateRetrySeconds,
85 delay->GetInitialDelay(state).InSeconds());
86 }
87
88 TEST_F(BackoffDelayProviderTest, GetInitialDelayWithOverride) {
89 std::unique_ptr<BackoffDelayProvider> delay(
90 BackoffDelayProvider::WithShortInitialRetryOverride());
91 sessions::ModelNeutralState state;
92 state.last_get_key_result = SYNC_SERVER_ERROR;
93 EXPECT_EQ(kInitialBackoffShortRetrySeconds,
94 delay->GetInitialDelay(state).InSeconds());
95
96 state.last_get_key_result = UNSET;
97 state.last_download_updates_result = SERVER_RETURN_MIGRATION_DONE;
98 EXPECT_EQ(kInitialBackoffImmediateRetrySeconds,
99 delay->GetInitialDelay(state).InSeconds());
100
101 state.last_download_updates_result = SERVER_RETURN_TRANSIENT_ERROR;
102 EXPECT_EQ(kInitialBackoffShortRetrySeconds,
103 delay->GetInitialDelay(state).InSeconds());
104
105 state.last_download_updates_result = SERVER_RESPONSE_VALIDATION_FAILED;
106 EXPECT_EQ(kInitialBackoffShortRetrySeconds,
107 delay->GetInitialDelay(state).InSeconds());
108
109 state.last_download_updates_result = DATATYPE_TRIGGERED_RETRY;
110 EXPECT_EQ(kInitialBackoffImmediateRetrySeconds,
111 delay->GetInitialDelay(state).InSeconds());
112
113 state.last_download_updates_result = SYNCER_OK;
114 // Note that updating credentials triggers a canary job, trumping
115 // the initial delay, but in theory we still expect this function to treat
116 // it like any other error in the system (except migration).
117 state.commit_result = SERVER_RETURN_INVALID_CREDENTIAL;
118 EXPECT_EQ(kInitialBackoffShortRetrySeconds,
119 delay->GetInitialDelay(state).InSeconds());
120
121 state.commit_result = SERVER_RETURN_MIGRATION_DONE;
122 EXPECT_EQ(kInitialBackoffImmediateRetrySeconds,
123 delay->GetInitialDelay(state).InSeconds());
124
125 state.commit_result = SERVER_RETURN_CONFLICT;
126 EXPECT_EQ(kInitialBackoffImmediateRetrySeconds,
127 delay->GetInitialDelay(state).InSeconds());
128 }
129
130 } // namespace syncer
OLDNEW
« no previous file with comments | « sync/engine/backoff_delay_provider.cc ('k') | sync/engine/clear_server_data.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698