Skip to content

Commit 87306cc

Browse files
committed
fix(serve/tests): shut down AsyncioRouter after each test to prevent resource leaks
Per code review feedback: each AsyncioRouter instance spawns background tasks (MetricsPusher, LongPollClient). Without explicit teardown these tasks leak into subsequent tests. Add the same cleanup pattern used by the existing setup_router fixture: await router.shutdown() router.long_poll_client.stop() at the end of all three test cases in TestUpdateDeploymentConfigNullRouter. Signed-off-by: chenshi5012 <chenshi5012@163.com>
1 parent a666f4b commit 87306cc

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

python/ray/serve/tests/unit/test_router.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1904,6 +1904,8 @@ async def test_update_deployment_config_with_null_router_no_exception(self):
19041904
)
19051905
# Should not raise AttributeError.
19061906
router.update_deployment_config(DeploymentConfig())
1907+
await router.shutdown()
1908+
router.long_poll_client.stop()
19071909

19081910
async def test_update_deployment_config_with_null_router_passes_zero_replicas(self):
19091911
"""When request_router is None, curr_num_replicas forwarded to
@@ -1937,6 +1939,8 @@ def _capture(deployment_config, curr_num_replicas):
19371939
f"Expected 0 replicas when router is None, "
19381940
f"got {captured['curr_num_replicas']}"
19391941
)
1942+
await router.shutdown()
1943+
router.long_poll_client.stop()
19401944

19411945
async def test_update_deployment_config_with_initialized_router_passes_correct_count(
19421946
self,
@@ -1976,6 +1980,8 @@ def _capture(deployment_config, curr_num_replicas):
19761980
assert captured["curr_num_replicas"] == 1, (
19771981
f"Expected 1 replica, got {captured['curr_num_replicas']}"
19781982
)
1983+
await router.shutdown()
1984+
router.long_poll_client.stop()
19791985

19801986

19811987
@pytest.mark.asyncio

0 commit comments

Comments
 (0)