Permalink
Browse files

Merge remote-tracking branch 'upstream/master'

Conflicts:
	tornado/simple_httpclient.py
  • Loading branch information...
2 parents 162cb8f + 52c83a4 commit 56d1a87100b36e04835e9f457c2ad43295e26ce3 @ovidiucp committed Dec 9, 2011
View
@@ -6,4 +6,5 @@ dist/
MANIFEST
tornado.egg-info
_auto2to3*
-.tox
+.tox
+.vagrant
View
@@ -0,0 +1,3 @@
+This directory contains tools and scripts that are used in the development
+and maintainance of Tornado itself, but are probably not of interest to
+Tornado users.
View
@@ -0,0 +1,11 @@
+Unit test support for app engine. Currently very limited as most of
+our tests depend on direct network access, but these tests ensure that the
+modules that are supposed to work on app engine don't depend on any
+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.
@@ -0,0 +1,72 @@
+#!/usr/bin/env python
+import logging
+import unittest
+
+# Most of our tests depend on IOLoop, which is not importable on app engine.
+# Run the tests that work, and check that forbidden imports don't sneak
+# in to modules that are supposed to work on app engine.
+TEST_MODULES = [
+ 'tornado.httputil.doctests',
+ #'tornado.iostream.doctests',
+ 'tornado.util.doctests',
+ #'tornado.test.auth_test',
+ #'tornado.test.curl_httpclient_test',
+ 'tornado.test.escape_test',
+ #'tornado.test.gen_test',
+ #'tornado.test.httpclient_test',
+ #'tornado.test.httpserver_test',
+ 'tornado.test.httputil_test',
+ #'tornado.test.import_test',
+ #'tornado.test.ioloop_test',
+ #'tornado.test.iostream_test',
+ #'tornado.test.process_test',
+ #'tornado.test.simple_httpclient_test',
+ #'tornado.test.stack_context_test',
+ 'tornado.test.template_test',
+ #'tornado.test.testing_test',
+ #'tornado.test.twisted_test',
+ #'tornado.test.web_test',
+ #'tornado.test.wsgi_test',
+]
+
+def import_everything():
+ # import tornado.auth
+ # import tornado.autoreload
+ # import tornado.curl_httpclient # depends on pycurl
+ # import tornado.database # depends on MySQLdb
+ import tornado.escape
+ # import tornado.httpclient
+ # import tornado.httpserver
+ import tornado.httputil
+ # import tornado.ioloop
+ # import tornado.iostream
+ import tornado.locale
+ import tornado.options
+ # import tornado.netutil
+ # import tornado.platform.twisted # depends on twisted
+ # import tornado.process
+ # import tornado.simple_httpclient
+ import tornado.stack_context
+ import tornado.template
+ import tornado.testing
+ import tornado.util
+ import tornado.web
+ # import tornado.websocket
+ import tornado.wsgi
+
+def all():
+ return unittest.defaultTestLoader.loadTestsFromNames(TEST_MODULES)
+
+if __name__ == '__main__':
+ print "Content-Type: text/plain\r\n\r\n",
+
+ import_everything()
+
+ import tornado.testing
+ try:
+ tornado.testing.main()
+ except SystemExit, e:
+ if e.code == 0:
+ print "PASS"
+ else:
+ raise
@@ -0,0 +1,29 @@
+#!/usr/bin/env python
+
+import os
+import random
+import signal
+import subprocess
+import sys
+import time
+import urllib2
+
+if __name__ == "__main__":
+ tornado_root = os.path.abspath(os.path.join(os.path.dirname(__file__),
+ '../../..'))
+ # dev_appserver doesn't seem to set SO_REUSEADDR
+ port = random.randrange(10000, 11000)
+ # 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
+ ],
+ cwd=tornado_root)
+ time.sleep(3)
+ try:
+ resp = urllib2.urlopen("http://localhost:%d/" % port)
+ print resp.read()
+ finally:
+ os.kill(proc.pid, signal.SIGTERM)
+ proc.wait()
@@ -0,0 +1,8 @@
+application: tornado-tests-appengine25
+version: 1
+runtime: python
+api_version: 1
+
+handlers:
+- url: /
+ script: cgi_runtests.py
@@ -0,0 +1,9 @@
+application: tornado-tests-appengine27
+version: 1
+runtime: python27
+threadsafe: false
+api_version: 1
+
+handlers:
+- url: /
+ script: cgi_runtests.py
View
@@ -0,0 +1,23 @@
+This directory contains virtual machine setup scripts for testing Tornado.
+
+Requirements:
+
+Vagrant (http://vagrantup.com) and VirtualBox (http://virtualbox.org).
+Vagrant provides an easy download for Ubuntu 10.04 (aka lucid64); base
+images for other platforms are harder to find and can be built with
+VeeWee (https://github.com/jedi4ever/veewee).
+
+Usage:
+
+cd to the appropriate directory and run `vagrant up`, then `vagrant ssh`.
+From there, simply run `tox` to run the full test suite, or cd to /tornado
+and test manually. Afterwards, use `vagrant suspend` or `vagrant destroy`
+to clean up.
+
+Notes:
+
+Python distutils (and therefore tox) assume that if the platform
+supports hard links, they can be used in the Tornado source directory.
+VirtualBox's shared folder filesystem does not support hard links (or
+symlinks), so we have to use NFS shared folders instead. (which has
+the unfortunate side effect of requiring sudo on the host machine)
@@ -0,0 +1,27 @@
+require 'vagrant/systems/freebsd'
+
+Vagrant::Config.run do |config|
+ # A freebsd image can be created with veewee
+ # https://github.com/jedi4ever/veewee
+ #
+ # vagrant basebox define freebsd freebsd-8.2-pcbsd-i386-netboot
+ # vagrant basebox build freebsd
+ # vagrant basebox export freebsd
+ # vagrant box add freebsd freebsd.box
+ config.vm.box = "freebsd"
+
+ config.vm.system = :freebsd
+
+ # Note that virtualbox shared folders don't work with freebsd, so
+ # we'd need nfs shared folders here even if virtualbox gains
+ # support for symlinks.
+ config.vm.network "172.19.1.3"
+ config.vm.share_folder("tornado", "/tornado", "../../..", :nfs => true)
+
+ # This doesn't seem to get mounted by default for freebsd,
+ # but that's actually a good thing since there are apparently issues
+ # when one nfs export is a subfolder of another.
+ #config.vm.share_folder("v-root", "/vagrant", ".", :nfs => true)
+
+ config.vm.provision :shell, :path => "setup.sh"
+end
View
@@ -0,0 +1,30 @@
+#!/bin/sh
+
+chsh -s bash vagrant
+
+# This doesn't get created automatically for freebsd since virtualbox
+# shared folders don't work.
+ln -snf /tornado/maint/vm/freebsd /vagrant
+
+PORTS="
+lang/python27
+devel/py-pip
+devel/py-virtualenv
+ftp/curl
+"
+
+PIP_PACKAGES="
+tox
+pycurl
+"
+
+cd /usr/ports
+
+for port in $PORTS; do
+ make -C $port -DBATCH install
+done
+
+pip install $PIP_PACKAGES
+
+/tornado/maint/vm/shared-setup.sh
+
View
@@ -0,0 +1,13 @@
+[tox]
+envlist=py27-full, py27
+setupdir=/tornado
+# /home is a symlink to /usr/home, but tox doesn't like symlinks here
+toxworkdir=/usr/home/vagrant/tox-tornado
+
+[testenv]
+commands = python -m tornado.test.runtests {posargs:}
+
+[testenv:py27-full]
+# other dependencies aren't really worth the install time
+deps =
+ pycurl
View
@@ -0,0 +1,7 @@
+#!/bin/sh
+# Run at the end of each vm's provisioning script
+
+# Link tox.ini into the home directory so you can run tox immediately
+# after ssh'ing in without cd'ing to /vagrant (since cd'ing to /tornado
+# gets the wrong config)
+ln -sf /vagrant/tox.ini ~vagrant/tox.ini
@@ -0,0 +1,9 @@
+Vagrant::Config.run do |config|
+ config.vm.box = "lucid64"
+ config.vm.box_url = "http://files.vagrantup.com/lucid64.box"
+
+ config.vm.network "172.19.1.2"
+ config.vm.share_folder("tornado", "/tornado", "../../..", :nfs=> true)
+
+ config.vm.provision :shell, :path => "setup.sh"
+end
@@ -0,0 +1,25 @@
+#!/bin/sh
+
+# libcurl4-gnutls-dev is the default if you ask for libcurl4-dev, but it
+# has bugs that make our tests deadlock (the relevant tests detect this and
+# disable themselves, but it means that to get full coverage we have to use
+# the openssl version)
+APT_PACKAGES="
+python-pip
+python-virtualenv
+python-dev
+libmysqlclient-dev
+libcurl4-openssl-dev
+"
+
+PIP_PACKAGES="
+tox
+MySQL-python
+pycurl
+twisted
+"
+
+apt-get -y install $APT_PACKAGES
+pip install $PIP_PACKAGES
+
+/tornado/maint/vm/shared-setup.sh
@@ -0,0 +1,13 @@
+[tox]
+envlist=py26-full, py26
+setupdir=/tornado
+toxworkdir=/home/vagrant/tox-tornado
+
+[testenv]
+commands = python -m tornado.test.runtests {posargs:}
+
+[testenv:py26-full]
+deps =
+ MySQL-python
+ pycurl
+ twisted
View
@@ -33,7 +33,7 @@
extensions.append(distutils.core.Extension(
"tornado.epoll", ["tornado/epoll.c"]))
-version = "2.1.1"
+version = "2.1.1git"
if major >= 3:
import setuptools # setuptools is required for use_2to3
View
@@ -16,5 +16,5 @@
"""The Tornado web server and tools."""
-version = "2.1.1"
+version = "2.1.1git"
version_info = (2, 1, 1)
View
@@ -172,7 +172,7 @@ def close(self, all_fds=False):
try:
os.close(fd)
except Exception:
- logging.debug("error closing fd %d", fd, exc_info=True)
+ logging.debug("error closing fd %s", fd, exc_info=True)
self._waker.close()
self._impl.close()
@@ -262,8 +262,8 @@ def start(self):
timeout = heapq.heappop(self._timeouts)
self._run_callback(timeout.callback)
else:
- milliseconds = self._timeouts[0].deadline - now
- poll_timeout = min(milliseconds, poll_timeout)
+ seconds = self._timeouts[0].deadline - now
+ poll_timeout = min(seconds, poll_timeout)
break
if self._callbacks:
@@ -312,10 +312,10 @@ def start(self):
# Happens when the client closes the connection
pass
else:
- logging.error("Exception in I/O handler for fd %d",
+ logging.error("Exception in I/O handler for fd %s",
fd, exc_info=True)
except Exception:
- logging.error("Exception in I/O handler for fd %d",
+ logging.error("Exception in I/O handler for fd %s",
fd, exc_info=True)
# reset the stopped flag so another start/stop pair can be issued
self._stopped = False
@@ -455,6 +455,7 @@ def __init__(self, callback, callback_time, io_loop=None):
self.callback_time = callback_time
self.io_loop = io_loop or IOLoop.instance()
self._running = False
+ self._timeout = None
def start(self):
"""Starts the timer."""
@@ -465,6 +466,9 @@ def start(self):
def stop(self):
"""Stops the timer."""
self._running = False
+ if self._timeout is not None:
+ self.io_loop.remove_timeout(self._timeout)
+ self._timeout = None
def _run(self):
if not self._running: return
@@ -479,7 +483,7 @@ def _schedule_next(self):
current_time = time.time()
while self._next_timeout <= current_time:
self._next_timeout += self.callback_time / 1000.0
- self.io_loop.add_timeout(self._next_timeout, self._run)
+ self._timeout = self.io_loop.add_timeout(self._next_timeout, self._run)
class _EPoll(object):
Oops, something went wrong.

0 comments on commit 56d1a87

Please sign in to comment.