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

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

Issue 2973833002: [Sync] Added integ tests to verify UserEvents retry on TRANSIENT_ERROR. (Closed)
Patch Set: Created 3 years, 5 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
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 COMPONENTS_SYNC_TEST_FAKE_SERVER_FAKE_SERVER_H_ 5 #ifndef COMPONENTS_SYNC_TEST_FAKE_SERVER_FAKE_SERVER_H_
6 #define COMPONENTS_SYNC_TEST_FAKE_SERVER_FAKE_SERVER_H_ 6 #define COMPONENTS_SYNC_TEST_FAKE_SERVER_FAKE_SERVER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 // Forces every request to fail in a way that simulates a network failure. 139 // Forces every request to fail in a way that simulates a network failure.
140 // This can be used to trigger exponential backoff in the client. 140 // This can be used to trigger exponential backoff in the client.
141 void DisableNetwork(); 141 void DisableNetwork();
142 142
143 // Returns the entity ID of the Bookmark Bar folder. 143 // Returns the entity ID of the Bookmark Bar folder.
144 std::string GetBookmarkBarFolderId() const; 144 std::string GetBookmarkBarFolderId() const;
145 145
146 // Returns the current FakeServer as a WeakPtr. 146 // Returns the current FakeServer as a WeakPtr.
147 base::WeakPtr<FakeServer> AsWeakPtr(); 147 base::WeakPtr<FakeServer> AsWeakPtr();
148 148
149 using ResponseTypeProvider =
150 base::RepeatingCallback<sync_pb::CommitResponse::ResponseType(
151 const FakeServerEntity& entity)>;
152
153 // Use this callback to generate response types for entities. They will still
154 // be "committed" and stored as normal, this only affects the response type
155 // the client sees. This allows tests to still inspect what the client has
156 // done, although not as useful of a mechanism for multi client tests. Care
157 // should be taken when failing responses, as the client will go into
158 // exponential backoff, which can cause tests to be slow or time out.
159 void OverrideResponseType(ResponseTypeProvider response_type_override);
160
149 private: 161 private:
150 using EntityMap = std::map<std::string, std::unique_ptr<FakeServerEntity>>; 162 using EntityMap = std::map<std::string, std::unique_ptr<FakeServerEntity>>;
151 163
152 // Gets FakeServer ready for syncing. 164 // Gets FakeServer ready for syncing.
153 void Init(); 165 void Init();
154 166
155 // Processes a GetUpdates call. 167 // Processes a GetUpdates call.
156 bool HandleGetUpdatesRequest(const sync_pb::GetUpdatesMessage& get_updates, 168 bool HandleGetUpdatesRequest(const sync_pb::GetUpdatesMessage& get_updates,
157 sync_pb::GetUpdatesResponse* response); 169 sync_pb::GetUpdatesResponse* response);
158 170
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 base::ObserverList<Observer, true> observers_; 260 base::ObserverList<Observer, true> observers_;
249 261
250 // When true, the server operates normally. When false, a failure is returned 262 // When true, the server operates normally. When false, a failure is returned
251 // on every request. This is used to simulate a network failure on the client. 263 // on every request. This is used to simulate a network failure on the client.
252 bool network_enabled_; 264 bool network_enabled_;
253 265
254 // The last received client to server messages. 266 // The last received client to server messages.
255 sync_pb::ClientToServerMessage last_commit_message_; 267 sync_pb::ClientToServerMessage last_commit_message_;
256 sync_pb::ClientToServerMessage last_getupdates_message_; 268 sync_pb::ClientToServerMessage last_getupdates_message_;
257 269
270 ResponseTypeProvider response_type_override_;
271
258 // Used to verify that FakeServer is only used from one thread. 272 // Used to verify that FakeServer is only used from one thread.
259 base::ThreadChecker thread_checker_; 273 base::ThreadChecker thread_checker_;
260 274
261 // Creates WeakPtr versions of the current FakeServer. This must be the last 275 // Creates WeakPtr versions of the current FakeServer. This must be the last
262 // data member! 276 // data member!
263 base::WeakPtrFactory<FakeServer> weak_ptr_factory_; 277 base::WeakPtrFactory<FakeServer> weak_ptr_factory_;
264 }; 278 };
265 279
266 } // namespace fake_server 280 } // namespace fake_server
267 281
268 #endif // COMPONENTS_SYNC_TEST_FAKE_SERVER_FAKE_SERVER_H_ 282 #endif // COMPONENTS_SYNC_TEST_FAKE_SERVER_FAKE_SERVER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698