Make it possible to run the test suite with --httpclient=CurlAsyncHTTPClient

This commit is contained in:
Ben Darnell 2012-01-08 13:49:30 -08:00
parent 0a949c07be
commit 98f77972ae
6 changed files with 30 additions and 6 deletions

View File

@ -271,7 +271,7 @@ def _curl_create(max_simultaneous_connections=None):
def _curl_setup_request(curl, request, buffer, headers):
curl.setopt(pycurl.URL, request.url)
curl.setopt(pycurl.URL, utf8(request.url))
# libcurl's magic "Expect: 100-continue" behavior causes delays
# with servers that don't support it (which include, among others,

View File

@ -54,9 +54,11 @@ class HTTPClient(object):
except httpclient.HTTPError, e:
print "Error:", e
"""
def __init__(self):
def __init__(self, async_client_class=None):
self._io_loop = IOLoop()
self._async_client = AsyncHTTPClient(self._io_loop)
if async_client_class is None:
async_client_class = AsyncHTTPClient
self._async_client = async_client_class(self._io_loop)
self._response = None
self._closed = False

View File

@ -118,7 +118,8 @@ class HTTPConnectionTest(AsyncHTTPTestCase, LogTrapTestCase):
return Application(self.get_handlers())
def raw_fetch(self, headers, body):
conn = RawRequestHTTPConnection(self.io_loop, self.http_client,
client = SimpleAsyncHTTPClient(self.io_loop)
conn = RawRequestHTTPConnection(self.io_loop, client,
httpclient.HTTPRequest(self.get_url("/")),
None, self.stop,
1024*1024)
@ -127,6 +128,7 @@ class HTTPConnectionTest(AsyncHTTPTestCase, LogTrapTestCase):
[utf8("Content-Length: %d\r\n" % len(body))]) +
b("\r\n") + body)
response = self.wait()
client.close()
response.rethrow()
return response

View File

@ -9,6 +9,7 @@ from tornado.httpserver import HTTPServer
from tornado.ioloop import IOLoop
from tornado.netutil import bind_sockets
from tornado.process import fork_processes, task_id
from tornado.simple_httpclient import SimpleAsyncHTTPClient
from tornado.testing import LogTrapTestCase, get_unused_port
from tornado.web import RequestHandler, Application
@ -72,7 +73,11 @@ class ProcessTest(LogTrapTestCase):
signal.alarm(5)
self.assertEqual(id, task_id())
for sock in sockets: sock.close()
client = HTTPClient()
# Always use SimpleAsyncHTTPClient here; the curl
# version appears to get confused sometimes if the
# connection gets closed before it's had a chance to
# switch from writing mode to reading mode.
client = HTTPClient(SimpleAsyncHTTPClient)
def fetch(url, fail_ok=False):
try:

View File

@ -55,6 +55,10 @@ class NoContentHandler(RequestHandler):
self.set_status(204)
class SimpleHTTPClientTestCase(AsyncHTTPTestCase, LogTrapTestCase):
def setUp(self):
super(SimpleHTTPClientTestCase, self).setUp()
self.http_client = SimpleAsyncHTTPClient(self.io_loop)
def get_app(self):
# callable objects to finish pending /trigger requests
self.triggers = collections.deque()

13
tox.ini
View File

@ -13,7 +13,7 @@
[tox]
# "-full" variants include optional dependencies, to ensure
# that things work both in a bare install and with all the extras.
envlist = py27-full, py25-full, py32, pypy, py25, py26, py26-full, py27
envlist = py27-full, py27-curl, py25-full, py32, pypy, py25, py26, py26-full, py27
[testenv]
commands = python -m tornado.test.runtests {posargs:}
@ -52,6 +52,17 @@ deps =
pycurl
twisted==11.0.0
[testenv:py27-curl]
# Same as py27-full, but runs the tests with curl_httpclient by default.
# Note that httpclient_test is always run with both client implementations;
# this flag controls which client all the other tests use.
basepython = python2.7
deps =
MySQL-python
pycurl
twisted==11.0.0
commands = python -m tornado.test.runtests --httpclient=tornado.curl_httpclient.CurlAsyncHTTPClient {posargs:}
# No pypy-full yet: pycurl doesn't build with pypy, and installing
# twisted under pypy takes a *very* long time. MySQL-python builds with
# pypy, but doesn't work.