Allowed assigning a port in DaphneProcess test helper. (#550)

This commit is contained in:
Mohammed 2025-05-07 08:33:22 -06:00 committed by GitHub
parent 7c9334952d
commit beef1c1514
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -126,14 +126,16 @@ class DaphneProcess(multiprocessing.Process):
port it ends up listening on back to the parent process.
"""
def __init__(self, host, get_application, kwargs=None, setup=None, teardown=None):
def __init__(
self, host, get_application, kwargs=None, setup=None, teardown=None, port=None
):
super().__init__()
self.host = host
self.get_application = get_application
self.kwargs = kwargs or {}
self.setup = setup
self.teardown = teardown
self.port = multiprocessing.Value("i")
self.port = multiprocessing.Value("i", port if port is not None else 0)
self.ready = multiprocessing.Event()
self.errors = multiprocessing.Queue()
@ -153,7 +155,9 @@ class DaphneProcess(multiprocessing.Process):
try:
# Create the server class
endpoints = build_endpoint_description_strings(host=self.host, port=0)
endpoints = build_endpoint_description_strings(
host=self.host, port=self.port.value
)
self.server = Server(
application=application,
endpoints=endpoints,