sort imports and add some commentary to cancellederror test

This commit is contained in:
Patrick Gingras 2020-11-02 22:34:09 -05:00
parent 49c00da715
commit af16649725
No known key found for this signature in database
GPG Key ID: F56B4E7C84CA0B49

View File

@ -6,9 +6,10 @@ from urllib import parse
import http_strategies import http_strategies
from http_base import DaphneTestCase, DaphneTestingInstance from http_base import DaphneTestCase, DaphneTestingInstance
from daphne.testing import BaseDaphneTestingInstance
from hypothesis import given, settings from hypothesis import given, settings
from daphne.testing import BaseDaphneTestingInstance
class TestWebsocket(DaphneTestCase): class TestWebsocket(DaphneTestCase):
""" """
@ -285,8 +286,10 @@ class TestWebsocket(DaphneTestCase):
async def cancelling_application(scope, receive, send): async def cancelling_application(scope, receive, send):
import asyncio import asyncio
from twisted.internet import reactor from twisted.internet import reactor
# Stop the server after a short delay so that the teardown is run.
reactor.callLater(2, lambda: reactor.stop()) reactor.callLater(2, lambda: reactor.stop())
await send({"type": "websocket.accept"}) await send({"type": "websocket.accept"})
raise asyncio.CancelledError() raise asyncio.CancelledError()
@ -303,6 +306,11 @@ class CancellingTestingInstance(BaseDaphneTestingInstance):
def process_teardown(self): def process_teardown(self):
import multiprocessing import multiprocessing
# Get a hold of the enclosing DaphneProcess (we're currently running in
# the same process as the application).
proc = multiprocessing.current_process() 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: if proc.server.connections:
raise ConnectionsNotEmpty() raise ConnectionsNotEmpty()