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 import contextlib | 5 import contextlib |
6 import httplib | 6 import httplib |
7 import logging | 7 import logging |
8 import os | 8 import os |
9 import tempfile | 9 import tempfile |
10 import time | 10 import time |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 # proper hand-shake/shutdown. | 159 # proper hand-shake/shutdown. |
160 Forwarder.KillDevice(self.adb, self.tool) | 160 Forwarder.KillDevice(self.adb, self.tool) |
161 if self._forwarder: | 161 if self._forwarder: |
162 self._forwarder.Close() | 162 self._forwarder.Close() |
163 if self._http_server: | 163 if self._http_server: |
164 self._http_server.ShutdownHttpServer() | 164 self._http_server.ShutdownHttpServer() |
165 if self._spawning_server: | 165 if self._spawning_server: |
166 self._spawning_server.Stop() | 166 self._spawning_server.Stop() |
167 self.flags.Restore() | 167 self.flags.Restore() |
168 | 168 |
| 169 def CleanupSpawningServerState(self): |
| 170 """Tells the spawning server to clean up any state. |
| 171 |
| 172 If the spawning server is reused for multiple tests, this should be called |
| 173 after each test to prevent tests affecting each other. |
| 174 """ |
| 175 if self._spawning_server: |
| 176 self._spawning_server.CleanupState() |
| 177 |
169 def LaunchChromeTestServerSpawner(self): | 178 def LaunchChromeTestServerSpawner(self): |
170 """Launches test server spawner.""" | 179 """Launches test server spawner.""" |
171 server_ready = False | 180 server_ready = False |
172 error_msgs = [] | 181 error_msgs = [] |
173 # Try 3 times to launch test spawner server. | 182 # Try 3 times to launch test spawner server. |
174 for i in xrange(0, 3): | 183 for i in xrange(0, 3): |
175 # Do not allocate port for test server here. We will allocate | 184 # Do not allocate port for test server here. We will allocate |
176 # different port for individual test in TestServerThread. | 185 # different port for individual test in TestServerThread. |
177 self.test_server_spawner_port = ports.AllocateTestServerPort() | 186 self.test_server_spawner_port = ports.AllocateTestServerPort() |
178 self._spawning_server = SpawningServer(self.test_server_spawner_port, | 187 self._spawning_server = SpawningServer(self.test_server_spawner_port, |
(...skipping 12 matching lines...) Expand all Loading... |
191 # Wait for 2 seconds then restart. | 200 # Wait for 2 seconds then restart. |
192 time.sleep(2) | 201 time.sleep(2) |
193 if not server_ready: | 202 if not server_ready: |
194 logging.error(';'.join(error_msgs)) | 203 logging.error(';'.join(error_msgs)) |
195 raise Exception('Can not start the test spawner server.') | 204 raise Exception('Can not start the test spawner server.') |
196 self._PushTestServerPortInfoToDevice() | 205 self._PushTestServerPortInfoToDevice() |
197 self._spawner_forwarder = self._CreateAndRunForwarder( | 206 self._spawner_forwarder = self._CreateAndRunForwarder( |
198 self.adb, | 207 self.adb, |
199 [(self.test_server_spawner_port, self.test_server_spawner_port)], | 208 [(self.test_server_spawner_port, self.test_server_spawner_port)], |
200 self.tool, '127.0.0.1', self.build_type) | 209 self.tool, '127.0.0.1', self.build_type) |
OLD | NEW |