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

Side by Side Diff: chrome/browser/sync/test/integration/sync_exponential_backoff_test.cc

Issue 165393010: Draft: Moving code out of ProfileSyncServiceHarness (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 10 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
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/strings/stringprintf.h"
6 #include "chrome/browser/sync/test/integration/bookmarks_helper.h" 7 #include "chrome/browser/sync/test/integration/bookmarks_helper.h"
7 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h" 8 #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h"
8 #include "chrome/browser/sync/test/integration/retry_verifier.h" 9 #include "chrome/browser/sync/test/integration/retry_verifier.h"
9 #include "chrome/browser/sync/test/integration/status_change_checker.h" 10 #include "chrome/browser/sync/test/integration/single_client_status_change_check er.h"
10 #include "chrome/browser/sync/test/integration/sync_test.h" 11 #include "chrome/browser/sync/test/integration/sync_test.h"
11 12
12 namespace { 13 namespace {
13 14
14 using bookmarks_helper::AddFolder; 15 using bookmarks_helper::AddFolder;
15 using bookmarks_helper::ModelMatchesVerifier; 16 using bookmarks_helper::ModelMatchesVerifier;
16 using syncer::sessions::SyncSessionSnapshot; 17 using syncer::sessions::SyncSessionSnapshot;
17 18
18 class SyncExponentialBackoffTest : public SyncTest { 19 class SyncExponentialBackoffTest : public SyncTest {
19 public: 20 public:
20 SyncExponentialBackoffTest() : SyncTest(SINGLE_CLIENT) {} 21 SyncExponentialBackoffTest() : SyncTest(SINGLE_CLIENT) {}
21 virtual ~SyncExponentialBackoffTest() {} 22 virtual ~SyncExponentialBackoffTest() {}
22 23
23 private: 24 private:
24 DISALLOW_COPY_AND_ASSIGN(SyncExponentialBackoffTest); 25 DISALLOW_COPY_AND_ASSIGN(SyncExponentialBackoffTest);
25 }; 26 };
26 27
27 // Helper class that checks if a sync client has successfully gone through 28 // Helper class that checks if a sync client has successfully gone through
28 // exponential backoff after it encounters an error. 29 // exponential backoff after it encounters an error.
29 class ExponentialBackoffChecker : public StatusChangeChecker { 30 class ExponentialBackoffChecker : public SingleClientStatusChangeChecker {
30 public: 31 public:
31 explicit ExponentialBackoffChecker(const ProfileSyncServiceHarness* harness) 32 explicit ExponentialBackoffChecker(ProfileSyncService* pss)
32 : StatusChangeChecker("ExponentialBackoffChecker"), 33 : SingleClientStatusChangeChecker(pss) {
33 harness_(harness) { 34 const SyncSessionSnapshot& snap = service()->GetLastSessionSnapshot();
34 DCHECK(harness);
35 const SyncSessionSnapshot& snap = harness_->GetLastSessionSnapshot();
36 retry_verifier_.Initialize(snap); 35 retry_verifier_.Initialize(snap);
37 } 36 }
38 37
39 virtual ~ExponentialBackoffChecker() {} 38 virtual ~ExponentialBackoffChecker() {}
40 39
41 // Checks if backoff is complete. Called repeatedly each time PSS notifies 40 // Checks if backoff is complete. Called repeatedly each time PSS notifies
42 // observers of a state change. 41 // observers of a state change.
43 virtual bool IsExitConditionSatisfied() OVERRIDE { 42 virtual bool IsExitConditionSatisfied() OVERRIDE {
44 const SyncSessionSnapshot& snap = harness_->GetLastSessionSnapshot(); 43 const SyncSessionSnapshot& snap = service()->GetLastSessionSnapshot();
45 retry_verifier_.VerifyRetryInterval(snap); 44 retry_verifier_.VerifyRetryInterval(snap);
46 return (retry_verifier_.done() && retry_verifier_.Succeeded()); 45 return (retry_verifier_.done() && retry_verifier_.Succeeded());
47 } 46 }
48 47
48 virtual std::string GetDebugMessage() const OVERRIDE {
49 return base::StringPrintf("Verifying backoff intervals (%d/%d)",
50 retry_verifier_.retry_count(),
51 RetryVerifier::kMaxRetry);
52 }
53
49 private: 54 private:
50 // The sync client for which backoff is being verified.
51 const ProfileSyncServiceHarness* harness_;
52
53 // Keeps track of the number of attempts at exponential backoff and its 55 // Keeps track of the number of attempts at exponential backoff and its
54 // related bookkeeping information for verification. 56 // related bookkeeping information for verification.
55 RetryVerifier retry_verifier_; 57 RetryVerifier retry_verifier_;
56 58
57 DISALLOW_COPY_AND_ASSIGN(ExponentialBackoffChecker); 59 DISALLOW_COPY_AND_ASSIGN(ExponentialBackoffChecker);
58 }; 60 };
59 61
60 IN_PROC_BROWSER_TEST_F(SyncExponentialBackoffTest, OfflineToOnline) { 62 IN_PROC_BROWSER_TEST_F(SyncExponentialBackoffTest, OfflineToOnline) {
61 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; 63 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
62 64
63 // Add an item and ensure that sync is successful. 65 // Add an item and ensure that sync is successful.
64 ASSERT_TRUE(AddFolder(0, 0, L"folder1")); 66 ASSERT_TRUE(AddFolder(0, 0, L"folder1"));
65 ASSERT_TRUE(GetClient(0)->AwaitCommitActivityCompletion()); 67 ASSERT_TRUE(GetClient(0)->AwaitCommitActivityCompletion());
66 68
67 // Trigger a network error at the client side. 69 // Trigger a network error at the client side.
68 DisableNetwork(GetProfile(0)); 70 DisableNetwork(GetProfile(0));
69 71
70 // Add a new item to trigger another sync cycle. 72 // Add a new item to trigger another sync cycle.
71 ASSERT_TRUE(AddFolder(0, 0, L"folder2")); 73 ASSERT_TRUE(AddFolder(0, 0, L"folder2"));
72 74
73 // Verify that the client goes into exponential backoff while it is unable to 75 // Verify that the client goes into exponential backoff while it is unable to
74 // reach the sync server. 76 // reach the sync server.
75 ExponentialBackoffChecker exponential_backoff_checker(GetClient(0)); 77 ExponentialBackoffChecker exponential_backoff_checker(
76 ASSERT_TRUE(GetClient(0)->AwaitStatusChange(&exponential_backoff_checker, 78 GetClient(0)->service());
77 "Checking exponential backoff")); 79 ASSERT_TRUE(GetClient(0)->AwaitStatusChange(&exponential_backoff_checker));
78 80
79 // Recover from the network error. 81 // Recover from the network error.
80 EnableNetwork(GetProfile(0)); 82 EnableNetwork(GetProfile(0));
81 83
82 // Verify that sync was able to recover. 84 // Verify that sync was able to recover.
83 ASSERT_TRUE(GetClient(0)->AwaitCommitActivityCompletion()); 85 ASSERT_TRUE(GetClient(0)->AwaitCommitActivityCompletion());
84 ASSERT_TRUE(ModelMatchesVerifier(0)); 86 ASSERT_TRUE(ModelMatchesVerifier(0));
85 } 87 }
86 88
87 IN_PROC_BROWSER_TEST_F(SyncExponentialBackoffTest, TransientErrorTest) { 89 IN_PROC_BROWSER_TEST_F(SyncExponentialBackoffTest, TransientErrorTest) {
88 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; 90 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
89 91
90 // Add an item and ensure that sync is successful. 92 // Add an item and ensure that sync is successful.
91 ASSERT_TRUE(AddFolder(0, 0, L"folder1")); 93 ASSERT_TRUE(AddFolder(0, 0, L"folder1"));
92 ASSERT_TRUE(GetClient(0)->AwaitCommitActivityCompletion()); 94 ASSERT_TRUE(GetClient(0)->AwaitCommitActivityCompletion());
93 95
94 // Trigger a transient error on the server. 96 // Trigger a transient error on the server.
95 TriggerTransientError(); 97 TriggerTransientError();
96 98
97 // Add a new item to trigger another sync cycle. 99 // Add a new item to trigger another sync cycle.
98 ASSERT_TRUE(AddFolder(0, 0, L"folder2")); 100 ASSERT_TRUE(AddFolder(0, 0, L"folder2"));
99 101
100 // Verify that the client goes into exponential backoff while it is unable to 102 // Verify that the client goes into exponential backoff while it is unable to
101 // reach the sync server. 103 // reach the sync server.
102 ExponentialBackoffChecker exponential_backoff_checker(GetClient(0)); 104 ExponentialBackoffChecker exponential_backoff_checker(
103 ASSERT_TRUE(GetClient(0)->AwaitStatusChange(&exponential_backoff_checker, 105 GetClient(0)->service());
104 "Checking exponential backoff")); 106 ASSERT_TRUE(GetClient(0)->AwaitStatusChange(&exponential_backoff_checker));
105 } 107 }
106 108
107 } // namespace 109 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/sync/test/integration/sync_errors_test.cc ('k') | chrome/browser/sync/test/integration/sync_test.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698