| 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 """Host driven test server controller. | 5 """Host driven test server controller. |
| 6 | 6 |
| 7 This class controls the startup and shutdown of a python driven test server that | 7 This class controls the startup and shutdown of a python driven test server that |
| 8 runs in a separate process. | 8 runs in a separate process. |
| 9 | 9 |
| 10 The server starts up automatically when the object is created. | 10 The server starts up automatically when the object is created. |
| 11 | 11 |
| 12 After it starts up, it is possible to retreive the hostname it started on | 12 After it starts up, it is possible to retreive the hostname it started on |
| 13 through accessing the member field |host| and the port name through |port|. | 13 through accessing the member field |host| and the port name through |port|. |
| 14 | 14 |
| 15 For shutting down the server, call TearDown(). | 15 For shutting down the server, call TearDown(). |
| 16 """ | 16 """ |
| 17 | 17 |
| 18 import logging | 18 import logging |
| 19 import subprocess | 19 import subprocess |
| 20 import os | 20 import os |
| 21 import os.path | 21 import os.path |
| 22 import time | 22 import time |
| 23 import urllib2 | 23 import urllib2 |
| 24 | 24 |
| 25 from pylib import constants | 25 from pylib import constants |
| 26 from pylib.constants import host_paths |
| 26 | 27 |
| 27 # NOTE: when adding or modifying these lines, omit any leading slashes! | 28 # NOTE: when adding or modifying these lines, omit any leading slashes! |
| 28 # Otherwise os.path.join() will (correctly) treat them as absolute paths | 29 # Otherwise os.path.join() will (correctly) treat them as absolute paths |
| 29 # instead of relative paths, and will do nothing. | 30 # instead of relative paths, and will do nothing. |
| 30 _PYTHONPATH_DIRS = [ | 31 _PYTHONPATH_DIRS = [ |
| 31 'net/tools/testserver/', | 32 'net/tools/testserver/', |
| 32 'third_party/', | 33 'third_party/', |
| 33 'third_party/pyftpdlib/src/', | 34 'third_party/pyftpdlib/src/', |
| 34 'third_party/pywebsocket/src', | 35 'third_party/pywebsocket/src', |
| 35 'third_party/tlslite/', | 36 'third_party/tlslite/', |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 shard_index: Index of the current shard. | 81 shard_index: Index of the current shard. |
| 81 test_server_port: Port to run the test server on. This is multiplexed with | 82 test_server_port: Port to run the test server on. This is multiplexed with |
| 82 the shard index. To retrieve the real port access the | 83 the shard index. To retrieve the real port access the |
| 83 member variable |port|. | 84 member variable |port|. |
| 84 test_server_path: The path (relative to the root src dir) of the server | 85 test_server_path: The path (relative to the root src dir) of the server |
| 85 test_server_flags: Optional list of additional flags to the test server | 86 test_server_flags: Optional list of additional flags to the test server |
| 86 """ | 87 """ |
| 87 self.host = _TEST_SERVER_HOST | 88 self.host = _TEST_SERVER_HOST |
| 88 self.port = test_server_port + shard_index | 89 self.port = test_server_port + shard_index |
| 89 | 90 |
| 90 src_dir = constants.DIR_SOURCE_ROOT | 91 src_dir = host_paths.DIR_SOURCE_ROOT |
| 91 # Make dirs into a list of absolute paths. | 92 # Make dirs into a list of absolute paths. |
| 92 abs_dirs = [os.path.join(src_dir, d) for d in _PYTHONPATH_DIRS] | 93 abs_dirs = [os.path.join(src_dir, d) for d in _PYTHONPATH_DIRS] |
| 93 # Add the generated python files to the path | 94 # Add the generated python files to the path |
| 94 abs_dirs.extend([os.path.join(src_dir, constants.GetOutDirectory(), d) | 95 abs_dirs.extend([os.path.join(src_dir, constants.GetOutDirectory(), d) |
| 95 for d in _GENERATED_PYTHONPATH_DIRS]) | 96 for d in _GENERATED_PYTHONPATH_DIRS]) |
| 96 current_python_path = os.environ.get('PYTHONPATH') | 97 current_python_path = os.environ.get('PYTHONPATH') |
| 97 extra_python_path = ':'.join(abs_dirs) | 98 extra_python_path = ':'.join(abs_dirs) |
| 98 if current_python_path: | 99 if current_python_path: |
| 99 python_path = current_python_path + ':' + extra_python_path | 100 python_path = current_python_path + ':' + extra_python_path |
| 100 else: | 101 else: |
| (...skipping 20 matching lines...) Expand all Loading... |
| 121 if d.startswith(expected_response): | 122 if d.startswith(expected_response): |
| 122 break | 123 break |
| 123 except Exception as e: # pylint: disable=broad-except | 124 except Exception as e: # pylint: disable=broad-except |
| 124 logging.info('URL %s GOT: %s', test_url, e) | 125 logging.info('URL %s GOT: %s', test_url, e) |
| 125 time.sleep(retries * 0.1) | 126 time.sleep(retries * 0.1) |
| 126 retries += 1 | 127 retries += 1 |
| 127 | 128 |
| 128 def TearDown(self): | 129 def TearDown(self): |
| 129 self._test_server_process.kill() | 130 self._test_server_process.kill() |
| 130 self._test_server_process.wait() | 131 self._test_server_process.wait() |
| OLD | NEW |