OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 """A "Test Server Spawner" that handles killing/stopping per-test test servers. | 5 """A "Test Server Spawner" that handles killing/stopping per-test test servers. |
6 | 6 |
7 It's used to accept requests from the device to spawn and kill instances of the | 7 It's used to accept requests from the device to spawn and kill instances of the |
8 chrome test server on the host. | 8 chrome test server on the host. |
9 """ | 9 """ |
10 # pylint: disable=W0702 | 10 # pylint: disable=W0702 |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 content_length = self.headers.getheader('content-length') | 314 content_length = self.headers.getheader('content-length') |
315 if not content_length: | 315 if not content_length: |
316 content_length = 0 | 316 content_length = 0 |
317 try: | 317 try: |
318 content_length = int(content_length) | 318 content_length = int(content_length) |
319 except: | 319 except: |
320 raise Exception('Bad content-length for start request.') | 320 raise Exception('Bad content-length for start request.') |
321 logging.info(content_length) | 321 logging.info(content_length) |
322 test_server_argument_json = self.rfile.read(content_length) | 322 test_server_argument_json = self.rfile.read(content_length) |
323 logging.info(test_server_argument_json) | 323 logging.info(test_server_argument_json) |
324 assert not self.server.test_server_instance | 324 # There should only be one test server instance at a time. However it may |
| 325 # be possible that a previous instance was not cleaned up properly |
| 326 # (crbug.com/665686) |
| 327 if self.server.test_server_instance: |
| 328 port = self.server.test_server_instance.host_port |
| 329 logging.info('Killing lingering test server instance on port: %d', port) |
| 330 self.server.test_server_instance.Stop() |
| 331 self.server.test_server_instance = None |
325 ready_event = threading.Event() | 332 ready_event = threading.Event() |
326 self.server.test_server_instance = TestServerThread( | 333 self.server.test_server_instance = TestServerThread( |
327 ready_event, | 334 ready_event, |
328 json.loads(test_server_argument_json), | 335 json.loads(test_server_argument_json), |
329 self.server.device, | 336 self.server.device, |
330 self.server.tool) | 337 self.server.tool) |
331 self.server.test_server_instance.setDaemon(True) | 338 self.server.test_server_instance.setDaemon(True) |
332 self.server.test_server_instance.start() | 339 self.server.test_server_instance.start() |
333 ready_event.wait() | 340 ready_event.wait() |
334 if self.server.test_server_instance.is_ready: | 341 if self.server.test_server_instance.is_ready: |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 | 430 |
424 def CleanupState(self): | 431 def CleanupState(self): |
425 """Cleans up the spawning server state. | 432 """Cleans up the spawning server state. |
426 | 433 |
427 This should be called if the test server spawner is reused, | 434 This should be called if the test server spawner is reused, |
428 to avoid sharing the test server instance. | 435 to avoid sharing the test server instance. |
429 """ | 436 """ |
430 if self.server.test_server_instance: | 437 if self.server.test_server_instance: |
431 self.server.test_server_instance.Stop() | 438 self.server.test_server_instance.Stop() |
432 self.server.test_server_instance = None | 439 self.server.test_server_instance = None |
OLD | NEW |