diff options
author | tim@chromium.org <tim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-15 06:18:36 +0000 |
---|---|---|
committer | tim@chromium.org <tim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-15 06:18:36 +0000 |
commit | f706df5706936983f97b4898997da87029787da2 (patch) | |
tree | a1315c180059844bf0bc6344452f18544da6c91f /sync/engine/backoff_delay_provider_unittest.cc | |
parent | 639ec914f10c955f3b0c0c7dc2b1cdfd6b9f9527 (diff) | |
download | chromium_src-f706df5706936983f97b4898997da87029787da2.zip chromium_src-f706df5706936983f97b4898997da87029787da2.tar.gz chromium_src-f706df5706936983f97b4898997da87029787da2.tar.bz2 |
sync: add InternalComponentsFactory::Switches to simplify passing switches to internal components.
Cleans up backoff retry override code to use InternalComponentsFactory::Switches rather than
global bool hack.
Also puts keystore encryption flag atop new mechanism.
(TBR sky for new chrome_switch).
TBR=sky@chromium.org
BUG=142029, 139839
Review URL: https://chromiumcodereview.appspot.com/10837231
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151664 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sync/engine/backoff_delay_provider_unittest.cc')
-rw-r--r-- | sync/engine/backoff_delay_provider_unittest.cc | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/sync/engine/backoff_delay_provider_unittest.cc b/sync/engine/backoff_delay_provider_unittest.cc new file mode 100644 index 0000000..31ed515 --- /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 |