| OLD | NEW |
| (Empty) |
| 1 # Copyright (c) 2009 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 """Base class with common routines between the Apache and Lighttpd servers.""" | |
| 6 | |
| 7 import logging | |
| 8 import time | |
| 9 import urllib | |
| 10 | |
| 11 | |
| 12 class HttpServerBase(object): | |
| 13 | |
| 14 def WaitForAction(self, action): | |
| 15 """Repeat the action for 20 seconds or until it succeeds. Returns | |
| 16 whether it succeeded.""" | |
| 17 start_time = time.time() | |
| 18 while time.time() - start_time < 20: | |
| 19 if action(): | |
| 20 return True | |
| 21 time.sleep(1) | |
| 22 | |
| 23 return False | |
| 24 | |
| 25 def IsServerRunningOnAllPorts(self): | |
| 26 """Returns whether the server is running on all the desired ports.""" | |
| 27 for mapping in self.mappings: | |
| 28 if 'sslcert' in mapping: | |
| 29 http_suffix = 's' | |
| 30 else: | |
| 31 http_suffix = '' | |
| 32 | |
| 33 url = 'http%s://127.0.0.1:%d/' % (http_suffix, mapping['port']) | |
| 34 | |
| 35 try: | |
| 36 response = urllib.urlopen(url) | |
| 37 logging.debug("Server running at %s" % url) | |
| 38 except IOError: | |
| 39 logging.debug("Server NOT running at %s" % url) | |
| 40 return False | |
| 41 | |
| 42 return True | |
| OLD | NEW |