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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: sync/engine/backoff_delay_provider_unittest.cc
diff --git a/sync/engine/backoff_delay_provider_unittest.cc b/sync/engine/backoff_delay_provider_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..31ed5152601c54225ee6de36fc282983ceaadf15
--- /dev/null
+++ b/sync/engine/backoff_delay_provider_unittest.cc
@@ -0,0 +1,103 @@
+// 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_LE(TimeDelta::FromSeconds(0),
+ 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(kInitialBackoffShortRetrySeconds,
+ 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(kInitialBackoffShortRetrySeconds,
+ 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(kInitialBackoffShortRetrySeconds,
+ 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(kInitialBackoffShortRetrySeconds,
+ delay->GetInitialDelay(state).InSeconds());
+}
+
+} // namespace syncer

Powered by Google App Engine
This is Rietveld 408576698