server : use pytest-xdist for server tests (#28298)

* server : use pytest-xdist for server tests

This commit adds pytest-xdist to the server tests. This is pytest
plugin that distributes test execution across multiple CPU cores.

Assisted-by: pi:llama.cpp/qwen3.8-27B

Refs: https://github.com/ggml-org/llama.cpp/pull/26734#issuecomment-5220707042

* remove server_base_port and BASE_PORT

* use worksteal and pytest builting tmp_path
This commit is contained in:
Daniel Bevenius
2026-09-03 15:04:30 +02:00
committed by GitHub
parent de8656bd94
commit 42f0225fea
10 changed files with 36 additions and 26 deletions
+16 -2
View File
@@ -1,7 +1,17 @@
import os
import pytest
from filelock import FileLock
from utils import *
@pytest.fixture(scope="session", autouse=True)
def configure_worker_port(request):
worker_id = getattr(request.config, "workerinput", {}).get("workerid", "master")
if worker_id != "master":
worker_num = int(worker_id[2:])
os.environ["PORT"] = str(8080 + worker_num * 10)
# ref: https://stackoverflow.com/questions/22627659/run-code-before-and-after-each-test-in-py-test
@pytest.fixture(autouse=True)
def stop_server_after_each_test():
@@ -16,6 +26,10 @@ def stop_server_after_each_test():
@pytest.fixture(scope="session", autouse=True)
def load_server_presets():
def load_server_presets(configure_worker_port, tmp_path_factory):
# this will be run once per test session, before any tests
ServerPreset.load_all()
# serialize model downloads across parallel workers.
root_tmp_dir = tmp_path_factory.getbasetemp().parent
with FileLock(str(root_tmp_dir / "load_all.lock")):
ServerPreset.load_all()