TestStreamingSessionAbortLeakRepro: inherit stdout/stderr instead of tempfile (#22668)

This commit is contained in:
Liangsheng Yin
2026-04-13 00:37:29 -07:00
committed by GitHub
parent 4a746ea462
commit 9e6d1c066e
@@ -11,11 +11,8 @@ Usage:
import asyncio import asyncio
import json import json
import os
import tempfile
import time import time
import unittest import unittest
from pathlib import Path
from typing import Any, Optional from typing import Any, Optional
import aiohttp import aiohttp
@@ -281,13 +278,6 @@ async def _abort_repro_generate(
return data return data
def _read_tail(path: str, num_lines: int = 120) -> str:
if not path or not os.path.exists(path):
return "<missing log>"
lines = Path(path).read_text(errors="replace").splitlines()
return "\n".join(lines[-num_lines:])
async def _abort_repro_run_all(base_url: str, tokenizer: Any) -> None: async def _abort_repro_run_all(base_url: str, tokenizer: Any) -> None:
timeout = aiohttp.ClientTimeout(total=300) timeout = aiohttp.ClientTimeout(total=300)
async with aiohttp.ClientSession(timeout=timeout) as http: async with aiohttp.ClientSession(timeout=timeout) as http:
@@ -683,20 +673,6 @@ class TestStreamingSessionAbortLeakRepro(CustomTestCase):
def setUpClass(cls): def setUpClass(cls):
cls.model = DEFAULT_SMALL_MODEL_NAME_FOR_TEST cls.model = DEFAULT_SMALL_MODEL_NAME_FOR_TEST
cls.base_url = DEFAULT_URL_FOR_TEST cls.base_url = DEFAULT_URL_FOR_TEST
cls.stdout = tempfile.NamedTemporaryFile(
prefix="streaming-session-abort-repro.",
suffix=".stdout.log",
delete=False,
mode="w+",
encoding="utf-8",
)
cls.stderr = tempfile.NamedTemporaryFile(
prefix="streaming-session-abort-repro.",
suffix=".stderr.log",
delete=False,
mode="w+",
encoding="utf-8",
)
cls.process = popen_launch_server( cls.process = popen_launch_server(
cls.model, cls.model,
cls.base_url, cls.base_url,
@@ -714,18 +690,12 @@ class TestStreamingSessionAbortLeakRepro(CustomTestCase):
"--log-level", "--log-level",
"info", "info",
], ],
return_stdout_stderr=(cls.stdout, cls.stderr),
) )
cls.tokenizer = get_tokenizer(cls.model) cls.tokenizer = get_tokenizer(cls.model)
@classmethod @classmethod
def tearDownClass(cls): def tearDownClass(cls):
kill_process_tree(cls.process.pid) kill_process_tree(cls.process.pid)
for handle in (cls.stdout, cls.stderr):
path = handle.name
handle.close()
if os.path.exists(path):
os.remove(path)
def test_abort_heavy_chunked_prefill_does_not_leak(self) -> None: def test_abort_heavy_chunked_prefill_does_not_leak(self) -> None:
requests.post(self.base_url + "/flush_cache") requests.post(self.base_url + "/flush_cache")
@@ -747,23 +717,14 @@ class TestStreamingSessionAbortLeakRepro(CustomTestCase):
time.sleep(5) time.sleep(5)
self.assertIsNone( self.assertIsNone(
self.process.poll(), self.process.poll(),
"Server crashed during abort-heavy streaming session repro.\n" "Server crashed during abort-heavy streaming session repro.",
f"---- stderr tail ----\n{_read_tail(self.stderr.name)}",
) )
health = requests.get(self.base_url + "/health", timeout=10) health = requests.get(self.base_url + "/health", timeout=10)
self.assertEqual( self.assertEqual(
health.status_code, health.status_code,
200, 200,
"Server unhealthy after abort-heavy streaming session cleanup.\n" "Server unhealthy after abort-heavy streaming session cleanup.",
f"---- stderr tail ----\n{_read_tail(self.stderr.name)}",
)
stderr_tail = _read_tail(self.stderr.name)
self.assertNotIn(
"token_to_kv_pool_allocator memory leak detected",
stderr_tail,
stderr_tail,
) )