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

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

Issue 167873002: sync: Improve StatusChangeChecker debug strings (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/status_change_checker.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 StatusChangeChecker {
30 public: 31 public:
31 explicit ExponentialBackoffChecker(const ProfileSyncServiceHarness* harness) 32 explicit ExponentialBackoffChecker(const ProfileSyncServiceHarness* harness)
32 : StatusChangeChecker("ExponentialBackoffChecker"), 33 : harness_(harness) {
33 harness_(harness) {
34 DCHECK(harness); 34 DCHECK(harness);
35 const SyncSessionSnapshot& snap = harness_->GetLastSessionSnapshot(); 35 const SyncSessionSnapshot& snap = harness_->GetLastSessionSnapshot();
36 retry_verifier_.Initialize(snap); 36 retry_verifier_.Initialize(snap);
37 } 37 }
38 38
39 virtual ~ExponentialBackoffChecker() {} 39 virtual ~ExponentialBackoffChecker() {}
40 40
41 // Checks if backoff is complete. Called repeatedly each time PSS notifies 41 // Checks if backoff is complete. Called repeatedly each time PSS notifies
42 // observers of a state change. 42 // observers of a state change.
43 virtual bool IsExitConditionSatisfied() OVERRIDE { 43 virtual bool IsExitConditionSatisfied() OVERRIDE {
44 const SyncSessionSnapshot& snap = harness_->GetLastSessionSnapshot(); 44 const SyncSessionSnapshot& snap = harness_->GetLastSessionSnapshot();
45 retry_verifier_.VerifyRetryInterval(snap); 45 retry_verifier_.VerifyRetryInterval(snap);
46 return (retry_verifier_.done() && retry_verifier_.Succeeded()); 46 return (retry_verifier_.done() && retry_verifier_.Succeeded());
47 } 47 }
48 48
49 virtual std::string GetDebugMessage() const OVERRIDE {
50 return base::StringPrintf("Verifying backoff intervals (%d/%d)",
51 retry_verifier_.retry_count(),
52 RetryVerifier::kMaxRetry);
53 }
54
49 private: 55 private:
50 // The sync client for which backoff is being verified. 56 // The sync client for which backoff is being verified.
51 const ProfileSyncServiceHarness* harness_; 57 const ProfileSyncServiceHarness* harness_;
52 58
53 // Keeps track of the number of attempts at exponential backoff and its 59 // Keeps track of the number of attempts at exponential backoff and its
54 // related bookkeeping information for verification. 60 // related bookkeeping information for verification.
55 RetryVerifier retry_verifier_; 61 RetryVerifier retry_verifier_;
56 62
57 DISALLOW_COPY_AND_ASSIGN(ExponentialBackoffChecker); 63 DISALLOW_COPY_AND_ASSIGN(ExponentialBackoffChecker);
58 }; 64 };
59 65
60 IN_PROC_BROWSER_TEST_F(SyncExponentialBackoffTest, OfflineToOnline) { 66 IN_PROC_BROWSER_TEST_F(SyncExponentialBackoffTest, OfflineToOnline) {
61 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; 67 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
62 68
63 // Add an item and ensure that sync is successful. 69 // Add an item and ensure that sync is successful.
64 ASSERT_TRUE(AddFolder(0, 0, L"folder1")); 70 ASSERT_TRUE(AddFolder(0, 0, L"folder1"));
65 ASSERT_TRUE(GetClient(0)->AwaitCommitActivityCompletion()); 71 ASSERT_TRUE(GetClient(0)->AwaitCommitActivityCompletion());
66 72
67 // Trigger a network error at the client side. 73 // Trigger a network error at the client side.
68 DisableNetwork(GetProfile(0)); 74 DisableNetwork(GetProfile(0));
69 75
70 // Add a new item to trigger another sync cycle. 76 // Add a new item to trigger another sync cycle.
71 ASSERT_TRUE(AddFolder(0, 0, L"folder2")); 77 ASSERT_TRUE(AddFolder(0, 0, L"folder2"));
72 78
73 // Verify that the client goes into exponential backoff while it is unable to 79 // Verify that the client goes into exponential backoff while it is unable to
74 // reach the sync server. 80 // reach the sync server.
75 ExponentialBackoffChecker exponential_backoff_checker(GetClient(0)); 81 ExponentialBackoffChecker exponential_backoff_checker(GetClient(0));
76 ASSERT_TRUE(GetClient(0)->AwaitStatusChange(&exponential_backoff_checker, 82 ASSERT_TRUE(GetClient(0)->AwaitStatusChange(&exponential_backoff_checker));
77 "Checking exponential backoff"));
78 83
79 // Recover from the network error. 84 // Recover from the network error.
80 EnableNetwork(GetProfile(0)); 85 EnableNetwork(GetProfile(0));
81 86
82 // Verify that sync was able to recover. 87 // Verify that sync was able to recover.
83 ASSERT_TRUE(GetClient(0)->AwaitCommitActivityCompletion()); 88 ASSERT_TRUE(GetClient(0)->AwaitCommitActivityCompletion());
84 ASSERT_TRUE(ModelMatchesVerifier(0)); 89 ASSERT_TRUE(ModelMatchesVerifier(0));
85 } 90 }
86 91
87 IN_PROC_BROWSER_TEST_F(SyncExponentialBackoffTest, TransientErrorTest) { 92 IN_PROC_BROWSER_TEST_F(SyncExponentialBackoffTest, TransientErrorTest) {
88 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; 93 ASSERT_TRUE(SetupSync()) << "SetupSync() failed.";
89 94
90 // Add an item and ensure that sync is successful. 95 // Add an item and ensure that sync is successful.
91 ASSERT_TRUE(AddFolder(0, 0, L"folder1")); 96 ASSERT_TRUE(AddFolder(0, 0, L"folder1"));
92 ASSERT_TRUE(GetClient(0)->AwaitCommitActivityCompletion()); 97 ASSERT_TRUE(GetClient(0)->AwaitCommitActivityCompletion());
93 98
94 // Trigger a transient error on the server. 99 // Trigger a transient error on the server.
95 TriggerTransientError(); 100 TriggerTransientError();
96 101
97 // Add a new item to trigger another sync cycle. 102 // Add a new item to trigger another sync cycle.
98 ASSERT_TRUE(AddFolder(0, 0, L"folder2")); 103 ASSERT_TRUE(AddFolder(0, 0, L"folder2"));
99 104
100 // Verify that the client goes into exponential backoff while it is unable to 105 // Verify that the client goes into exponential backoff while it is unable to
101 // reach the sync server. 106 // reach the sync server.
102 ExponentialBackoffChecker exponential_backoff_checker(GetClient(0)); 107 ExponentialBackoffChecker exponential_backoff_checker(GetClient(0));
103 ASSERT_TRUE(GetClient(0)->AwaitStatusChange(&exponential_backoff_checker, 108 ASSERT_TRUE(GetClient(0)->AwaitStatusChange(&exponential_backoff_checker));
104 "Checking exponential backoff"));
105 } 109 }
106 110
107 } // namespace 111 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698