|
| 1 | +# SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +import pytest |
| 5 | +import requests |
| 6 | +import time |
| 7 | +import subprocess |
| 8 | +from pathlib import Path |
| 9 | + |
| 10 | + |
| 11 | +class TestAIPerfMockServerIntegration: |
| 12 | + @pytest.fixture(scope="class") |
| 13 | + def test_server(self): |
| 14 | + """Start a test LLM inference server for integration testing""" |
| 15 | + # Start test server (e.g., vLLM, Triton, etc.) |
| 16 | + server_process = subprocess.Popen( |
| 17 | + [ |
| 18 | + "aiperf-mock-server", |
| 19 | + "-m", |
| 20 | + "Qwen/Qwen3-0.6B", |
| 21 | + "-p", |
| 22 | + "8080", |
| 23 | + ] |
| 24 | + ) |
| 25 | + |
| 26 | + # Wait for server to be ready |
| 27 | + self._wait_for_server_ready("http://127.0.0.1:8080") |
| 28 | + |
| 29 | + yield "http://127.0.0.1:8080" |
| 30 | + |
| 31 | + # Cleanup |
| 32 | + server_process.terminate() |
| 33 | + server_process.wait() |
| 34 | + |
| 35 | + def _wait_for_server_ready(self, url, timeout=60): |
| 36 | + """Wait for server to become ready""" |
| 37 | + start_time = time.time() |
| 38 | + while time.time() - start_time < timeout: |
| 39 | + try: |
| 40 | + response = requests.get(f"{url}/health", timeout=5) |
| 41 | + if response.status_code == 200: |
| 42 | + return |
| 43 | + except requests.exceptions.RequestException: |
| 44 | + pass |
| 45 | + time.sleep(2) |
| 46 | + raise RuntimeError("Server failed to start within timeout") |
| 47 | + |
| 48 | + def test_basic_performance_analysis(self, test_server): |
| 49 | + """Test basic throughput and latency measurement""" |
| 50 | + # Run your CLI tool against the test server |
| 51 | + result = subprocess.run( |
| 52 | + [ |
| 53 | + "aiperf", |
| 54 | + "profile", |
| 55 | + "--model-names", |
| 56 | + "Qwen/Qwen3-0.6B", |
| 57 | + "--concurrency", |
| 58 | + "1", |
| 59 | + "--request-count", |
| 60 | + "1", |
| 61 | + ], |
| 62 | + capture_output=True, |
| 63 | + text=True, |
| 64 | + ) |
| 65 | + |
| 66 | + assert result.returncode == 0, f"aiperf failed: {result.stderr}" |
| 67 | + |
| 68 | + # Parse and validate output |
| 69 | + import json |
| 70 | + |
| 71 | + output = json.loads(result.stdout) |
| 72 | + |
| 73 | + # Verify key metrics are present |
| 74 | + assert "ttft_avg" in output |
| 75 | + assert "tpot_avg" in output |
| 76 | + assert "throughput_tokens_per_sec" in output |
| 77 | + assert "request_throughput" in output |
| 78 | + |
| 79 | + # Verify metrics are reasonable |
| 80 | + assert output["ttft_avg"] > 0 |
| 81 | + assert output["tpot_avg"] > 0 |
| 82 | + assert output["throughput_tokens_per_sec"] > 0 |
0 commit comments