Skip to content

Commit beef1c1

Browse files
Allowed assigning a port in DaphneProcess test helper. (#550)
1 parent 7c93349 commit beef1c1

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

daphne/testing.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,16 @@ class DaphneProcess(multiprocessing.Process):
126126
port it ends up listening on back to the parent process.
127127
"""
128128

129-
def __init__(self, host, get_application, kwargs=None, setup=None, teardown=None):
129+
def __init__(
130+
self, host, get_application, kwargs=None, setup=None, teardown=None, port=None
131+
):
130132
super().__init__()
131133
self.host = host
132134
self.get_application = get_application
133135
self.kwargs = kwargs or {}
134136
self.setup = setup
135137
self.teardown = teardown
136-
self.port = multiprocessing.Value("i")
138+
self.port = multiprocessing.Value("i", port if port is not None else 0)
137139
self.ready = multiprocessing.Event()
138140
self.errors = multiprocessing.Queue()
139141

@@ -153,7 +155,9 @@ def run(self):
153155

154156
try:
155157
# Create the server class
156-
endpoints = build_endpoint_description_strings(host=self.host, port=0)
158+
endpoints = build_endpoint_description_strings(
159+
host=self.host, port=self.port.value
160+
)
157161
self.server = Server(
158162
application=application,
159163
endpoints=endpoints,

0 commit comments

Comments
 (0)