Skip to content

Commit

Permalink
Add test capturing failure. Ref #263.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Apr 4, 2020
1 parent 5d4f1ca commit ec07ec4
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
26 changes: 25 additions & 1 deletion cheroot/test/test_wsgi.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -25,11 +29,31 @@ 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()


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
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ testing =
colorama!=0.4.2; python_version == "3.4"

portend
requests_toolbelt
jaraco.context

[options.entry_points]
console_scripts =
Expand Down

0 comments on commit ec07ec4

Please sign in to comment.