diff options
author | tim@chromium.org <tim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-16 01:31:55 +0000 |
---|---|---|
committer | tim@chromium.org <tim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-16 01:31:55 +0000 |
commit | 1b4ec9a088731d6cd028ffdf6695b0f5e2748846 (patch) | |
tree | 739d90bcbc8b5aa4c3d171d0e9d62ddb1c6c51a4 /chrome/test/sync | |
parent | 4f92fbc2765f3bd2db6d076c9b4d17410b847538 (diff) | |
download | chromium_src-1b4ec9a088731d6cd028ffdf6695b0f5e2748846.zip chromium_src-1b4ec9a088731d6cd028ffdf6695b0f5e2748846.tar.gz chromium_src-1b4ec9a088731d6cd028ffdf6695b0f5e2748846.tar.bz2 |
Hook up ClientToServerResponse::THROTTLED to the client sync loop.
TEST=Added SyncerThreadWithSyncerTest.Throttling
Review URL: http://codereview.chromium.org/269101
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29236 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/test/sync')
-rw-r--r-- | chrome/test/sync/engine/mock_server_connection.cc | 26 | ||||
-rw-r--r-- | chrome/test/sync/engine/mock_server_connection.h | 20 |
2 files changed, 46 insertions, 0 deletions
diff --git a/chrome/test/sync/engine/mock_server_connection.cc b/chrome/test/sync/engine/mock_server_connection.cc index 46ec870..372d408 100644 --- a/chrome/test/sync/engine/mock_server_connection.cc +++ b/chrome/test/sync/engine/mock_server_connection.cc @@ -44,6 +44,8 @@ MockConnectionManager::MockConnectionManager(DirectoryManager* dirmgr, mid_commit_callback_function_(NULL), mid_commit_observer_(NULL), client_command_(NULL), + throttling_(false), + fail_non_periodic_get_updates_(false), next_position_in_parent_(2) { server_reachable_ = true; }; @@ -105,6 +107,7 @@ bool MockConnectionManager::PostBufferToPath(const PostBufferParams* params, EXPECT_TRUE(!store_birthday_sent_ || post.has_store_birthday() || post.message_contents() == ClientToServerMessage::AUTHENTICATE); store_birthday_sent_ = true; + if (post.message_contents() == ClientToServerMessage::COMMIT) { ProcessCommit(&post, &response); } else if (post.message_contents() == ClientToServerMessage::GET_UPDATES) { @@ -118,6 +121,15 @@ bool MockConnectionManager::PostBufferToPath(const PostBufferParams* params, if (client_command_.get()) { response.mutable_client_command()->CopyFrom(*client_command_.get()); } + + { + AutoLock throttle_lock(throttle_lock_); + if (throttling_) { + response.set_error_code(ClientToServerResponse::THROTTLED); + throttling_ = false; + } + } + response.SerializeToString(params->buffer_out); if (mid_commit_callback_function_) { if (mid_commit_callback_function_(directory)) @@ -126,6 +138,7 @@ bool MockConnectionManager::PostBufferToPath(const PostBufferParams* params, if (mid_commit_observer_) { mid_commit_observer_->Observe(); } + return result; } @@ -248,6 +261,11 @@ void MockConnectionManager::ProcessGetUpdates(ClientToServerMessage* csm, ASSERT_EQ(csm->message_contents(), ClientToServerMessage::GET_UPDATES); const GetUpdatesMessage& gu = csm->get_updates(); EXPECT_TRUE(gu.has_from_timestamp()); + if (fail_non_periodic_get_updates_) { + EXPECT_EQ(sync_pb::GetUpdatesCallerInfo::PERIODIC, + gu.caller_info().source()); + } + // TODO(sync): filter results dependant on timestamp? or check limits? response->mutable_get_updates()->CopyFrom(updates_); ResetUpdates(); @@ -380,3 +398,11 @@ const CommitMessage& MockConnectionManager::last_sent_commit() const { DCHECK(!commit_messages_.empty()); return *commit_messages_.back(); } + +void MockConnectionManager::ThrottleNextRequest( + ThrottleRequestVisitor* visitor) { + AutoLock lock(throttle_lock_); + throttling_ = true; + if (visitor) + visitor->VisitAtomically(); +}
\ No newline at end of file diff --git a/chrome/test/sync/engine/mock_server_connection.h b/chrome/test/sync/engine/mock_server_connection.h index 1c19a5b..e203081 100644 --- a/chrome/test/sync/engine/mock_server_connection.h +++ b/chrome/test/sync/engine/mock_server_connection.h @@ -117,6 +117,18 @@ class MockConnectionManager : public browser_sync::ServerConnectionManager { void FailNextPostBufferToPathCall() { fail_next_postbuffer_ = true; } + // A visitor class to allow a test to change some monitoring state atomically + // with the action of throttling requests (for example, so you can say + // "ThrottleNextRequest, and assert no more requests are made once throttling + // is in effect" in one step. + class ThrottleRequestVisitor { + public: + // Called with throttle parameter lock acquired. + virtual void VisitAtomically() = 0; + }; + void ThrottleNextRequest(ThrottleRequestVisitor* visitor); + void FailNonPeriodicGetUpdates() { fail_non_periodic_get_updates_ = true; } + // Simple inspectors. bool client_stuck() const { return client_stuck_; } @@ -204,6 +216,14 @@ class MockConnectionManager : public browser_sync::ServerConnectionManager { // What we use to determine if we should return SUCCESS or BAD_AUTH_TOKEN. std::string valid_auth_token_; + // Whether we are faking a server mandating clients to throttle requests. + // Protected by |throttle_lock_|. + bool throttling_; + Lock throttle_lock_; + + // True if we are only accepting GetUpdatesCallerInfo::PERIODIC requests. + bool fail_non_periodic_get_updates_; + scoped_ptr<sync_pb::ClientCommand> client_command_; // The next value to use for the position_in_parent property. |