Chromium Code Reviews| Index: net/tools/testserver/chromiumsync.py |
| diff --git a/net/tools/testserver/chromiumsync.py b/net/tools/testserver/chromiumsync.py |
| index a8a939c3a68b75eb86c4c950014fbdc21d1bed8a..3e6ea9ce3f8504895232199ff0d1c520c6c8cac2 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: |
| + 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 = \ |
| + (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>SetError: %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. |
|
Raghu Simha
2011/09/22 21:57:41
This comment still doesn't follow the style guide.
|
| 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() |