diff --git a/scripts/functional_tests.py b/scripts/functional_tests.py index 8a8faec10c8..8fc09bfd88d 100644 --- a/scripts/functional_tests.py +++ b/scripts/functional_tests.py @@ -1,6 +1,5 @@ #!/usr/bin/env python -import httplib import os import os.path import random @@ -10,7 +9,6 @@ import socket import sys import tempfile import threading -import time from ConfigParser import SafeConfigParser from json import dumps @@ -326,15 +324,7 @@ def main(): t = threading.Thread( target=server.serve_forever ) t.start() - # Test if the server is up - for i in range( 10 ): - conn = httplib.HTTPConnection( galaxy_test_host, galaxy_test_port ) # directly test the app, not the proxy - conn.request( "GET", "/" ) - if conn.getresponse().status == 200: - break - time.sleep( 0.1 ) - else: - raise Exception( "Test HTTP server did not return '200 OK' after 10 tries" ) + driver_util.wait_for_http_server(galaxy_test_host, galaxy_test_port) log.info( "Embedded web server started" ) # ---- Find tests --------------------------------------------------------- diff --git a/test/base/driver_util.py b/test/base/driver_util.py index aeda67acb96..d8c36be55fe 100644 --- a/test/base/driver_util.py +++ b/test/base/driver_util.py @@ -1,10 +1,12 @@ """Scripts for drivers of Galaxy functional tests.""" +import httplib import logging import os import shutil import sys import tempfile +import time from six.moves.urllib.request import urlretrieve @@ -117,10 +119,27 @@ def get_webapp_global_conf(): return global_conf +def wait_for_http_server(host, port): + """Wait for an HTTP server to boot up.""" + # Test if the server is up + for i in range( 10 ): + # directly test the app, not the proxy + conn = httplib.HTTPConnection(host, port) + conn.request( "GET", "/" ) + if conn.getresponse().status == 200: + break + time.sleep( 0.1 ) + else: + template = "Test HTTP server on host %s and port %s did not return '200 OK' after 10 tries" + message = template % (host, port) + raise Exception(message) + + __all__ = [ "configure_environment", "copy_database_template", "build_logger", "get_webapp_global_conf", "nose_config_and_run", + "wait_for_http_server", ] diff --git a/test/tool_shed/functional_tests.py b/test/tool_shed/functional_tests.py index 01b7a9caa18..b1d24fbb26c 100644 --- a/test/tool_shed/functional_tests.py +++ b/test/tool_shed/functional_tests.py @@ -1,7 +1,6 @@ #!/usr/bin/env python from __future__ import absolute_import -import httplib import os import random import shutil @@ -10,7 +9,6 @@ import string import sys import tempfile import threading -import time galaxy_root = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir, os.path.pardir)) # Need to remove this directory from sys.path @@ -243,16 +241,7 @@ def main(): os.environ[ 'TOOL_SHED_TEST_PORT' ] = tool_shed_test_port t = threading.Thread( target=tool_shed_server.serve_forever ) t.start() - # Test if the server is up - for i in range( 10 ): - # Directly test the app, not the proxy. - conn = httplib.HTTPConnection( tool_shed_test_host, tool_shed_test_port ) - conn.request( "GET", "/" ) - if conn.getresponse().status == 200: - break - time.sleep( 0.1 ) - else: - raise Exception( "Test HTTP server did not return '200 OK' after 10 tries" ) + driver_util.wait_for_http_server(tool_shed_test_host, tool_shed_test_port) log.info( "Embedded web server started" ) # ---- Optionally start up a Galaxy instance ------------------------------------------------------ @@ -350,16 +339,7 @@ def main(): os.environ[ 'GALAXY_TEST_PORT' ] = galaxy_test_port t = threading.Thread( target=galaxy_server.serve_forever ) t.start() - # Test if the server is up - for i in range( 10 ): - # Directly test the app, not the proxy. - conn = httplib.HTTPConnection( galaxy_test_host, galaxy_test_port ) - conn.request( "GET", "/" ) - if conn.getresponse().status == 200: - break - time.sleep( 0.1 ) - else: - raise Exception( "Test HTTP server did not return '200 OK' after 10 tries" ) + driver_util.wait_for_http_server(galaxy_test_host, galaxy_test_port) log.info( "Embedded galaxy web server started" ) # ---- Find tests --------------------------------------------------------- if tool_shed_test_proxy_port: