1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "sync/engine/backoff_delay_provider.h"
#include "base/memory/scoped_ptr.h"
#include "base/time.h"
#include "sync/internal_api/public/engine/polling_constants.h"
#include "sync/internal_api/public/sessions/model_neutral_state.h"
#include "sync/internal_api/public/util/syncer_error.h"
#include "testing/gtest/include/gtest/gtest.h"
using base::TimeDelta;
namespace syncer {
class BackoffDelayProviderTest : public testing::Test {};
TEST_F(BackoffDelayProviderTest, GetRecommendedDelay) {
scoped_ptr<BackoffDelayProvider> delay(BackoffDelayProvider::FromDefaults());
EXPECT_EQ(TimeDelta::FromSeconds(1),
delay->GetDelay(TimeDelta::FromSeconds(0)));
EXPECT_LE(TimeDelta::FromSeconds(1),
delay->GetDelay(TimeDelta::FromSeconds(1)));
EXPECT_LE(TimeDelta::FromSeconds(50),
delay->GetDelay(TimeDelta::FromSeconds(50)));
EXPECT_LE(TimeDelta::FromSeconds(10),
delay->GetDelay(TimeDelta::FromSeconds(10)));
EXPECT_EQ(TimeDelta::FromSeconds(kMaxBackoffSeconds),
delay->GetDelay(TimeDelta::FromSeconds(kMaxBackoffSeconds)));
EXPECT_EQ(TimeDelta::FromSeconds(kMaxBackoffSeconds),
delay->GetDelay(TimeDelta::FromSeconds(kMaxBackoffSeconds + 1)));
}
TEST_F(BackoffDelayProviderTest, GetInitialDelay) {
scoped_ptr<BackoffDelayProvider> delay(BackoffDelayProvider::FromDefaults());
sessions::ModelNeutralState state;
state.last_get_key_result = SYNC_SERVER_ERROR;
EXPECT_EQ(kInitialBackoffRetrySeconds,
delay->GetInitialDelay(state).InSeconds());
state.last_get_key_result = UNSET;
state.last_download_updates_result = SERVER_RETURN_MIGRATION_DONE;
EXPECT_EQ(kInitialBackoffImmediateRetrySeconds,
delay->GetInitialDelay(state).InSeconds());
state.last_download_updates_result = NETWORK_CONNECTION_UNAVAILABLE;
EXPECT_EQ(kInitialBackoffImmediateRetrySeconds,
delay->GetInitialDelay(state).InSeconds());
state.last_download_updates_result = SERVER_RETURN_TRANSIENT_ERROR;
EXPECT_EQ(kInitialBackoffRetrySeconds,
delay->GetInitialDelay(state).InSeconds());
state.last_download_updates_result = SERVER_RESPONSE_VALIDATION_FAILED;
EXPECT_EQ(kInitialBackoffRetrySeconds,
delay->GetInitialDelay(state).InSeconds());
state.last_download_updates_result = SYNCER_OK;
// Note that updating credentials triggers a canary job, trumping
// the initial delay, but in theory we still expect this function to treat
// it like any other error in the system (except migration).
state.commit_result = SERVER_RETURN_INVALID_CREDENTIAL;
EXPECT_EQ(kInitialBackoffRetrySeconds,
delay->GetInitialDelay(state).InSeconds());
state.commit_result = SERVER_RETURN_MIGRATION_DONE;
EXPECT_EQ(kInitialBackoffImmediateRetrySeconds,
delay->GetInitialDelay(state).InSeconds());
state.commit_result = NETWORK_CONNECTION_UNAVAILABLE;
EXPECT_EQ(kInitialBackoffImmediateRetrySeconds,
delay->GetInitialDelay(state).InSeconds());
state.commit_result = SERVER_RETURN_CONFLICT;
EXPECT_EQ(kInitialBackoffImmediateRetrySeconds,
delay->GetInitialDelay(state).InSeconds());
}
TEST_F(BackoffDelayProviderTest, GetInitialDelayWithOverride) {
scoped_ptr<BackoffDelayProvider> delay(
BackoffDelayProvider::WithShortInitialRetryOverride());
sessions::ModelNeutralState state;
state.last_get_key_result = SYNC_SERVER_ERROR;
EXPECT_EQ(kInitialBackoffShortRetrySeconds,
delay->GetInitialDelay(state).InSeconds());
state.last_get_key_result = UNSET;
state.last_download_updates_result = SERVER_RETURN_MIGRATION_DONE;
EXPECT_EQ(kInitialBackoffImmediateRetrySeconds,
delay->GetInitialDelay(state).InSeconds());
state.last_download_updates_result = SERVER_RETURN_TRANSIENT_ERROR;
EXPECT_EQ(kInitialBackoffShortRetrySeconds,
delay->GetInitialDelay(state).InSeconds());
state.last_download_updates_result = SERVER_RESPONSE_VALIDATION_FAILED;
EXPECT_EQ(kInitialBackoffShortRetrySeconds,
delay->GetInitialDelay(state).InSeconds());
state.last_download_updates_result = SYNCER_OK;
// Note that updating credentials triggers a canary job, trumping
// the initial delay, but in theory we still expect this function to treat
// it like any other error in the system (except migration).
state.commit_result = SERVER_RETURN_INVALID_CREDENTIAL;
EXPECT_EQ(kInitialBackoffShortRetrySeconds,
delay->GetInitialDelay(state).InSeconds());
state.commit_result = SERVER_RETURN_MIGRATION_DONE;
EXPECT_EQ(kInitialBackoffImmediateRetrySeconds,
delay->GetInitialDelay(state).InSeconds());
state.commit_result = SERVER_RETURN_CONFLICT;
EXPECT_EQ(kInitialBackoffImmediateRetrySeconds,
delay->GetInitialDelay(state).InSeconds());
}
} // namespace syncer
|