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

Side by Side Diff: sync/test/fake_server/fake_server.h

Issue 650463003: Improve error triggering in sync_integration_tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
« no previous file with comments | « chrome/browser/sync/test/integration/sync_test.cc ('k') | sync/test/fake_server/fake_server.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 #ifndef SYNC_TEST_FAKE_SERVER_FAKE_SERVER_H_ 5 #ifndef SYNC_TEST_FAKE_SERVER_FAKE_SERVER_H_
6 #define SYNC_TEST_FAKE_SERVER_FAKE_SERVER_H_ 6 #define SYNC_TEST_FAKE_SERVER_FAKE_SERVER_H_
7 7
8 #include <map> 8 #include <map>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 // Puts the server in a state where it acts as if authentication has 65 // Puts the server in a state where it acts as if authentication has
66 // succeeded. 66 // succeeded.
67 void SetAuthenticated(); 67 void SetAuthenticated();
68 68
69 // Puts the server in a state where all commands will fail with an 69 // Puts the server in a state where all commands will fail with an
70 // authentication error. 70 // authentication error.
71 void SetUnauthenticated(); 71 void SetUnauthenticated();
72 72
73 // Force the server to return |error_type| in the error_code field of 73 // Force the server to return |error_type| in the error_code field of
74 // ClientToServerResponse on all subsequent sync requests. This method should 74 // ClientToServerResponse on all subsequent sync requests. This method should
75 // not be called if TriggerActionableError has previously been called. 75 // not be called if TriggerActionableError has previously been called. Returns
76 // TODO(pvalenzuela): Return a bool here to indicate whether the call 76 // true if error triggering was successfully configured.
77 // succeeded. 77 bool TriggerError(const sync_pb::SyncEnums::ErrorType& error_type);
78 void TriggerError(const sync_pb::SyncEnums::ErrorType& error_type);
79 78
80 // Force the server to return the given data as part of the error field of 79 // Force the server to return the given data as part of the error field of
81 // ClientToServerResponse on all subsequent sync requests. This method should 80 // ClientToServerResponse on all subsequent sync requests. This method should
82 // not be called if TriggerError has previously been called. 81 // not be called if TriggerError has previously been called. Returns true if
82 // error triggering was successfully configured.
83 bool TriggerActionableError( 83 bool TriggerActionableError(
84 const sync_pb::SyncEnums::ErrorType& error_type, 84 const sync_pb::SyncEnums::ErrorType& error_type,
85 const std::string& description, 85 const std::string& description,
86 const std::string& url, 86 const std::string& url,
87 const sync_pb::SyncEnums::Action& action); 87 const sync_pb::SyncEnums::Action& action);
88 88
89 // Instructs the server to send triggered errors on every other request
90 // (starting with the first one after this call). This feature can be used to
91 // test the resiliency of the client when communicating with a problematic
92 // server or flaky network connection. This method should only be called
93 // after a call to TriggerError or TriggerActionableError. Returns true if
94 // triggered error alternating was successful.
95 bool EnableAlternatingTriggeredErrors();
96
89 // Adds |observer| to FakeServer's observer list. This should be called 97 // Adds |observer| to FakeServer's observer list. This should be called
90 // before the Profile associated with |observer| is connected to the server. 98 // before the Profile associated with |observer| is connected to the server.
91 void AddObserver(Observer* observer); 99 void AddObserver(Observer* observer);
92 100
93 // Removes |observer| from the FakeServer's observer list. This method 101 // Removes |observer| from the FakeServer's observer list. This method
94 // must be called if AddObserver was ever called with |observer|. 102 // must be called if AddObserver was ever called with |observer|.
95 void RemoveObserver(Observer* observer); 103 void RemoveObserver(Observer* observer);
96 104
97 // Undoes the effects of DisableNetwork. 105 // Undoes the effects of DisableNetwork.
98 void EnableNetwork(); 106 void EnableNetwork();
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 FakeServerEntity* entity); 148 FakeServerEntity* entity);
141 149
142 // Determines whether the SyncEntity with id_string |id| is a child of an 150 // Determines whether the SyncEntity with id_string |id| is a child of an
143 // entity with id_string |potential_parent_id|. 151 // entity with id_string |potential_parent_id|.
144 bool IsChild(const std::string& id, const std::string& potential_parent_id); 152 bool IsChild(const std::string& id, const std::string& potential_parent_id);
145 153
146 // Creates and saves tombstones for all children of the entity with the given 154 // Creates and saves tombstones for all children of the entity with the given
147 // |id|. A tombstone is not created for the entity itself. 155 // |id|. A tombstone is not created for the entity itself.
148 bool DeleteChildren(const std::string& id); 156 bool DeleteChildren(const std::string& id);
149 157
158 // Returns whether a triggered error should be sent for the request.
159 bool ShouldSendTriggeredError() const;
160
150 // This is the last version number assigned to an entity. The next entity will 161 // This is the last version number assigned to an entity. The next entity will
151 // have a version number of version_ + 1. 162 // have a version number of version_ + 1.
152 int64 version_; 163 int64 version_;
153 164
154 // The current store birthday value. 165 // The current store birthday value.
155 std::string store_birthday_; 166 std::string store_birthday_;
156 167
157 // Whether the server should act as if incoming connections are properly 168 // Whether the server should act as if incoming connections are properly
158 // authenticated. 169 // authenticated.
159 bool authenticated_; 170 bool authenticated_;
160 171
161 // All SyncEntity objects saved by the server. The key value is the entity's 172 // All SyncEntity objects saved by the server. The key value is the entity's
162 // id string. 173 // id string.
163 EntityMap entities_; 174 EntityMap entities_;
164 175
165 // All Keystore keys known to the server. 176 // All Keystore keys known to the server.
166 std::vector<std::string> keystore_keys_; 177 std::vector<std::string> keystore_keys_;
167 178
168 // Used as the error_code field of ClientToServerResponse on all responses 179 // Used as the error_code field of ClientToServerResponse on all responses
169 // except when |triggered_actionable_error_| is set. 180 // except when |triggered_actionable_error_| is set.
170 sync_pb::SyncEnums::ErrorType error_type_; 181 sync_pb::SyncEnums::ErrorType error_type_;
171 182
172 // Used as the error field of ClientToServerResponse when its pointer is not 183 // Used as the error field of ClientToServerResponse when its pointer is not
173 // NULL. 184 // NULL.
174 scoped_ptr<sync_pb::ClientToServerResponse_Error> triggered_actionable_error_; 185 scoped_ptr<sync_pb::ClientToServerResponse_Error> triggered_actionable_error_;
175 186
187 // These values are used in tandem to return a triggered error (either
188 // |error_type_| or |triggered_actionable_error_|) on every other request.
189 // |alternate_triggered_errors_| is set if this feature is enabled and
190 // |request_counter_| is used to send triggered errors on odd-numbered
191 // requests. Note that |request_counter_| can be reset and is not necessarily
192 // indicative of the total number of requests handled during the object's
193 // lifetime.
194 bool alternate_triggered_errors_;
195 int request_counter_;
196
176 // FakeServer's observers. 197 // FakeServer's observers.
177 ObserverList<Observer, true> observers_; 198 ObserverList<Observer, true> observers_;
178 199
179 // When true, the server operates normally. When false, a failure is returned 200 // When true, the server operates normally. When false, a failure is returned
180 // on every request. This is used to simulate a network failure on the client. 201 // on every request. This is used to simulate a network failure on the client.
181 bool network_enabled_; 202 bool network_enabled_;
182 }; 203 };
183 204
184 } // namespace fake_server 205 } // namespace fake_server
185 206
186 #endif // SYNC_TEST_FAKE_SERVER_FAKE_SERVER_H_ 207 #endif // SYNC_TEST_FAKE_SERVER_FAKE_SERVER_H_
OLDNEW
« no previous file with comments | « chrome/browser/sync/test/integration/sync_test.cc ('k') | sync/test/fake_server/fake_server.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698