| 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 | 10 |
| (...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 self.server.adb = adb | 390 self.server.adb = adb |
| 391 self.server.tool = tool | 391 self.server.tool = tool |
| 392 self.server.test_server_instance = None | 392 self.server.test_server_instance = None |
| 393 self.server.build_type = build_type | 393 self.server.build_type = build_type |
| 394 | 394 |
| 395 def _Listen(self): | 395 def _Listen(self): |
| 396 logging.info('Starting test server spawner') | 396 logging.info('Starting test server spawner') |
| 397 self.server.serve_forever() | 397 self.server.serve_forever() |
| 398 | 398 |
| 399 def Start(self): | 399 def Start(self): |
| 400 """Starts the test server spawner.""" |
| 400 listener_thread = threading.Thread(target=self._Listen) | 401 listener_thread = threading.Thread(target=self._Listen) |
| 401 listener_thread.setDaemon(True) | 402 listener_thread.setDaemon(True) |
| 402 listener_thread.start() | 403 listener_thread.start() |
| 403 time.sleep(1) | 404 time.sleep(1) |
| 404 | 405 |
| 405 def Stop(self): | 406 def Stop(self): |
| 407 """Stops the test server spawner. |
| 408 |
| 409 Also cleans the server state. |
| 410 """ |
| 411 self.CleanupState() |
| 412 self.server.shutdown() |
| 413 |
| 414 def CleanupState(self): |
| 415 """Cleans up the spawning server state. |
| 416 |
| 417 This should be called if the test server spawner is reused, |
| 418 to avoid sharing the test server instance. |
| 419 """ |
| 406 if self.server.test_server_instance: | 420 if self.server.test_server_instance: |
| 407 self.server.test_server_instance.Stop() | 421 self.server.test_server_instance.Stop() |
| 408 self.server.shutdown() | 422 self.server.test_server_instance = None |
| OLD | NEW |