OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 """Base class for running tests on a single device.""" | 5 """Base class for running tests on a single device.""" |
6 | 6 |
7 import contextlib | |
8 import httplib | |
9 import logging | 7 import logging |
10 import os | |
11 import tempfile | |
12 import time | 8 import time |
13 | 9 |
14 from pylib import android_commands | 10 from pylib import android_commands |
15 from pylib import constants | |
16 from pylib import ports | 11 from pylib import ports |
17 from pylib.chrome_test_server_spawner import SpawningServer | 12 from pylib.chrome_test_server_spawner import SpawningServer |
18 from pylib.forwarder import Forwarder | 13 from pylib.forwarder import Forwarder |
19 from pylib.valgrind_tools import CreateTool | 14 from pylib.valgrind_tools import CreateTool |
20 # TODO(frankf): Move this to pylib/utils | 15 # TODO(frankf): Move this to pylib/utils |
21 import lighttpd_server | 16 import lighttpd_server |
22 | 17 |
23 | 18 |
24 # A file on device to store ports of net test server. The format of the file is | 19 # A file on device to store ports of net test server. The format of the file is |
25 # test-spawner-server-port:test-server-port | 20 # test-spawner-server-port:test-server-port |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 self._spawning_server.CleanupState() | 169 self._spawning_server.CleanupState() |
175 | 170 |
176 def LaunchChromeTestServerSpawner(self): | 171 def LaunchChromeTestServerSpawner(self): |
177 """Launches test server spawner.""" | 172 """Launches test server spawner.""" |
178 server_ready = False | 173 server_ready = False |
179 error_msgs = [] | 174 error_msgs = [] |
180 # TODO(pliard): deflake this function. The for loop should be removed as | 175 # TODO(pliard): deflake this function. The for loop should be removed as |
181 # well as IsHttpServerConnectable(). spawning_server.Start() should also | 176 # well as IsHttpServerConnectable(). spawning_server.Start() should also |
182 # block until the server is ready. | 177 # block until the server is ready. |
183 # Try 3 times to launch test spawner server. | 178 # Try 3 times to launch test spawner server. |
184 for i in xrange(0, 3): | 179 for _ in xrange(0, 3): |
185 self.test_server_spawner_port = ports.AllocateTestServerPort() | 180 self.test_server_spawner_port = ports.AllocateTestServerPort() |
186 self._ForwardPorts( | 181 self._ForwardPorts( |
187 [(self.test_server_spawner_port, self.test_server_spawner_port)]) | 182 [(self.test_server_spawner_port, self.test_server_spawner_port)]) |
188 self._spawning_server = SpawningServer(self.test_server_spawner_port, | 183 self._spawning_server = SpawningServer(self.test_server_spawner_port, |
189 self.adb, | 184 self.adb, |
190 self.tool) | 185 self.tool) |
191 self._spawning_server.Start() | 186 self._spawning_server.Start() |
192 server_ready, error_msg = ports.IsHttpServerConnectable( | 187 server_ready, error_msg = ports.IsHttpServerConnectable( |
193 '127.0.0.1', self.test_server_spawner_port, path='/ping', | 188 '127.0.0.1', self.test_server_spawner_port, path='/ping', |
194 expected_read='ready') | 189 expected_read='ready') |
195 if server_ready: | 190 if server_ready: |
196 break | 191 break |
197 else: | 192 else: |
198 error_msgs.append(error_msg) | 193 error_msgs.append(error_msg) |
199 self._spawning_server.Stop() | 194 self._spawning_server.Stop() |
200 # Wait for 2 seconds then restart. | 195 # Wait for 2 seconds then restart. |
201 time.sleep(2) | 196 time.sleep(2) |
202 if not server_ready: | 197 if not server_ready: |
203 logging.error(';'.join(error_msgs)) | 198 logging.error(';'.join(error_msgs)) |
204 raise Exception('Can not start the test spawner server.') | 199 raise Exception('Can not start the test spawner server.') |
205 self._PushTestServerPortInfoToDevice() | 200 self._PushTestServerPortInfoToDevice() |
OLD | NEW |