From c368a4a98c677938ca87002edb6186ff2c02fd83 Mon Sep 17 00:00:00 2001 From: Pascal Date: Fri, 11 Sep 2026 23:08:26 +0200 Subject: [PATCH] tests: serialize the router tests that download the same model Parallel workers share one cache, so the two tests fetch the same blob into the same in-progress file and race to rename it. They now take a file lock around the download, like the session fixture does for the preset models. --- tools/server/tests/unit/test_router.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/tools/server/tests/unit/test_router.py b/tools/server/tests/unit/test_router.py index e4b7f9fe48..932b2718ff 100644 --- a/tools/server/tests/unit/test_router.py +++ b/tools/server/tests/unit/test_router.py @@ -1,5 +1,6 @@ import threading import pytest +from filelock import FileLock from utils import * server: ServerProcess @@ -504,6 +505,18 @@ MODEL_DOWNLOAD_ID = "ggml-org/test-model-router-download:F16" MODEL_DOWNLOAD_TIMEOUT = 30 +@pytest.fixture +def download_model_lock(tmp_path_factory): + """Serialize the tests that download MODEL_DOWNLOAD_ID. + + Parallel workers share one cache, so they would fetch the same blob into + the same in-progress file and race to rename it. + """ + root_tmp_dir = tmp_path_factory.getbasetemp().parent + with FileLock(str(root_tmp_dir / "model_download.lock")): + yield + + def _listen_sse( server: ServerProcess, collected: list, stop: threading.Event, ready: threading.Event | None = None ): @@ -539,7 +552,7 @@ def _wait_for_sse_event(collected: list, event_type: str, model: str, timeout: i return False -def test_router_download_model(): +def test_router_download_model(download_model_lock): """Case 1: download a model, verify SSE events and GET /models.""" global server server.start() @@ -582,7 +595,7 @@ def test_router_download_model(): assert MODEL_DOWNLOAD_ID in ids, f"{MODEL_DOWNLOAD_ID} not found in /models after download" -def test_router_delete_model(): +def test_router_delete_model(download_model_lock): """Case 2: delete the downloaded model, verify it disappears from GET /models.""" global server server.start()