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

Side by Side Diff: components/sync/test/engine/mock_connection_manager.h

Issue 2475043002: [Sync] Sync client should to exponential backoff when receive partial failure (Closed)
Patch Set: rebase Created 4 years, 1 month 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_ENGINE_MOCK_CONNECTION_MANAGER_H_ 5 #ifndef COMPONENTS_SYNC_TEST_ENGINE_MOCK_CONNECTION_MANAGER_H_
6 #define COMPONENTS_SYNC_TEST_ENGINE_MOCK_CONNECTION_MANAGER_H_ 6 #define COMPONENTS_SYNC_TEST_ENGINE_MOCK_CONNECTION_MANAGER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <bitset> 10 #include <bitset>
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 use_legacy_bookmarks_protocol_ = value; 209 use_legacy_bookmarks_protocol_ = value;
210 } 210 }
211 211
212 void set_store_birthday(const std::string& new_birthday) { 212 void set_store_birthday(const std::string& new_birthday) {
213 // Multiple threads can set store_birthday_ in our tests, need to lock it to 213 // Multiple threads can set store_birthday_ in our tests, need to lock it to
214 // ensure atomic read/writes and avoid race conditions. 214 // ensure atomic read/writes and avoid race conditions.
215 base::AutoLock lock(store_birthday_lock_); 215 base::AutoLock lock(store_birthday_lock_);
216 store_birthday_ = new_birthday; 216 store_birthday_ = new_birthday;
217 } 217 }
218 218
219 void set_partial_throttling(bool value) { partialThrottling_ = value; } 219 void set_throttling(bool value) { throttling_ = value; }
220
221 void set_partial_failure(bool value) { partial_failure_ = value; }
220 222
221 // Retrieve the number of GetUpdates requests that the mock server has 223 // Retrieve the number of GetUpdates requests that the mock server has
222 // seen since the last time this function was called. Can be used to 224 // seen since the last time this function was called. Can be used to
223 // verify that a GetUpdates actually did or did not happen after running 225 // verify that a GetUpdates actually did or did not happen after running
224 // the syncer. 226 // the syncer.
225 int GetAndClearNumGetUpdatesRequests() { 227 int GetAndClearNumGetUpdatesRequests() {
226 int result = num_get_updates_requests_; 228 int result = num_get_updates_requests_;
227 num_get_updates_requests_ = 0; 229 num_get_updates_requests_ = 0;
228 return result; 230 return result;
229 } 231 }
230 232
231 // Expect that GetUpdates will request exactly the types indicated in 233 // Expect that GetUpdates will request exactly the types indicated in
232 // the bitset. 234 // the bitset.
233 void ExpectGetUpdatesRequestTypes(ModelTypeSet expected_filter) { 235 void ExpectGetUpdatesRequestTypes(ModelTypeSet expected_filter) {
234 expected_filter_ = expected_filter; 236 expected_filter_ = expected_filter;
235 } 237 }
236 238
237 // Set throttled date types. 239 // Set partial failure date types.
238 void SetThrottledTypes(ModelTypeSet types) { throttled_type_ = types; } 240 void SetPartialFailureTypes(ModelTypeSet types) {
241 partial_failure_type_ = types;
242 }
239 243
240 void SetServerReachable(); 244 void SetServerReachable();
241 245
242 void SetServerNotReachable(); 246 void SetServerNotReachable();
243 247
244 // Updates our internal state as if we had attempted a connection. Does not 248 // Updates our internal state as if we had attempted a connection. Does not
245 // send notifications as a real connection attempt would. This is useful in 249 // send notifications as a real connection attempt would. This is useful in
246 // cases where we're mocking out most of the code that performs network 250 // cases where we're mocking out most of the code that performs network
247 // requests. 251 // requests.
248 void UpdateConnectionStatus(); 252 void UpdateConnectionStatus();
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 372
369 // The AUTHENTICATE response we'll return for auth requests. 373 // The AUTHENTICATE response we'll return for auth requests.
370 sync_pb::AuthenticateResponse auth_response_; 374 sync_pb::AuthenticateResponse auth_response_;
371 // What we use to determine if we should return SUCCESS or BAD_AUTH_TOKEN. 375 // What we use to determine if we should return SUCCESS or BAD_AUTH_TOKEN.
372 std::string valid_auth_token_; 376 std::string valid_auth_token_;
373 377
374 // Whether we are faking a server mandating clients to throttle requests. 378 // Whether we are faking a server mandating clients to throttle requests.
375 // Protected by |response_code_override_lock_|. 379 // Protected by |response_code_override_lock_|.
376 bool throttling_; 380 bool throttling_;
377 381
378 // Whether we are faking a server mandating clients to partial throttle 382 // Whether we are faking a server mandating clients to partial failure
379 // requests. 383 // requests.
380 // Protected by |response_code_override_lock_|. 384 // Protected by |response_code_override_lock_|.
381 bool partialThrottling_; 385 bool partial_failure_;
382 386
383 base::Lock response_code_override_lock_; 387 base::Lock response_code_override_lock_;
384 388
385 // True if we are only accepting GetUpdatesCallerInfo::PERIODIC requests. 389 // True if we are only accepting GetUpdatesCallerInfo::PERIODIC requests.
386 bool fail_non_periodic_get_updates_; 390 bool fail_non_periodic_get_updates_;
387 391
388 std::unique_ptr<sync_pb::ClientCommand> gu_client_command_; 392 std::unique_ptr<sync_pb::ClientCommand> gu_client_command_;
389 std::unique_ptr<sync_pb::ClientCommand> commit_client_command_; 393 std::unique_ptr<sync_pb::ClientCommand> commit_client_command_;
390 394
391 // The next value to use for the position_in_parent property. 395 // The next value to use for the position_in_parent property.
392 int64_t next_position_in_parent_; 396 int64_t next_position_in_parent_;
393 397
394 // The default is to use the newer sync_pb::BookmarkSpecifics-style protocol. 398 // The default is to use the newer sync_pb::BookmarkSpecifics-style protocol.
395 // If this option is set to true, then the MockConnectionManager will 399 // If this option is set to true, then the MockConnectionManager will
396 // use the older sync_pb::SyncEntity_BookmarkData-style protocol. 400 // use the older sync_pb::SyncEntity_BookmarkData-style protocol.
397 bool use_legacy_bookmarks_protocol_; 401 bool use_legacy_bookmarks_protocol_;
398 402
399 ModelTypeSet expected_filter_; 403 ModelTypeSet expected_filter_;
400 404
401 ModelTypeSet throttled_type_; 405 ModelTypeSet partial_failure_type_;
402 406
403 int num_get_updates_requests_; 407 int num_get_updates_requests_;
404 408
405 std::string next_token_; 409 std::string next_token_;
406 410
407 std::vector<sync_pb::ClientToServerMessage> requests_; 411 std::vector<sync_pb::ClientToServerMessage> requests_;
408 412
409 DISALLOW_COPY_AND_ASSIGN(MockConnectionManager); 413 DISALLOW_COPY_AND_ASSIGN(MockConnectionManager);
410 }; 414 };
411 415
412 } // namespace syncer 416 } // namespace syncer
413 417
414 #endif // COMPONENTS_SYNC_TEST_ENGINE_MOCK_CONNECTION_MANAGER_H_ 418 #endif // COMPONENTS_SYNC_TEST_ENGINE_MOCK_CONNECTION_MANAGER_H_
OLDNEW
« no previous file with comments | « components/sync/test/engine/fake_sync_scheduler.cc ('k') | components/sync/test/engine/mock_connection_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698