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. |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 python_path = current_python_path + ':' + extra_python_path | 99 python_path = current_python_path + ':' + extra_python_path |
100 else: | 100 else: |
101 python_path = extra_python_path | 101 python_path = extra_python_path |
102 | 102 |
103 # NOTE: A separate python process is used to simplify getting the right | 103 # NOTE: A separate python process is used to simplify getting the right |
104 # system path for finding includes. | 104 # system path for finding includes. |
105 test_server_flags = test_server_flags or [] | 105 test_server_flags = test_server_flags or [] |
106 cmd = ['python', os.path.join(src_dir, test_server_path), | 106 cmd = ['python', os.path.join(src_dir, test_server_path), |
107 '--log-to-console', | 107 '--log-to-console', |
108 ('--host=%s' % self.host), | 108 ('--host=%s' % self.host), |
109 ('--port=%d' % self.port)] + test_server_flags | 109 ('--port=%d' % self.port), |
| 110 '--on-remote-server'] + test_server_flags |
110 self._test_server_process = subprocess.Popen( | 111 self._test_server_process = subprocess.Popen( |
111 cmd, env={'PYTHONPATH': python_path}) | 112 cmd, env={'PYTHONPATH': python_path}) |
112 test_url = 'http://%s:%d/%s' % (self.host, self.port, | 113 test_url = 'http://%s:%d/%s' % (self.host, self.port, |
113 TEST_SERVER_CHECK_PARAMS[test_server_path]['url_path']) | 114 TEST_SERVER_CHECK_PARAMS[test_server_path]['url_path']) |
114 expected_response = TEST_SERVER_CHECK_PARAMS[test_server_path]['response'] | 115 expected_response = TEST_SERVER_CHECK_PARAMS[test_server_path]['response'] |
115 retries = 0 | 116 retries = 0 |
116 while retries < 5: | 117 while retries < 5: |
117 try: | 118 try: |
118 d = urllib2.urlopen(test_url).read() | 119 d = urllib2.urlopen(test_url).read() |
119 logging.info('URL %s GOT: %s' % (test_url, d)) | 120 logging.info('URL %s GOT: %s' % (test_url, d)) |
120 if d.startswith(expected_response): | 121 if d.startswith(expected_response): |
121 break | 122 break |
122 except Exception as e: | 123 except Exception as e: |
123 logging.info('URL %s GOT: %s' % (test_url, e)) | 124 logging.info('URL %s GOT: %s' % (test_url, e)) |
124 time.sleep(retries * 0.1) | 125 time.sleep(retries * 0.1) |
125 retries += 1 | 126 retries += 1 |
126 | 127 |
127 def TearDown(self): | 128 def TearDown(self): |
128 self._test_server_process.kill() | 129 self._test_server_process.kill() |
129 self._test_server_process.wait() | 130 self._test_server_process.wait() |
OLD | NEW |