[router] Allow empty worker list for sglang.launch_router (#2979)

This commit is contained in:
Byron Hsu
2025-01-19 17:05:23 +08:00
committed by GitHub
parent 53cc91e504
commit ef18b0eda2
8 changed files with 46 additions and 17 deletions

View File

@@ -22,11 +22,9 @@ def terminate_process(process: multiprocessing.Process, timeout: float = 1.0) ->
class TestLaunchRouter(unittest.TestCase):
def test_launch_router_no_exception(self):
# Create SimpleNamespace with default arguments
args = SimpleNamespace(
worker_urls=["http://localhost:8000"],
def setUp(self):
"""Set up default arguments for router tests."""
self.default_args = SimpleNamespace(
host="127.0.0.1",
port=30000,
policy="cache_aware",
@@ -39,6 +37,15 @@ class TestLaunchRouter(unittest.TestCase):
verbose=False,
)
def create_router_args(self, **kwargs):
"""Create router arguments by updating default args with provided kwargs."""
args_dict = vars(self.default_args).copy()
args_dict.update(kwargs)
return SimpleNamespace(**args_dict)
def run_router_process(self, args):
"""Run router in a separate process and verify it starts successfully."""
def run_router():
try:
from sglang_router.launch_router import launch_router
@@ -51,7 +58,6 @@ class TestLaunchRouter(unittest.TestCase):
print(e)
return 1
# Start router in separate process
process = multiprocessing.Process(target=run_router)
try:
process.start()
@@ -62,6 +68,14 @@ class TestLaunchRouter(unittest.TestCase):
finally:
terminate_process(process)
def test_launch_router_common(self):
args = self.create_router_args(worker_urls=["http://localhost:8000"])
self.run_router_process(args)
def test_launch_router_with_empty_worker_urls(self):
args = self.create_router_args(worker_urls=[])
self.run_router_process(args)
if __name__ == "__main__":
unittest.main()