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

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

Issue 10103017: Abort sync cycles when download step fails (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove notifications re-enable code Created 8 years, 8 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
« no previous file with comments | « sync/sessions/sync_session_unittest.cc ('k') | sync/test/engine/mock_connection_manager.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 (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 // Mock ServerConnectionManager class for use in client unit tests. 5 // Mock ServerConnectionManager class for use in client unit tests.
6 6
7 #ifndef SYNC_TEST_ENGINE_MOCK_CONNECTION_MANAGER_H_ 7 #ifndef SYNC_TEST_ENGINE_MOCK_CONNECTION_MANAGER_H_
8 #define SYNC_TEST_ENGINE_MOCK_CONNECTION_MANAGER_H_ 8 #define SYNC_TEST_ENGINE_MOCK_CONNECTION_MANAGER_H_
9 #pragma once 9 #pragma once
10 10
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 const std::string& entry_id); 110 const std::string& entry_id);
111 void SetLastUpdatePosition(int64 position_in_parent); 111 void SetLastUpdatePosition(int64 position_in_parent);
112 void SetNewTimestamp(int ts); 112 void SetNewTimestamp(int ts);
113 void SetChangesRemaining(int64 count); 113 void SetChangesRemaining(int64 count);
114 114
115 // Add a new batch of updates after the current one. Allows multiple 115 // Add a new batch of updates after the current one. Allows multiple
116 // GetUpdates responses to be buffered up, since the syncer may 116 // GetUpdates responses to be buffered up, since the syncer may
117 // issue multiple requests during a sync cycle. 117 // issue multiple requests during a sync cycle.
118 void NextUpdateBatch(); 118 void NextUpdateBatch();
119 119
120 void FailNextPostBufferToPathCall() { fail_next_postbuffer_ = true; } 120 void FailNextPostBufferToPathCall() { countdown_to_postbuffer_fail_ = 1; }
121 void FailNthPostBufferToPathCall(int n) { countdown_to_postbuffer_fail_ = n; }
121 122
122 void SetClearUserDataResponseStatus(sync_pb::SyncEnums::ErrorType errortype); 123 void SetClearUserDataResponseStatus(sync_pb::SyncEnums::ErrorType errortype);
123 124
124 // A visitor class to allow a test to change some monitoring state atomically
125 // with the action of overriding the response codes sent back to the Syncer
126 // (for example, so you can say "ThrottleNextRequest, and assert no more
127 // requests are made once throttling is in effect" in one step.
128 class ResponseCodeOverrideRequestor {
129 public:
130 // Called with response_code_override_lock_ acquired.
131 virtual void OnOverrideComplete() = 0;
132
133 protected:
134 virtual ~ResponseCodeOverrideRequestor() {}
135 };
136 void ThrottleNextRequest(ResponseCodeOverrideRequestor* visitor);
137 void FailWithAuthInvalid(ResponseCodeOverrideRequestor* visitor);
138 void StopFailingWithAuthInvalid(ResponseCodeOverrideRequestor* visitor);
139 void FailNonPeriodicGetUpdates() { fail_non_periodic_get_updates_ = true; } 125 void FailNonPeriodicGetUpdates() { fail_non_periodic_get_updates_ = true; }
140 126
141 // Simple inspectors. 127 // Simple inspectors.
142 bool client_stuck() const { return client_stuck_; } 128 bool client_stuck() const { return client_stuck_; }
143 129
144 sync_pb::ClientCommand* GetNextClientCommand(); 130 sync_pb::ClientCommand* GetNextClientCommand();
145 131
146 const std::vector<syncable::Id>& committed_ids() const { 132 const std::vector<syncable::Id>& committed_ids() const {
147 return committed_ids_; 133 return committed_ids_;
148 } 134 }
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 // cases where we're mocking out most of the code that performs network 201 // cases where we're mocking out most of the code that performs network
216 // requests. 202 // requests.
217 void UpdateConnectionStatus(); 203 void UpdateConnectionStatus();
218 204
219 // Return by copy to be thread-safe. 205 // Return by copy to be thread-safe.
220 const std::string store_birthday() { 206 const std::string store_birthday() {
221 base::AutoLock lock(store_birthday_lock_); 207 base::AutoLock lock(store_birthday_lock_);
222 return store_birthday_; 208 return store_birthday_;
223 } 209 }
224 210
211 // Explicitly indicate that we will not be fetching some updates.
212 void ClearUpdatesQueue() {
213 update_queue_.clear();
214 }
215
225 // Locate the most recent update message for purpose of alteration. 216 // Locate the most recent update message for purpose of alteration.
226 sync_pb::SyncEntity* GetMutableLastUpdate(); 217 sync_pb::SyncEntity* GetMutableLastUpdate();
227 218
228 private: 219 private:
229 sync_pb::SyncEntity* AddUpdateFull(syncable::Id id, syncable::Id parentid, 220 sync_pb::SyncEntity* AddUpdateFull(syncable::Id id, syncable::Id parentid,
230 std::string name, int64 version, 221 std::string name, int64 version,
231 int64 sync_ts, 222 int64 sync_ts,
232 bool is_dir); 223 bool is_dir);
233 sync_pb::SyncEntity* AddUpdateFull(std::string id, 224 sync_pb::SyncEntity* AddUpdateFull(std::string id,
234 std::string parentid, std::string name, 225 std::string parentid, std::string name,
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 // The next id the mock will return to a commit. 283 // The next id the mock will return to a commit.
293 int next_new_id_; 284 int next_new_id_;
294 285
295 // The store birthday we send to the client. 286 // The store birthday we send to the client.
296 std::string store_birthday_; 287 std::string store_birthday_;
297 base::Lock store_birthday_lock_; 288 base::Lock store_birthday_lock_;
298 bool store_birthday_sent_; 289 bool store_birthday_sent_;
299 bool client_stuck_; 290 bool client_stuck_;
300 std::string commit_time_rename_prepended_string_; 291 std::string commit_time_rename_prepended_string_;
301 292
302 // Fail on the next call to PostBufferToPath(). 293 // On each PostBufferToPath() call, we decrement this counter. The call fails
303 bool fail_next_postbuffer_; 294 // iff we hit zero at that call.
295 int countdown_to_postbuffer_fail_;
304 296
305 // Our directory. Used only to ensure that we are not holding the transaction 297 // Our directory. Used only to ensure that we are not holding the transaction
306 // lock when performing network I/O. Can be NULL if the test author is 298 // lock when performing network I/O. Can be NULL if the test author is
307 // confident this can't happen. 299 // confident this can't happen.
308 syncable::Directory* directory_; 300 syncable::Directory* directory_;
309 301
310 // The updates we'll return to the next request. 302 // The updates we'll return to the next request.
311 std::list<sync_pb::GetUpdatesResponse> update_queue_; 303 std::list<sync_pb::GetUpdatesResponse> update_queue_;
312 base::Closure mid_commit_callback_; 304 base::Closure mid_commit_callback_;
313 MidCommitObserver* mid_commit_observer_; 305 MidCommitObserver* mid_commit_observer_;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 int num_get_updates_requests_; 343 int num_get_updates_requests_;
352 344
353 std::string next_token_; 345 std::string next_token_;
354 346
355 sync_pb::ClientToServerMessage last_request_; 347 sync_pb::ClientToServerMessage last_request_;
356 348
357 DISALLOW_COPY_AND_ASSIGN(MockConnectionManager); 349 DISALLOW_COPY_AND_ASSIGN(MockConnectionManager);
358 }; 350 };
359 351
360 #endif // SYNC_TEST_ENGINE_MOCK_CONNECTION_MANAGER_H_ 352 #endif // SYNC_TEST_ENGINE_MOCK_CONNECTION_MANAGER_H_
OLDNEW
« no previous file with comments | « sync/sessions/sync_session_unittest.cc ('k') | sync/test/engine/mock_connection_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698