From af16649725c2097df8e69e9538d3fe1fca410d6d Mon Sep 17 00:00:00 2001 From: Patrick Gingras <775.pg.12@gmail.com> Date: Mon, 2 Nov 2020 22:34:09 -0500 Subject: [PATCH] sort imports and add some commentary to cancellederror test --- tests/test_websocket.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/tests/test_websocket.py b/tests/test_websocket.py index 3230832..26572e7 100644 --- a/tests/test_websocket.py +++ b/tests/test_websocket.py @@ -6,9 +6,10 @@ from urllib import parse import http_strategies from http_base import DaphneTestCase, DaphneTestingInstance -from daphne.testing import BaseDaphneTestingInstance from hypothesis import given, settings +from daphne.testing import BaseDaphneTestingInstance + class TestWebsocket(DaphneTestCase): """ @@ -285,8 +286,10 @@ class TestWebsocket(DaphneTestCase): async def cancelling_application(scope, receive, send): import asyncio + from twisted.internet import reactor + # Stop the server after a short delay so that the teardown is run. reactor.callLater(2, lambda: reactor.stop()) await send({"type": "websocket.accept"}) raise asyncio.CancelledError() @@ -303,6 +306,11 @@ class CancellingTestingInstance(BaseDaphneTestingInstance): def process_teardown(self): import multiprocessing + # Get a hold of the enclosing DaphneProcess (we're currently running in + # the same process as the application). proc = multiprocessing.current_process() + # By now the (only) socket should have disconnected, and the + # application_checker should have run. If there are any connections + # still, it means that the application_checker did not clean them up. if proc.server.connections: raise ConnectionsNotEmpty()