Skip to content

Commit

Permalink
Make live test case use pickleable DaphneProcess
Browse files Browse the repository at this point in the history
adamchainz authored and carltongibson committed Oct 7, 2022
1 parent f162a4b commit 985f176
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions channels/testing/live.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import multiprocessing
from functools import partial

from daphne.testing import DaphneProcess
from django.contrib.staticfiles.handlers import ASGIStaticFilesHandler
@@ -9,8 +9,13 @@

from channels.routing import get_default_application

# Enforce multiprocessing start method for macOS.
multiprocessing.set_start_method("fork")

def make_application(*, static_wrapper):
# Module-level function for pickle-ability
application = get_default_application()
if static_wrapper is not None:
application = static_wrapper(application)
return application


class ChannelsLiveServerTestCase(TransactionTestCase):
@@ -48,12 +53,11 @@ def _pre_setup(self):
)
self._live_server_modified_settings.enable()

if self.serve_static:
application = self.static_wrapper(get_default_application())
else:
application = get_default_application()

self._server_process = self.ProtocolServerProcess(self.host, application)
get_application = partial(
make_application,
static_wrapper=self.static_wrapper if self.serve_static else None,
)
self._server_process = self.ProtocolServerProcess(self.host, get_application)
self._server_process.start()
self._server_process.ready.wait()
self._port = self._server_process.port.value

0 comments on commit 985f176

Please sign in to comment.