|
1 | 1 | # SPDX-License-Identifier: Apache-2.0
|
2 | 2 |
|
3 | 3 | import asyncio
|
| 4 | +import os |
| 5 | +import signal |
4 | 6 | import time
|
5 | 7 | import uuid
|
6 | 8 | from threading import Thread
|
7 | 9 | from typing import Optional
|
8 | 10 |
|
9 |
| -import psutil |
10 | 11 | import pytest
|
11 | 12 | from transformers import AutoTokenizer
|
12 | 13 |
|
|
17 | 18 | from vllm.usage.usage_lib import UsageContext
|
18 | 19 | from vllm.v1.engine import EngineCoreRequest
|
19 | 20 | from vllm.v1.engine.core import EngineCore
|
20 |
| -from vllm.v1.engine.core_client import (AsyncMPClient, EngineCoreClient, |
21 |
| - SyncMPClient) |
| 21 | +from vllm.v1.engine.core_client import (AsyncMPClient, CoreEngine, |
| 22 | + EngineCoreClient, SyncMPClient) |
22 | 23 | from vllm.v1.executor.abstract import Executor
|
23 | 24 |
|
24 | 25 | from ...distributed.conftest import MockSubscriber
|
@@ -337,34 +338,40 @@ def test_kv_cache_events(
|
337 | 338 | "Token ids should be the same as the custom tokens")
|
338 | 339 | finally:
|
339 | 340 | client.shutdown()
|
340 |
| - return |
341 | 341 |
|
342 | 342 |
|
343 |
| -@pytest.mark.timeout(10) |
| 343 | +@pytest.mark.timeout(20) |
344 | 344 | def test_startup_failure(monkeypatch: pytest.MonkeyPatch):
|
345 | 345 |
|
346 | 346 | with monkeypatch.context() as m, pytest.raises(Exception) as e_info:
|
347 | 347 | m.setenv("VLLM_USE_V1", "1")
|
348 | 348 |
|
| 349 | + # Monkey-patch to extract core process pid while it's starting. |
| 350 | + core_proc_pid = [None] |
| 351 | + ce_ctor = CoreEngine.__init__ |
| 352 | + |
| 353 | + def patched_ce_ctor(self, *args, **kwargs): |
| 354 | + ce_ctor(self, *args, **kwargs) |
| 355 | + core_proc_pid[0] = self.proc_handle.proc.pid |
| 356 | + |
| 357 | + m.setattr(CoreEngine, "__init__", patched_ce_ctor) |
| 358 | + |
| 359 | + t = time.time() |
349 | 360 | engine_args = EngineArgs(model=MODEL_NAME)
|
350 | 361 | vllm_config = engine_args.create_engine_config(
|
351 | 362 | usage_context=UsageContext.UNKNOWN_CONTEXT)
|
352 | 363 | executor_class = Executor.get_class(vllm_config)
|
| 364 | + print(f"VllmConfig creation took {time.time() - t:.2f} seconds.") |
353 | 365 |
|
354 | 366 | # Start another thread to wait for engine core process to start
|
355 | 367 | # and kill it - simulate fatal uncaught process exit.
|
356 |
| - this_proc = psutil.Process() |
357 |
| - children_before = set(this_proc.children()) |
358 | 368 |
|
359 | 369 | def kill_first_child():
|
360 |
| - while True: |
| 370 | + while (child_pid := core_proc_pid[0]) is None: |
361 | 371 | time.sleep(0.5)
|
362 |
| - children = set(this_proc.children()) - children_before |
363 |
| - if children: |
364 |
| - child = children.pop() |
365 |
| - print("Killing child core process", child.pid) |
366 |
| - child.kill() |
367 |
| - break |
| 372 | + print(f"Killing child core process {child_pid}") |
| 373 | + assert isinstance(child_pid, int) |
| 374 | + os.kill(child_pid, signal.SIGKILL) |
368 | 375 |
|
369 | 376 | Thread(target=kill_first_child, daemon=True).start()
|
370 | 377 |
|
|
0 commit comments