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

Unified Diff: net/tools/testserver/chromiumsync.py

Issue 7811026: Python server to test the actionable error feature. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: For review. Created 9 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | net/tools/testserver/testserver.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/tools/testserver/chromiumsync.py
diff --git a/net/tools/testserver/chromiumsync.py b/net/tools/testserver/chromiumsync.py
index a8a939c3a68b75eb86c4c950014fbdc21d1bed8a..17ee41535231c8f60c3631ba167625f8bbb8284e 100755
--- a/net/tools/testserver/chromiumsync.py
+++ b/net/tools/testserver/chromiumsync.py
@@ -105,6 +105,10 @@ class TransientError(Error):
"""The client would be sent a transient error."""
+class SyncInducedError(Error):
+ """The client would be sent an error."""
+
+
def GetEntryType(entry):
"""Extract the sync type from a SyncEntry.
@@ -415,6 +419,8 @@ class SyncDataModel(object):
self.migration_history = MigrationHistory()
+ self.induced_error = sync_pb2.ClientToServerResponse.Error()
+
def _SaveEntry(self, entry):
"""Insert or update an entry in the change log, and give it a new version.
@@ -880,6 +886,12 @@ class SyncDataModel(object):
True)
self._SaveEntry(nigori_new)
+ def SetInducedError(self, error):
+ self.induced_error = error
+
+ def GetInducedError(self):
+ return self.induced_error
+
class TestServer(object):
"""An object to handle requests for one (and only one) Chrome Sync account.
@@ -922,6 +934,12 @@ class TestServer(object):
if self.transient_error:
raise TransientError
+ def CheckSendError(self):
+ """Raises SyncInducedError if needed."""
+ if self.account.induced_error.error_type !=\
+ sync_pb2.ClientToServerResponse.UNKNOWN:
ncarter (slow) 2011/09/22 20:27:53 "Make use of Python's implicit line joining inside
+ raise SyncInducedError
+
def HandleMigrate(self, path):
query = urlparse.urlparse(path)[4]
code = 200
@@ -944,6 +962,39 @@ class TestServer(object):
return (code, '<html><title>Migration: %d</title><H1>%d %s</H1></html>' %
(code, code, response))
+ def HandleSetInducedError(self, path):
+ query = urlparse.urlparse(path)[4]
+ self.account_lock.acquire()
+ code = 200;
+ response = 'Success'
+ error = sync_pb2.ClientToServerResponse.Error()
+ try:
+ error_type = urlparse.parse_qs(query)['error']
+ action = urlparse.parse_qs(query)['action']
+ error.error_type = int(error_type[0])
+ error.action = int(action[0])
+ try:
+ error.url = (urlparse.parse_qs(query)['url'])[0]
+ except KeyError:
+ error.url = ''
+ try:
+ error.error_description = \
ncarter (slow) 2011/09/22 20:27:53 Don't escape newlines. It's very common to see ex
+ (urlparse.parse_qs(query)['error_description'])[0]
+ except KeyError:
+ error.error_description = ''
+ self.account.SetInducedError(error)
+ response = ('Error = %d, action = %d, url = %s, description = %s' %
+ (error.error_type, error.action,
+ error.url,
+ error.error_description))
+ except error:
+ response = 'Could not parse url'
+ code = 400
+ finally:
+ self.account_lock.release()
+ return (code, '<html><title>Migration: %d</title><H1>%d %s</H1></html>' %
+ (code, code, response))
+
def HandleCreateBirthdayError(self):
self.account.ResetStoreBirthday()
return (
@@ -992,6 +1043,7 @@ class TestServer(object):
self.CheckStoreBirthday(request)
response.store_birthday = self.account.store_birthday
self.CheckTransientError();
+ self.CheckSendError();
print_context('->')
@@ -1030,11 +1082,22 @@ class TestServer(object):
response.error_code = sync_pb2.ClientToServerResponse.NOT_MY_BIRTHDAY
return (200, response.SerializeToString())
except TransientError, error:
+ ### This is deprecated now. Would be remvoved once test cases are removed.
ncarter (slow) 2011/09/22 20:27:53 "remvoved"
print_context('<-')
print 'TRANSIENT_ERROR'
response.store_birthday = self.account.store_birthday
response.error_code = sync_pb2.ClientToServerResponse.TRANSIENT_ERROR
return (200, response.SerializeToString())
+ except SyncInducedError, error:
+ print_context('<-')
+ print 'INDUCED_ERROR'
+ response.store_birthday = self.account.store_birthday
+ error = self.account.GetInducedError()
+ response.error.error_type = error.error_type
+ response.error.url = error.url
+ response.error.error_description = error.error_description
+ response.error.action = error.action
+ return (200, response.SerializeToString())
finally:
self.account_lock.release()
« no previous file with comments | « no previous file | net/tools/testserver/testserver.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698