Eliminate duplication in waiting for HTTP servers in test drivers.

This commit is contained in:
John Chilton
2016-03-29 08:04:20 -04:00
parent d60fe9f5aa
commit b7c75f20a5
3 changed files with 22 additions and 33 deletions
+1 -11
View File
@@ -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 ---------------------------------------------------------
+19
View File
@@ -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",
]
+2 -22
View File
@@ -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: