Skip to content

Commit 985f176

Browse files
adamchainzcarltongibson
authored andcommitted
Make live test case use pickleable DaphneProcess
1 parent f162a4b commit 985f176

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

channels/testing/live.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import multiprocessing
1+
from functools import partial
22

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

1010
from channels.routing import get_default_application
1111

12-
# Enforce multiprocessing start method for macOS.
13-
multiprocessing.set_start_method("fork")
12+
13+
def make_application(*, static_wrapper):
14+
# Module-level function for pickle-ability
15+
application = get_default_application()
16+
if static_wrapper is not None:
17+
application = static_wrapper(application)
18+
return application
1419

1520

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

51-
if self.serve_static:
52-
application = self.static_wrapper(get_default_application())
53-
else:
54-
application = get_default_application()
55-
56-
self._server_process = self.ProtocolServerProcess(self.host, application)
56+
get_application = partial(
57+
make_application,
58+
static_wrapper=self.static_wrapper if self.serve_static else None,
59+
)
60+
self._server_process = self.ProtocolServerProcess(self.host, get_application)
5761
self._server_process.start()
5862
self._server_process.ready.wait()
5963
self._port = self._server_process.port.value

0 commit comments

Comments
 (0)