Convert formatting to use ruff instead of yapf + isort (#26247)

Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
This commit is contained in:
Harry Mellor
2025-10-05 15:06:22 +01:00
committed by GitHub
parent 17edd8a807
commit d6953beb91
1508 changed files with 115244 additions and 94146 deletions

View File

@@ -10,8 +10,7 @@ from unittest.mock import patch
import pytest
from vllm.v1.utils import (APIServerProcessManager,
wait_for_completion_or_failure)
from vllm.v1.utils import APIServerProcessManager, wait_for_completion_or_failure
# Global variables to control worker behavior
WORKER_RUNTIME_SECONDS = 0.5
@@ -30,26 +29,22 @@ def api_server_args():
"""Fixture to provide arguments for APIServerProcessManager."""
sock = socket.socket()
return {
"target_server_fn":
mock_run_api_server_worker,
"listen_address":
"localhost:8000",
"sock":
sock,
"args":
"test_args", # Simple string to avoid pickling issues
"num_servers":
3,
"target_server_fn": mock_run_api_server_worker,
"listen_address": "localhost:8000",
"sock": sock,
"args": "test_args", # Simple string to avoid pickling issues
"num_servers": 3,
"input_addresses": [
"tcp://127.0.0.1:5001", "tcp://127.0.0.1:5002",
"tcp://127.0.0.1:5003"
"tcp://127.0.0.1:5001",
"tcp://127.0.0.1:5002",
"tcp://127.0.0.1:5003",
],
"output_addresses": [
"tcp://127.0.0.1:6001", "tcp://127.0.0.1:6002",
"tcp://127.0.0.1:6003"
"tcp://127.0.0.1:6001",
"tcp://127.0.0.1:6002",
"tcp://127.0.0.1:6003",
],
"stats_update_address":
"tcp://127.0.0.1:7000",
"stats_update_address": "tcp://127.0.0.1:7000",
}
@@ -95,8 +90,9 @@ def test_api_server_process_manager_init(api_server_args, with_stats_update):
assert not proc.is_alive()
@patch("vllm.entrypoints.cli.serve.run_api_server_worker_proc",
mock_run_api_server_worker)
@patch(
"vllm.entrypoints.cli.serve.run_api_server_worker_proc", mock_run_api_server_worker
)
def test_wait_for_completion_or_failure(api_server_args):
"""Test that wait_for_completion_or_failure works with failures."""
global WORKER_RUNTIME_SECONDS
@@ -118,8 +114,7 @@ def test_wait_for_completion_or_failure(api_server_args):
result["exception"] = e
# Start a thread to run wait_for_completion_or_failure
wait_thread = threading.Thread(target=run_with_exception_capture,
daemon=True)
wait_thread = threading.Thread(target=run_with_exception_capture, daemon=True)
wait_thread.start()
# Let all processes run for a short time
@@ -174,8 +169,7 @@ def test_normal_completion(api_server_args):
# Verify all processes have terminated
for i, proc in enumerate(manager.processes):
assert not proc.is_alive(
), f"Process {i} still alive after terminate()"
assert not proc.is_alive(), f"Process {i} still alive after terminate()"
# Now call wait_for_completion_or_failure
# since all processes have already
@@ -198,13 +192,13 @@ def test_external_process_monitoring(api_server_args):
# Create and start the external process
# (simulates local_engine_manager or coordinator)
spawn_context = multiprocessing.get_context("spawn")
external_proc = spawn_context.Process(target=mock_run_api_server_worker,
name="MockExternalProcess")
external_proc = spawn_context.Process(
target=mock_run_api_server_worker, name="MockExternalProcess"
)
external_proc.start()
# Create the class to simulate a coordinator
class MockCoordinator:
def __init__(self, proc):
self.proc = proc
@@ -228,14 +222,14 @@ def test_external_process_monitoring(api_server_args):
def run_with_exception_capture():
try:
wait_for_completion_or_failure(api_server_manager=manager,
coordinator=mock_coordinator)
wait_for_completion_or_failure(
api_server_manager=manager, coordinator=mock_coordinator
)
except Exception as e:
result["exception"] = e
# Start a thread to run wait_for_completion_or_failure
wait_thread = threading.Thread(target=run_with_exception_capture,
daemon=True)
wait_thread = threading.Thread(target=run_with_exception_capture, daemon=True)
wait_thread.start()
# Terminate the external process to trigger a failure
@@ -246,21 +240,23 @@ def test_external_process_monitoring(api_server_args):
wait_thread.join(timeout=1.0)
# The wait thread should have completed
assert not wait_thread.is_alive(
), "wait_for_completion_or_failure thread still running"
assert not wait_thread.is_alive(), (
"wait_for_completion_or_failure thread still running"
)
# Verify that an exception was raised with appropriate error message
assert result["exception"] is not None, "No exception was raised"
error_message = str(result["exception"])
assert "died with exit code" in error_message, \
assert "died with exit code" in error_message, (
f"Unexpected error message: {error_message}"
assert "MockExternalProcess" in error_message, \
)
assert "MockExternalProcess" in error_message, (
f"Error doesn't mention external process: {error_message}"
)
# Verify that all API server processes were terminated as a result
for i, proc in enumerate(manager.processes):
assert not proc.is_alive(
), f"API server process {i} was not terminated"
assert not proc.is_alive(), f"API server process {i} was not terminated"
finally:
# Clean up