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/strings/stringprintf.h" | 6 #include "base/strings/stringprintf.h" |
7 #include "chrome/browser/sync/profile_sync_service.h" | 7 #include "chrome/browser/sync/profile_sync_service.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 | 13 |
14 namespace { | 14 namespace { |
15 | 15 |
16 using bookmarks_helper::AddFolder; | 16 using bookmarks_helper::AddFolder; |
17 using bookmarks_helper::ModelMatchesVerifier; | 17 using bookmarks_helper::ModelMatchesVerifier; |
18 using syncer::sessions::SyncSessionSnapshot; | 18 using syncer::sessions::SyncSessionSnapshot; |
19 using sync_integration_test_util::AwaitCommitActivityCompletion; | 19 using sync_integration_test_util::AwaitCommitActivityCompletion; |
20 | 20 |
21 class SyncExponentialBackoffTest : public SyncTest { | 21 class SyncExponentialBackoffTest : public SyncTest { |
22 public: | 22 public: |
23 // TODO(pvalenzuela): Switch to SINGLE_CLIENT once FakeServer | 23 SyncExponentialBackoffTest() : SyncTest(SINGLE_CLIENT) {} |
24 // supports this scenario. | |
25 SyncExponentialBackoffTest() : SyncTest(SINGLE_CLIENT_LEGACY) {} | |
26 virtual ~SyncExponentialBackoffTest() {} | 24 virtual ~SyncExponentialBackoffTest() {} |
27 | 25 |
28 private: | 26 private: |
29 DISALLOW_COPY_AND_ASSIGN(SyncExponentialBackoffTest); | 27 DISALLOW_COPY_AND_ASSIGN(SyncExponentialBackoffTest); |
30 }; | 28 }; |
31 | 29 |
32 // Helper class that checks if a sync client has successfully gone through | 30 // Helper class that checks if a sync client has successfully gone through |
33 // exponential backoff after it encounters an error. | 31 // exponential backoff after it encounters an error. |
34 class ExponentialBackoffChecker : public SingleClientStatusChangeChecker { | 32 class ExponentialBackoffChecker : public SingleClientStatusChangeChecker { |
35 public: | 33 public: |
(...skipping 27 matching lines...) Expand all Loading... |
63 DISALLOW_COPY_AND_ASSIGN(ExponentialBackoffChecker); | 61 DISALLOW_COPY_AND_ASSIGN(ExponentialBackoffChecker); |
64 }; | 62 }; |
65 | 63 |
66 IN_PROC_BROWSER_TEST_F(SyncExponentialBackoffTest, OfflineToOnline) { | 64 IN_PROC_BROWSER_TEST_F(SyncExponentialBackoffTest, OfflineToOnline) { |
67 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 65 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
68 | 66 |
69 // Add an item and ensure that sync is successful. | 67 // Add an item and ensure that sync is successful. |
70 ASSERT_TRUE(AddFolder(0, 0, "folder1")); | 68 ASSERT_TRUE(AddFolder(0, 0, "folder1")); |
71 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0)))); | 69 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0)))); |
72 | 70 |
73 // Trigger a network error at the client side. | 71 GetFakeServer()->DisableNetwork(); |
74 DisableNetwork(GetProfile(0)); | |
75 | 72 |
76 // Add a new item to trigger another sync cycle. | 73 // Add a new item to trigger another sync cycle. |
77 ASSERT_TRUE(AddFolder(0, 0, "folder2")); | 74 ASSERT_TRUE(AddFolder(0, 0, "folder2")); |
78 | 75 |
79 // Verify that the client goes into exponential backoff while it is unable to | 76 // Verify that the client goes into exponential backoff while it is unable to |
80 // reach the sync server. | 77 // reach the sync server. |
81 ExponentialBackoffChecker exponential_backoff_checker( | 78 ExponentialBackoffChecker exponential_backoff_checker( |
82 GetSyncService((0))); | 79 GetSyncService((0))); |
83 exponential_backoff_checker.Wait(); | 80 exponential_backoff_checker.Wait(); |
84 ASSERT_FALSE(exponential_backoff_checker.TimedOut()); | 81 ASSERT_FALSE(exponential_backoff_checker.TimedOut()); |
85 | 82 |
86 // Recover from the network error. | 83 GetFakeServer()->EnableNetwork(); |
87 EnableNetwork(GetProfile(0)); | |
88 | 84 |
89 // Verify that sync was able to recover. | 85 // Verify that sync was able to recover. |
90 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0)))); | 86 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0)))); |
91 ASSERT_TRUE(ModelMatchesVerifier(0)); | 87 ASSERT_TRUE(ModelMatchesVerifier(0)); |
92 } | 88 } |
93 | 89 |
94 IN_PROC_BROWSER_TEST_F(SyncExponentialBackoffTest, TransientErrorTest) { | 90 IN_PROC_BROWSER_TEST_F(SyncExponentialBackoffTest, TransientErrorTest) { |
95 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; | 91 ASSERT_TRUE(SetupSync()) << "SetupSync() failed."; |
96 | 92 |
97 // Add an item and ensure that sync is successful. | 93 // Add an item and ensure that sync is successful. |
98 ASSERT_TRUE(AddFolder(0, 0, "folder1")); | 94 ASSERT_TRUE(AddFolder(0, 0, "folder1")); |
99 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0)))); | 95 ASSERT_TRUE(AwaitCommitActivityCompletion(GetSyncService((0)))); |
100 | 96 |
101 // Trigger a transient error on the server. | 97 GetFakeServer()->TriggerError(sync_pb::SyncEnums::TRANSIENT_ERROR); |
102 TriggerTransientError(); | |
103 | 98 |
104 // Add a new item to trigger another sync cycle. | 99 // Add a new item to trigger another sync cycle. |
105 ASSERT_TRUE(AddFolder(0, 0, "folder2")); | 100 ASSERT_TRUE(AddFolder(0, 0, "folder2")); |
106 | 101 |
107 // 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 |
108 // reach the sync server. | 103 // reach the sync server. |
109 ExponentialBackoffChecker exponential_backoff_checker( | 104 ExponentialBackoffChecker exponential_backoff_checker( |
110 GetSyncService((0))); | 105 GetSyncService((0))); |
111 exponential_backoff_checker.Wait(); | 106 exponential_backoff_checker.Wait(); |
112 ASSERT_FALSE(exponential_backoff_checker.TimedOut()); | 107 ASSERT_FALSE(exponential_backoff_checker.TimedOut()); |
113 } | 108 } |
114 | 109 |
115 } // namespace | 110 } // namespace |
OLD | NEW |