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

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

Issue 10837231: sync: add InternalComponentsFactory::Switches to simplify passing switches to internal components. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: pass switches in test_profile_sync_service.cc Created 8 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 | Annotate | Revision Log
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 "base/memory/scoped_ptr.h"
8 #include "base/time.h"
9 #include "sync/internal_api/public/engine/polling_constants.h"
10 #include "sync/internal_api/public/sessions/model_neutral_state.h"
11 #include "sync/internal_api/public/util/syncer_error.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 using base::TimeDelta;
15
16 namespace syncer {
17
18 class BackoffDelayProviderTest : public testing::Test {};
19
20 TEST_F(BackoffDelayProviderTest, GetRecommendedDelay) {
21 scoped_ptr<BackoffDelayProvider> delay(BackoffDelayProvider::FromDefaults());
22 EXPECT_LE(TimeDelta::FromSeconds(0),
23 delay->GetDelay(TimeDelta::FromSeconds(0)));
24 EXPECT_LE(TimeDelta::FromSeconds(1),
25 delay->GetDelay(TimeDelta::FromSeconds(1)));
26 EXPECT_LE(TimeDelta::FromSeconds(50),
27 delay->GetDelay(TimeDelta::FromSeconds(50)));
28 EXPECT_LE(TimeDelta::FromSeconds(10),
29 delay->GetDelay(TimeDelta::FromSeconds(10)));
30 EXPECT_EQ(TimeDelta::FromSeconds(kMaxBackoffSeconds),
31 delay->GetDelay(TimeDelta::FromSeconds(kMaxBackoffSeconds)));
32 EXPECT_EQ(TimeDelta::FromSeconds(kMaxBackoffSeconds),
33 delay->GetDelay(TimeDelta::FromSeconds(kMaxBackoffSeconds + 1)));
34 }
35
36 TEST_F(BackoffDelayProviderTest, GetInitialDelay) {
37 scoped_ptr<BackoffDelayProvider> delay(BackoffDelayProvider::FromDefaults());
38 sessions::ModelNeutralState state;
39 state.last_get_key_result = SYNC_SERVER_ERROR;
40 EXPECT_EQ(kInitialBackoffRetrySeconds,
41 delay->GetInitialDelay(state).InSeconds());
42
43 state.last_get_key_result = UNSET;
44 state.last_download_updates_result = SERVER_RETURN_MIGRATION_DONE;
45 EXPECT_EQ(kInitialBackoffShortRetrySeconds,
46 delay->GetInitialDelay(state).InSeconds());
47
48 state.last_download_updates_result = SERVER_RETURN_TRANSIENT_ERROR;
49 EXPECT_EQ(kInitialBackoffRetrySeconds,
50 delay->GetInitialDelay(state).InSeconds());
51
52 state.last_download_updates_result = SERVER_RESPONSE_VALIDATION_FAILED;
53 EXPECT_EQ(kInitialBackoffRetrySeconds,
54 delay->GetInitialDelay(state).InSeconds());
55
56 state.last_download_updates_result = SYNCER_OK;
57 // Note that updating credentials triggers a canary job, trumping
58 // the initial delay, but in theory we still expect this function to treat
59 // it like any other error in the system (except migration).
60 state.commit_result = SERVER_RETURN_INVALID_CREDENTIAL;
61 EXPECT_EQ(kInitialBackoffRetrySeconds,
62 delay->GetInitialDelay(state).InSeconds());
63
64 state.commit_result = SERVER_RETURN_MIGRATION_DONE;
65 EXPECT_EQ(kInitialBackoffShortRetrySeconds,
66 delay->GetInitialDelay(state).InSeconds());
67 }
68
69 TEST_F(BackoffDelayProviderTest, GetInitialDelayWithOverride) {
70 scoped_ptr<BackoffDelayProvider> delay(
71 BackoffDelayProvider::WithShortInitialRetryOverride());
72 sessions::ModelNeutralState state;
73 state.last_get_key_result = SYNC_SERVER_ERROR;
74 EXPECT_EQ(kInitialBackoffShortRetrySeconds,
75 delay->GetInitialDelay(state).InSeconds());
76
77 state.last_get_key_result = UNSET;
78 state.last_download_updates_result = SERVER_RETURN_MIGRATION_DONE;
79 EXPECT_EQ(kInitialBackoffShortRetrySeconds,
80 delay->GetInitialDelay(state).InSeconds());
81
82 state.last_download_updates_result = SERVER_RETURN_TRANSIENT_ERROR;
83 EXPECT_EQ(kInitialBackoffShortRetrySeconds,
84 delay->GetInitialDelay(state).InSeconds());
85
86 state.last_download_updates_result = SERVER_RESPONSE_VALIDATION_FAILED;
87 EXPECT_EQ(kInitialBackoffShortRetrySeconds,
88 delay->GetInitialDelay(state).InSeconds());
89
90 state.last_download_updates_result = SYNCER_OK;
91 // Note that updating credentials triggers a canary job, trumping
92 // the initial delay, but in theory we still expect this function to treat
93 // it like any other error in the system (except migration).
94 state.commit_result = SERVER_RETURN_INVALID_CREDENTIAL;
95 EXPECT_EQ(kInitialBackoffShortRetrySeconds,
96 delay->GetInitialDelay(state).InSeconds());
97
98 state.commit_result = SERVER_RETURN_MIGRATION_DONE;
99 EXPECT_EQ(kInitialBackoffShortRetrySeconds,
100 delay->GetInitialDelay(state).InSeconds());
101 }
102
103 } // namespace syncer
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698