瀏覽代碼

test: library/queue probe files get unique names, so parallel workers no longer delete each other's files ("File not found on disk" flake)

maziggy 2 天之前
父節點
當前提交
c6598afec8

+ 3 - 1
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")

+ 6 - 3
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

+ 3 - 1
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")

+ 3 - 1
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")