diff --git a/cheroot/test/test_wsgi.py b/cheroot/test/test_wsgi.py index e546213dee..ca9f2b9b48 100644 --- a/cheroot/test/test_wsgi.py +++ b/cheroot/test/test_wsgi.py @@ -1,9 +1,13 @@ """Test wsgi.""" import threading +from concurrent.futures.thread import ThreadPoolExecutor import pytest import portend +import requests +from requests_toolbelt.sessions import BaseUrlSession as Session +from jaraco.context import ExceptionTrap from cheroot import wsgi @@ -25,6 +29,7 @@ def app(environ, start_response): thread = threading.Thread(target=server.start) thread.setDaemon(True) thread.start() + url = 'http://localhost:{port}/'.format(**locals()) yield locals() # would prefer to stop server, but has errors # server.stop() @@ -32,4 +37,23 @@ def app(environ, start_response): def test_connection_keepalive(simple_wsgi_server): """Test the connection keepalive works (duh).""" - pass + session = Session(base_url=simple_wsgi_server['url']) + pooled = requests.adapters.HTTPAdapter( + pool_connections=1, pool_maxsize=1000, + ) + session.mount('http://', pooled) + + def do_request(): + with ExceptionTrap(requests.exceptions.ConnectionError) as trap: + resp = session.get('info') + resp.raise_for_status() + return bool(trap) + + with ThreadPoolExecutor(max_workers=50) as pool: + tasks = [ + pool.submit(do_request) + for n in range(1000) + ] + failures = sum(task.result() for task in tasks) + + assert not failures diff --git a/setup.cfg b/setup.cfg index 99adb7d478..6b066d796f 100644 --- a/setup.cfg +++ b/setup.cfg @@ -124,6 +124,8 @@ testing = colorama!=0.4.2; python_version == "3.4" portend + requests_toolbelt + jaraco.context [options.entry_points] console_scripts =