From c6598afec8fef5f951b25f8c6b20b5f7762eacca Mon Sep 17 00:00:00 2001 From: maziggy Date: Tue, 20 Oct 2026 15:35:54 +0200 Subject: [PATCH] test: library/queue probe files get unique names, so parallel workers no longer delete each other's files ("File not found on disk" flake) --- .../integration/test_api_key_queue_acts_as_owner.py | 4 +++- backend/tests/integration/test_library_api.py | 9 ++++++--- .../tests/integration/test_queue_creation_attribution.py | 4 +++- backend/tests/integration/test_queue_review_1620.py | 4 +++- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/backend/tests/integration/test_api_key_queue_acts_as_owner.py b/backend/tests/integration/test_api_key_queue_acts_as_owner.py index 61a7c7b42..95ceb7b50 100644 --- a/backend/tests/integration/test_api_key_queue_acts_as_owner.py +++ b/backend/tests/integration/test_api_key_queue_acts_as_owner.py @@ -10,6 +10,7 @@ nothing and may use no cost center. from __future__ import annotations from pathlib import Path +from uuid import uuid4 import pytest from httpx import AsyncClient @@ -261,7 +262,8 @@ class TestSources: async def test_another_users_library_file_is_not_found(self, async_client, db_session, world): await _set(db_session, "billing_enabled", "false") - rel_path = "archive/library/files/probe_3256.gcode.3mf" + # Unique: the checkout's library folder is shared by every xdist worker. + rel_path = f"archive/library/files/probe_3256_{uuid4().hex}.gcode.3mf" abs_path = Path(app_settings.base_dir) / rel_path abs_path.parent.mkdir(parents=True, exist_ok=True) abs_path.write_bytes(b"probe") diff --git a/backend/tests/integration/test_library_api.py b/backend/tests/integration/test_library_api.py index c5f4f5ec7..c7128809f 100644 --- a/backend/tests/integration/test_library_api.py +++ b/backend/tests/integration/test_library_api.py @@ -4,6 +4,7 @@ import io import tempfile import zipfile from pathlib import Path +from uuid import uuid4 import pytest from httpx import AsyncClient @@ -749,13 +750,15 @@ class TestLibraryAddToQueueAPI: written: list[Path] = [] async def _create(**kwargs): - counter = len(written) + 1 - rel_path = kwargs.pop("file_path", f"archive/library/files/queue_probe_{counter}.gcode.3mf") + # A unique name: this is the checkout's real library folder, shared by + # every xdist worker, and a sibling's teardown deleted a same-named + # probe this test still needed ("File not found on disk"). + rel_path = kwargs.pop("file_path", f"archive/library/files/queue_probe_{uuid4().hex}.gcode.3mf") abs_path = Path(app_settings.base_dir) / rel_path abs_path.parent.mkdir(parents=True, exist_ok=True) abs_path.write_bytes(b"probe") written.append(abs_path) - kwargs.setdefault("filename", f"queue_probe_{counter}.gcode.3mf") + kwargs.setdefault("filename", Path(rel_path).name) return await library_file_factory(file_path=rel_path, **kwargs) yield _create diff --git a/backend/tests/integration/test_queue_creation_attribution.py b/backend/tests/integration/test_queue_creation_attribution.py index 40883e914..46bbeaea2 100644 --- a/backend/tests/integration/test_queue_creation_attribution.py +++ b/backend/tests/integration/test_queue_creation_attribution.py @@ -21,6 +21,7 @@ the same NULL-is-meaningful contract on the `/start` path. from __future__ import annotations from pathlib import Path +from uuid import uuid4 import pytest from httpx import AsyncClient @@ -69,7 +70,8 @@ async def sliced_library_file(db_session): route rejects rows whose file is missing from disk).""" from backend.app.models.library import LibraryFile - rel_path = "archive/library/files/attribution_probe.gcode.3mf" + # Unique: the checkout's library folder is shared by every xdist worker. + rel_path = f"archive/library/files/attribution_probe_{uuid4().hex}.gcode.3mf" abs_path = Path(app_settings.base_dir) / rel_path abs_path.parent.mkdir(parents=True, exist_ok=True) abs_path.write_bytes(b"probe") diff --git a/backend/tests/integration/test_queue_review_1620.py b/backend/tests/integration/test_queue_review_1620.py index e1861f1d8..a96879cb9 100644 --- a/backend/tests/integration/test_queue_review_1620.py +++ b/backend/tests/integration/test_queue_review_1620.py @@ -16,6 +16,7 @@ every way a job can be created or set going: from __future__ import annotations from pathlib import Path +from uuid import uuid4 import pytest from httpx import AsyncClient @@ -132,7 +133,8 @@ class TestQueueing: async def test_library_add_to_queue_waits(self, async_client, setup, db_session): from backend.app.models.library import LibraryFile - rel_path = "archive/library/files/review_probe.gcode.3mf" + # Unique: the checkout's library folder is shared by every xdist worker. + rel_path = f"archive/library/files/review_probe_{uuid4().hex}.gcode.3mf" abs_path = Path(app_settings.base_dir) / rel_path abs_path.parent.mkdir(parents=True, exist_ok=True) abs_path.write_bytes(b"probe")