| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2013 The LUCI Authors. All rights reserved. | 2 # Copyright 2013 The LUCI Authors. All rights reserved. |
| 3 # Use of this source code is governed under the Apache License, Version 2.0 | 3 # Use of this source code is governed under the Apache License, Version 2.0 |
| 4 # that can be found in the LICENSE file. | 4 # that can be found in the LICENSE file. |
| 5 | 5 |
| 6 import datetime | 6 import datetime |
| 7 import hashlib | 7 import hashlib |
| 8 import json | 8 import json |
| 9 import logging | 9 import logging |
| 10 import os | 10 import os |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 import auth | 25 import auth |
| 26 import isolateserver | 26 import isolateserver |
| 27 import swarming | 27 import swarming |
| 28 import test_utils | 28 import test_utils |
| 29 | 29 |
| 30 from depot_tools import fix_encoding | 30 from depot_tools import fix_encoding |
| 31 from utils import file_path | 31 from utils import file_path |
| 32 from utils import logging_utils | 32 from utils import logging_utils |
| 33 from utils import tools | 33 from utils import tools |
| 34 | 34 |
| 35 import httpserver_mock |
| 35 import isolateserver_mock | 36 import isolateserver_mock |
| 36 | 37 |
| 37 | 38 |
| 38 FILE_HASH = u'1' * 40 | 39 FILE_HASH = u'1' * 40 |
| 39 TEST_NAME = u'unit_tests' | 40 TEST_NAME = u'unit_tests' |
| 40 | 41 |
| 41 | 42 |
| 42 OUTPUT = 'Ran stuff\n' | 43 OUTPUT = 'Ran stuff\n' |
| 43 | 44 |
| 44 SHARD_OUTPUT_1 = 'Shard 1 of 3.' | 45 SHARD_OUTPUT_1 = 'Shard 1 of 3.' |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 class NonBlockingEvent(threading._Event): # pylint: disable=W0212 | 149 class NonBlockingEvent(threading._Event): # pylint: disable=W0212 |
| 149 """Just like threading.Event, but a class and ignores timeout in 'wait'. | 150 """Just like threading.Event, but a class and ignores timeout in 'wait'. |
| 150 | 151 |
| 151 Intended to be used as a mock for threading.Event in tests. | 152 Intended to be used as a mock for threading.Event in tests. |
| 152 """ | 153 """ |
| 153 | 154 |
| 154 def wait(self, timeout=None): | 155 def wait(self, timeout=None): |
| 155 return super(NonBlockingEvent, self).wait(0) | 156 return super(NonBlockingEvent, self).wait(0) |
| 156 | 157 |
| 157 | 158 |
| 158 class SwarmingServerHandler(isolateserver_mock.MockHandler): | 159 class SwarmingServerHandler(httpserver_mock.MockHandler): |
| 159 """An extremely minimal implementation of the swarming server API v1.0.""" | 160 """An extremely minimal implementation of the swarming server API v1.0.""" |
| 160 | 161 |
| 161 def do_GET(self): | 162 def do_GET(self): |
| 162 logging.info('S GET %s', self.path) | 163 logging.info('S GET %s', self.path) |
| 163 if self.path in ('/on/load', '/on/quit'): | 164 if self.path in ('/on/load', '/on/quit'): |
| 164 self._octet_stream('') | 165 self._octet_stream('') |
| 165 elif self.path == '/auth/api/v1/server/oauth_config': | 166 elif self.path == '/auth/api/v1/server/oauth_config': |
| 166 self._json({ | 167 self._json({ |
| 167 'client_id': 'c', | 168 'client_id': 'c', |
| 168 'client_not_so_secret': 's', | 169 'client_not_so_secret': 's', |
| 169 'primary_url': self.server.url}) | 170 'primary_url': self.server.url}) |
| 170 elif self.path == '/auth/api/v1/accounts/self': | 171 elif self.path == '/auth/api/v1/accounts/self': |
| 171 self._json({'identity': 'user:joe', 'xsrf_token': 'foo'}) | 172 self._json({'identity': 'user:joe', 'xsrf_token': 'foo'}) |
| 172 else: | 173 else: |
| 173 m = re.match(r'/_ah/api/swarming/v1/task/(\d+)/request', self.path) | 174 m = re.match(r'/_ah/api/swarming/v1/task/(\d+)/request', self.path) |
| 174 if m: | 175 if m: |
| 175 logging.info('%s', m.group(1)) | 176 logging.info('%s', m.group(1)) |
| 176 self._json(self.server.tasks[int(m.group(1))]) | 177 self._json(self.server.tasks[int(m.group(1))]) |
| 177 else: | 178 else: |
| 178 self._json( {'a': 'b'}) | 179 self._json( {'a': 'b'}) |
| 179 #raise NotImplementedError(self.path) | 180 #raise NotImplementedError(self.path) |
| 180 | 181 |
| 181 def do_POST(self): | 182 def do_POST(self): |
| 182 logging.info('POST %s', self.path) | 183 logging.info('POST %s', self.path) |
| 183 raise NotImplementedError(self.path) | 184 raise NotImplementedError(self.path) |
| 184 | 185 |
| 185 | 186 |
| 186 class MockSwarmingServer(isolateserver_mock.MockServer): | 187 class MockSwarmingServer(httpserver_mock.MockServer): |
| 187 _HANDLER_CLS = SwarmingServerHandler | 188 _HANDLER_CLS = SwarmingServerHandler |
| 188 | 189 |
| 189 def __init__(self): | 190 def __init__(self): |
| 190 super(MockSwarmingServer, self).__init__() | 191 super(MockSwarmingServer, self).__init__() |
| 191 self._server.tasks = {} | 192 self._server.tasks = {} |
| 192 | 193 |
| 193 | 194 |
| 194 class Common(object): | 195 class Common(object): |
| 195 def setUp(self): | 196 def setUp(self): |
| 196 self._tempdir = None | 197 self._tempdir = None |
| (...skipping 1187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1384 | 1385 |
| 1385 if __name__ == '__main__': | 1386 if __name__ == '__main__': |
| 1386 fix_encoding.fix_encoding() | 1387 fix_encoding.fix_encoding() |
| 1387 logging.basicConfig( | 1388 logging.basicConfig( |
| 1388 level=logging.DEBUG if '-v' in sys.argv else logging.CRITICAL) | 1389 level=logging.DEBUG if '-v' in sys.argv else logging.CRITICAL) |
| 1389 if '-v' in sys.argv: | 1390 if '-v' in sys.argv: |
| 1390 unittest.TestCase.maxDiff = None | 1391 unittest.TestCase.maxDiff = None |
| 1391 for e in ('ISOLATE_SERVER', 'SWARMING_TASK_ID', 'SWARMING_SERVER'): | 1392 for e in ('ISOLATE_SERVER', 'SWARMING_TASK_ID', 'SWARMING_SERVER'): |
| 1392 os.environ.pop(e, None) | 1393 os.environ.pop(e, None) |
| 1393 unittest.main() | 1394 unittest.main() |
| OLD | NEW |