mirror of
https://github.com/django/django.git
synced 2025-08-03 10:34:04 +00:00
Fixed #32240 -- Made runserver suppress ConnectionAbortedError/ConnectionResetError errors.
See https://bugs.python.org/issue27682 and https://github.com/python/cpython/pull/9713
This commit is contained in:
parent
28124e7bdf
commit
772eca0b02
3 changed files with 25 additions and 13 deletions
|
@ -113,15 +113,22 @@ class WSGIServerTestCase(SimpleTestCase):
|
|||
request = WSGIRequest(self.request_factory.get('/').environ)
|
||||
client_address = ('192.168.2.0', 8080)
|
||||
msg = f'- Broken pipe from {client_address}\n'
|
||||
try:
|
||||
server = WSGIServer(('localhost', 0), WSGIRequestHandler)
|
||||
try:
|
||||
raise BrokenPipeError()
|
||||
except Exception:
|
||||
with captured_stderr() as err:
|
||||
with self.assertLogs('django.server', 'INFO') as cm:
|
||||
server.handle_error(request, client_address)
|
||||
self.assertEqual(err.getvalue(), '')
|
||||
self.assertEqual(cm.records[0].getMessage(), msg)
|
||||
finally:
|
||||
server.server_close()
|
||||
tests = [
|
||||
BrokenPipeError,
|
||||
ConnectionAbortedError,
|
||||
ConnectionResetError,
|
||||
]
|
||||
for exception in tests:
|
||||
with self.subTest(exception=exception):
|
||||
try:
|
||||
server = WSGIServer(('localhost', 0), WSGIRequestHandler)
|
||||
try:
|
||||
raise exception()
|
||||
except Exception:
|
||||
with captured_stderr() as err:
|
||||
with self.assertLogs('django.server', 'INFO') as cm:
|
||||
server.handle_error(request, client_address)
|
||||
self.assertEqual(err.getvalue(), '')
|
||||
self.assertEqual(cm.records[0].getMessage(), msg)
|
||||
finally:
|
||||
server.server_close()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue