Added tests for multi-worker functionality on the server and correct interpretation of the --workers argument in the CLI.

This commit is contained in:
Ricardo Robles 2025-05-10 15:33:43 +02:00
parent 663cf4a23d
commit 0a56c37834
2 changed files with 23 additions and 0 deletions

View File

@ -282,3 +282,14 @@ class DaphneTestCase(unittest.TestCase):
self.assertIsInstance(address, str)
self.assert_is_ip_address(address)
self.assertIsInstance(port, int)
def test_multiple_workers(self):
"""
Tests that the server can start with multiple workers.
"""
with DaphneTestingInstance() as test_app:
# Configure the server with 3 workers
test_app.process.kwargs["workers"] = 3
test_app.process.start()
# Verify that the server is running
self.assertTrue(test_app.process.ready.wait(test_app.startup_timeout))

View File

@ -257,6 +257,18 @@ class TestCLIInterface(TestCase):
"""
self.assertCLI(["--no-server-name"], {"server_name": ""})
def test_workers_default(self):
"""
Tests that the default number of workers is 1.
"""
self.assertCLI([], {"workers": 1})
def test_workers_custom(self):
"""
Tests that the CLI correctly parses the --workers argument.
"""
self.assertCLI(["--workers", "4"], {"workers": 4})
@skipUnless(os.getenv("ASGI_THREADS"), "ASGI_THREADS environment variable not set.")
class TestASGIThreads(TestCase):