| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/macros.h" | 6 #include "base/macros.h" |
| 7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "chrome/browser/sync/test/integration/bookmarks_helper.h" | 8 #include "chrome/browser/sync/test/integration/bookmarks_helper.h" |
| 9 #include "chrome/browser/sync/test/integration/retry_verifier.h" | 9 #include "chrome/browser/sync/test/integration/retry_verifier.h" |
| 10 #include "chrome/browser/sync/test/integration/single_client_status_change_check
er.h" | 10 #include "chrome/browser/sync/test/integration/single_client_status_change_check
er.h" |
| 11 #include "chrome/browser/sync/test/integration/sync_integration_test_util.h" | 11 #include "chrome/browser/sync/test/integration/sync_integration_test_util.h" |
| 12 #include "chrome/browser/sync/test/integration/sync_test.h" | 12 #include "chrome/browser/sync/test/integration/sync_test.h" |
| 13 #include "components/browser_sync/browser/profile_sync_service.h" | 13 #include "components/browser_sync/browser/profile_sync_service.h" |
| 14 #include "net/base/network_change_notifier.h" | 14 #include "net/base/network_change_notifier.h" |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 using bookmarks_helper::AddFolder; | 18 using bookmarks_helper::AddFolder; |
| 19 using bookmarks_helper::ModelMatchesVerifier; | 19 using bookmarks_helper::ModelMatchesVerifier; |
| 20 using syncer::sessions::SyncSessionSnapshot; | 20 using syncer::SyncCycleSnapshot; |
| 21 using sync_integration_test_util::AwaitCommitActivityCompletion; | 21 using sync_integration_test_util::AwaitCommitActivityCompletion; |
| 22 | 22 |
| 23 class SyncExponentialBackoffTest : public SyncTest { | 23 class SyncExponentialBackoffTest : public SyncTest { |
| 24 public: | 24 public: |
| 25 SyncExponentialBackoffTest() : SyncTest(SINGLE_CLIENT) {} | 25 SyncExponentialBackoffTest() : SyncTest(SINGLE_CLIENT) {} |
| 26 ~SyncExponentialBackoffTest() override {} | 26 ~SyncExponentialBackoffTest() override {} |
| 27 | 27 |
| 28 private: | 28 private: |
| 29 DISALLOW_COPY_AND_ASSIGN(SyncExponentialBackoffTest); | 29 DISALLOW_COPY_AND_ASSIGN(SyncExponentialBackoffTest); |
| 30 }; | 30 }; |
| 31 | 31 |
| 32 // Helper class that checks if a sync client has successfully gone through | 32 // Helper class that checks if a sync client has successfully gone through |
| 33 // exponential backoff after it encounters an error. | 33 // exponential backoff after it encounters an error. |
| 34 class ExponentialBackoffChecker : public SingleClientStatusChangeChecker { | 34 class ExponentialBackoffChecker : public SingleClientStatusChangeChecker { |
| 35 public: | 35 public: |
| 36 explicit ExponentialBackoffChecker(ProfileSyncService* pss) | 36 explicit ExponentialBackoffChecker(ProfileSyncService* pss) |
| 37 : SingleClientStatusChangeChecker(pss) { | 37 : SingleClientStatusChangeChecker(pss) { |
| 38 const SyncSessionSnapshot& snap = service()->GetLastSessionSnapshot(); | 38 const SyncCycleSnapshot& snap = service()->GetLastCycleSnapshot(); |
| 39 retry_verifier_.Initialize(snap); | 39 retry_verifier_.Initialize(snap); |
| 40 } | 40 } |
| 41 | 41 |
| 42 ~ExponentialBackoffChecker() override {} | 42 ~ExponentialBackoffChecker() override {} |
| 43 | 43 |
| 44 // Checks if backoff is complete. Called repeatedly each time PSS notifies | 44 // Checks if backoff is complete. Called repeatedly each time PSS notifies |
| 45 // observers of a state change. | 45 // observers of a state change. |
| 46 bool IsExitConditionSatisfied() override { | 46 bool IsExitConditionSatisfied() override { |
| 47 const SyncSessionSnapshot& snap = service()->GetLastSessionSnapshot(); | 47 const SyncCycleSnapshot& snap = service()->GetLastCycleSnapshot(); |
| 48 retry_verifier_.VerifyRetryInterval(snap); | 48 retry_verifier_.VerifyRetryInterval(snap); |
| 49 return (retry_verifier_.done() && retry_verifier_.Succeeded()); | 49 return (retry_verifier_.done() && retry_verifier_.Succeeded()); |
| 50 } | 50 } |
| 51 | 51 |
| 52 std::string GetDebugMessage() const override { | 52 std::string GetDebugMessage() const override { |
| 53 return base::StringPrintf("Verifying backoff intervals (%d/%d)", | 53 return base::StringPrintf("Verifying backoff intervals (%d/%d)", |
| 54 retry_verifier_.retry_count(), | 54 retry_verifier_.retry_count(), |
| 55 RetryVerifier::kMaxRetry); | 55 RetryVerifier::kMaxRetry); |
| 56 } | 56 } |
| 57 | 57 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 | 90 |
| 91 base::Time network_notification_time = base::Time::Now(); | 91 base::Time network_notification_time = base::Time::Now(); |
| 92 | 92 |
| 93 // Verify that sync was able to recover. | 93 // Verify that sync was able to recover. |
| 94 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0)))); | 94 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0)))); |
| 95 ASSERT_TRUE(ModelMatchesVerifier(0)); | 95 ASSERT_TRUE(ModelMatchesVerifier(0)); |
| 96 | 96 |
| 97 // Verify that recovery time is short. Without canary job recovery time would | 97 // Verify that recovery time is short. Without canary job recovery time would |
| 98 // be more than 5 seconds. | 98 // be more than 5 seconds. |
| 99 base::TimeDelta recovery_time = | 99 base::TimeDelta recovery_time = |
| 100 GetSyncService(0)->GetLastSessionSnapshot().sync_start_time() - | 100 GetSyncService(0)->GetLastCycleSnapshot().sync_start_time() - |
| 101 network_notification_time; | 101 network_notification_time; |
| 102 ASSERT_LE(recovery_time, base::TimeDelta::FromSeconds(2)); | 102 ASSERT_LE(recovery_time, base::TimeDelta::FromSeconds(2)); |
| 103 } | 103 } |
| 104 | 104 |
| 105 IN_PROC_BROWSER_TEST_F(SyncExponentialBackoffTest, TransientErrorTest) { | 105 IN_PROC_BROWSER_TEST_F(SyncExponentialBackoffTest, TransientErrorTest) { |
| 106 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 106 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
| 107 | 107 |
| 108 // Add an item and ensure that sync is successful. | 108 // Add an item and ensure that sync is successful. |
| 109 ASSERT_TRUE(AddFolder(0, 0, "folder1")); | 109 ASSERT_TRUE(AddFolder(0, 0, "folder1")); |
| 110 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0)))); | 110 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0)))); |
| 111 | 111 |
| 112 GetFakeServer()->TriggerError(sync_pb::SyncEnums::TRANSIENT_ERROR); | 112 GetFakeServer()->TriggerError(sync_pb::SyncEnums::TRANSIENT_ERROR); |
| 113 | 113 |
| 114 // Add a new item to trigger another sync cycle. | 114 // Add a new item to trigger another sync cycle. |
| 115 ASSERT_TRUE(AddFolder(0, 0, "folder2")); | 115 ASSERT_TRUE(AddFolder(0, 0, "folder2")); |
| 116 | 116 |
| 117 // Verify that the client goes into exponential backoff while it is unable to | 117 // Verify that the client goes into exponential backoff while it is unable to |
| 118 // reach the sync server. | 118 // reach the sync server. |
| 119 ExponentialBackoffChecker exponential_backoff_checker( | 119 ExponentialBackoffChecker exponential_backoff_checker( |
| 120 GetSyncService((0))); | 120 GetSyncService((0))); |
| 121 exponential_backoff_checker.Wait(); | 121 exponential_backoff_checker.Wait(); |
| 122 ASSERT_FALSE(exponential_backoff_checker.TimedOut()); | 122 ASSERT_FALSE(exponential_backoff_checker.TimedOut()); |
| 123 } | 123 } |
| 124 | 124 |
| 125 } // namespace | 125 } // namespace |
| OLD | NEW |