Unverified Commit 96a55928 authored by Yan Ru Pei's avatar Yan Ru Pei Committed by GitHub
Browse files

chore(test): declutter router common.py into helper and router_process modules (#7210)


Signed-off-by: default avatarPeaBrane <yanrpei@gmail.com>
parent e094a2db
This diff is collapsed.
This diff is collapsed.
# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
import os
from tests.utils.managed_process import ManagedProcess
class KVRouterProcess(ManagedProcess):
"""Manages the KV router process using dynamo.frontend"""
def __init__(
self,
request,
block_size: int,
frontend_port: int,
namespace: str,
store_backend: str = "etcd",
enforce_disagg: bool = False,
blocks_threshold: float | None = None,
tokens_threshold: float | None = None,
tokens_threshold_frac: float | None = None,
request_plane: str = "nats",
durable_kv_events: bool = False,
):
command = [
"python3",
"-m",
"dynamo.frontend",
"--kv-cache-block-size",
str(block_size),
"--router-mode",
"kv",
"--http-port",
str(frontend_port),
"--discovery-backend",
store_backend,
"--namespace",
namespace,
]
if enforce_disagg:
command.append("--enforce-disagg")
if blocks_threshold is not None:
command.extend(["--active-decode-blocks-threshold", str(blocks_threshold)])
if tokens_threshold is not None:
command.extend(["--active-prefill-tokens-threshold", str(tokens_threshold)])
if tokens_threshold_frac is not None:
command.extend(
["--active-prefill-tokens-threshold-frac", str(tokens_threshold_frac)]
)
if durable_kv_events:
command.append("--router-durable-kv-events")
env = os.environ.copy()
env["DYN_REQUEST_PLANE"] = request_plane
super().__init__(
command=command,
env=env,
timeout=60,
display_output=True,
health_check_ports=[frontend_port],
health_check_urls=[
(f"http://localhost:{frontend_port}/v1/models", self._check_ready)
],
log_dir=request.node.name,
terminate_all_matching_process_names=False,
)
self.port = frontend_port
def _check_ready(self, response):
"""Check if KV router is ready"""
return response.status_code == 200
def __exit__(self, exc_type, exc_val, exc_tb):
super().__exit__(exc_type, exc_val, exc_tb)
...@@ -20,7 +20,7 @@ from typing import Any, Dict, Optional ...@@ -20,7 +20,7 @@ from typing import Any, Dict, Optional
import aiohttp import aiohttp
import pytest import pytest
from tests.router.common import ( # utilities from tests.router.common import (
_test_busy_threshold_endpoint, _test_busy_threshold_endpoint,
_test_python_router_bindings, _test_python_router_bindings,
_test_router_basic, _test_router_basic,
...@@ -30,9 +30,8 @@ from tests.router.common import ( # utilities ...@@ -30,9 +30,8 @@ from tests.router.common import ( # utilities
_test_router_overload_503, _test_router_overload_503,
_test_router_query_instance_id, _test_router_query_instance_id,
_test_router_two_routers, _test_router_two_routers,
generate_random_suffix,
get_runtime,
) )
from tests.router.helper import generate_random_suffix, get_runtime
from tests.utils.constants import ROUTER_MODEL_NAME from tests.utils.constants import ROUTER_MODEL_NAME
from tests.utils.managed_process import ManagedProcess from tests.utils.managed_process import ManagedProcess
from tests.utils.port_utils import allocate_ports, deallocate_ports from tests.utils.port_utils import allocate_ports, deallocate_ports
......
...@@ -12,13 +12,12 @@ from typing import Any, Dict, Optional ...@@ -12,13 +12,12 @@ from typing import Any, Dict, Optional
import pytest import pytest
from tests.router.common import ( # utilities from tests.router.common import (
_test_router_basic, _test_router_basic,
_test_router_decisions, _test_router_decisions,
_test_router_indexers_sync, _test_router_indexers_sync,
generate_random_suffix,
get_runtime,
) )
from tests.router.helper import generate_random_suffix, get_runtime
from tests.utils.constants import DefaultPort from tests.utils.constants import DefaultPort
from tests.utils.managed_process import ManagedProcess from tests.utils.managed_process import ManagedProcess
from tests.utils.port_utils import allocate_ports, deallocate_ports from tests.utils.port_utils import allocate_ports, deallocate_ports
......
...@@ -12,13 +12,12 @@ from typing import Any, Dict, Optional ...@@ -12,13 +12,12 @@ from typing import Any, Dict, Optional
import pytest import pytest
from tests.router.common import ( # utilities from tests.router.common import (
_test_router_basic, _test_router_basic,
_test_router_decisions, _test_router_decisions,
_test_router_indexers_sync, _test_router_indexers_sync,
generate_random_suffix,
get_runtime,
) )
from tests.router.helper import generate_random_suffix, get_runtime
from tests.utils.constants import DefaultPort from tests.utils.constants import DefaultPort
from tests.utils.managed_process import ManagedProcess from tests.utils.managed_process import ManagedProcess
from tests.utils.port_utils import allocate_ports, deallocate_ports from tests.utils.port_utils import allocate_ports, deallocate_ports
......
...@@ -13,13 +13,12 @@ from typing import Any, Dict, Optional ...@@ -13,13 +13,12 @@ from typing import Any, Dict, Optional
import pytest import pytest
from tests.router.common import ( # utilities from tests.router.common import (
_test_router_basic, _test_router_basic,
_test_router_decisions, _test_router_decisions,
_test_router_indexers_sync, _test_router_indexers_sync,
generate_random_suffix,
get_runtime,
) )
from tests.router.helper import generate_random_suffix, get_runtime
from tests.utils.constants import DefaultPort from tests.utils.constants import DefaultPort
from tests.utils.managed_process import ManagedProcess from tests.utils.managed_process import ManagedProcess
from tests.utils.port_utils import allocate_ports, deallocate_ports from tests.utils.port_utils import allocate_ports, deallocate_ports
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment