diff options
author | mhm@chromium.org <mhm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-07 23:53:57 +0000 |
---|---|---|
committer | mhm@chromium.org <mhm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-07 23:53:57 +0000 |
commit | d9735af55ab6fe947c68eb27c686df901d260398 (patch) | |
tree | 57e50782673d320a12aa602a3d62db69bf894b1e /tools/python | |
parent | 01c022ac4ee3ba1c3840544f3493cf0690e03125 (diff) | |
download | chromium_src-d9735af55ab6fe947c68eb27c686df901d260398.zip chromium_src-d9735af55ab6fe947c68eb27c686df901d260398.tar.gz chromium_src-d9735af55ab6fe947c68eb27c686df901d260398.tar.bz2 |
Clean up code duplication in layout test http_server.
Refactored out UrlIsAlive to live outside the ApacheHttpd class and imported http_utils.py into http_server.py
Now they share common code.
BUG=6784
TEST=started and stopped http_server successfully.
Review URL: http://codereview.chromium.org/243022
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28351 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/python')
-rw-r--r-- | tools/python/google/httpd_utils.py | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/tools/python/google/httpd_utils.py b/tools/python/google/httpd_utils.py index 309c924..e7cfe09 100644 --- a/tools/python/google/httpd_utils.py +++ b/tools/python/google/httpd_utils.py @@ -18,6 +18,31 @@ import google.platform_utils class HttpdNotStarted(Exception): pass +def UrlIsAlive(url): + """Checks to see if we get an http response from |url|. + We poll the url 5 times with a 1 second delay. If we don't + get a reply in that time, we give up and assume the httpd + didn't start properly. + + Args: + url: The URL to check. + Return: + True if the url is alive. + """ + wait_time = 5 + while wait_time > 0: + try: + response = urllib.urlopen(url) + # Server is up and responding. + return True + except IOError: + pass + wait_time -= 1 + # Wait a second and try again. + time.sleep(1) + + return False + def ApacheConfigDir(start_dir): """Returns a path to the directory holding the Apache config files.""" return google.path_utils.FindUpward(start_dir, 'tools', 'python', @@ -122,34 +147,9 @@ class ApacheHttpd(object): # Ensure that the server is running on all the desired ports. for port in self._port_list: - if not self._UrlIsAlive('http://127.0.0.1:%s/' % str(port)): + if not UrlIsAlive('http://127.0.0.1:%s/' % str(port)): raise HttpdNotStarted('Failed to start httpd on port %s' % str(port)) - def _UrlIsAlive(self, url): - """Checks to see if we get an http response from |url|. - We poll the url 5 times with a 1 second delay. If we don't - get a reply in that time, we give up and assume the httpd - didn't start properly. - - Args: - url: The URL to check. - Return: - True if the url is alive. - """ - wait_time = 5 - while wait_time > 0: - try: - response = urllib.urlopen(url) - # Server is up and responding. - return True - except IOError: - pass - wait_time -= 1 - # Wait a second and try again. - time.sleep(1) - - return False - def StopServer(self, force=False): """If we started an httpd.exe process, or if force is True, call self._stop_command (passed in on init so it can be platform-dependent). |