From: Ben Darnell Date: Fri, 16 Dec 2011 06:54:51 +0000 (-0800) Subject: Improve app engine tests now that SDK 1.6.1 is compatible with virtualenv X-Git-Tag: v2.2.0~69 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e7a47e7b6f7997ce10835d2716be68d5f0bcbe8e;p=thirdparty%2Ftornado.git Improve app engine tests now that SDK 1.6.1 is compatible with virtualenv --- diff --git a/maint/appengine/README b/maint/appengine/README index 6a77f3d22..8d534f28d 100644 --- a/maint/appengine/README +++ b/maint/appengine/README @@ -6,6 +6,3 @@ forbidden modules. The code lives in maint/appengine/common, but should be run from the py25 or py27 subdirectories (which contain an app.yaml and a bunch of symlinks). runtests.py is the entry point; cgi_runtests.py is used internally. -dev_appserver.py doesn't work with virtualenv -(http://code.google.com/p/googleappengine/issues/detail?id=4339) so these -tests are not hooked into tox yet. diff --git a/maint/appengine/common/cgi_runtests.py b/maint/appengine/common/cgi_runtests.py index 13f0d91dc..a3f1596bf 100644 --- a/maint/appengine/common/cgi_runtests.py +++ b/maint/appengine/common/cgi_runtests.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -import logging +import sys import unittest # Most of our tests depend on IOLoop, which is not importable on app engine. @@ -57,16 +57,19 @@ def import_everything(): def all(): return unittest.defaultTestLoader.loadTestsFromNames(TEST_MODULES) -if __name__ == '__main__': +def main(): print "Content-Type: text/plain\r\n\r\n", import_everything() - import tornado.testing try: - tornado.testing.main() + unittest.main(defaultTest="all", argv=sys.argv) except SystemExit, e: if e.code == 0: print "PASS" else: raise + +if __name__ == '__main__': + main() + diff --git a/maint/appengine/common/runtests.py b/maint/appengine/common/runtests.py index c648285f1..2db8d1aba 100644 --- a/maint/appengine/common/runtests.py +++ b/maint/appengine/common/runtests.py @@ -1,8 +1,12 @@ #!/usr/bin/env python +from __future__ import with_statement +import contextlib +import errno import os import random import signal +import socket import subprocess import sys import time @@ -16,14 +20,34 @@ if __name__ == "__main__": # does dev_appserver.py ever live anywhere but /usr/local/bin? proc = subprocess.Popen([sys.executable, "/usr/local/bin/dev_appserver.py", - os.path.dirname(__file__), - "--port=%d" % port + os.path.dirname(os.path.abspath(__file__)), + "--port=%d" % port, + "--skip_sdk_update_check", ], cwd=tornado_root) - time.sleep(3) + try: + for i in xrange(50): + with contextlib.closing(socket.socket()) as sock: + err = sock.connect_ex(('localhost', port)) + if err == 0: + break + elif err != errno.ECONNREFUSED: + raise Exception("Got unexpected socket error %d" % err) + time.sleep(0.1) + else: + raise Exception("Server didn't start listening") + resp = urllib2.urlopen("http://localhost:%d/" % port) print resp.read() finally: - os.kill(proc.pid, signal.SIGTERM) - proc.wait() + # dev_appserver sometimes ignores SIGTERM (especially on 2.5), + # so try a few times to kill it. + for sig in [signal.SIGTERM, signal.SIGTERM, signal.SIGKILL]: + os.kill(proc.pid, sig) + res = os.waitpid(proc.pid, os.WNOHANG) + if res != (0,0): + break + time.sleep(0.1) + else: + os.waitpid(proc.pid, 0) diff --git a/maint/appengine/setup.py b/maint/appengine/setup.py new file mode 100644 index 000000000..5d2d3141d --- /dev/null +++ b/maint/appengine/setup.py @@ -0,0 +1,4 @@ +# Dummy setup file to make tox happy. In the appengine world things aren't +# installed through setup.py +import distutils.core +distutils.core.setup() diff --git a/maint/appengine/tox.ini b/maint/appengine/tox.ini new file mode 100644 index 000000000..0970bf884 --- /dev/null +++ b/maint/appengine/tox.ini @@ -0,0 +1,19 @@ +# App Engine tests require the SDK to be installed separately. +# Version 1.6.1 or newer is required (older versions don't work when +# python is run from a virtualenv) +# +# These are currently excluded from the main tox.ini because their +# logs are spammy and they're a little flaky. +[tox] +envlist = py25-appengine, py27-appengine + +[testenv] +changedir = {toxworkdir} + +[testenv:py25-appengine] +basepython = python2.5 +commands = python {toxinidir}/py25/runtests.py {posargs:} + +[testenv:py27-appengine] +basepython = python2.7 +commands = python {toxinidir}/py27/runtests.py {posargs:}