Skip to content

Commit d600c76

Browse files
committed
test(assets): make seed content unique per test for isolation
Removing the delete_content param means delete is always a soft delete, so content created by one test now survives into the next. The suite had been relying on hard-delete teardown for isolation, so shared fixed-content fixtures started colliding: seeded_asset (b"A"*4096) and make_asset_bytes (deterministic on name) produced the same hash every test, so the second seed deduped to the surviving asset and returned 200 instead of 201, cascading into ~14 failures/errors. Salt both fixtures with a per-test uuid so each test creates fresh content (created_new True, 201), while keeping content deterministic within a test (same name/size -> same bytes) and preserving exact byte length so size-based list/sort assertions are unaffected.
1 parent 795927b commit d600c76

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

tests-unit/assets_test/conftest.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import sys
77
import tempfile
88
import time
9+
import uuid
910
from pathlib import Path
1011
from typing import Callable, Iterator, Optional
1112

@@ -188,9 +189,17 @@ def _post_multipart_asset(
188189

189190
@pytest.fixture
190191
def make_asset_bytes() -> Callable[[str, int], bytes]:
192+
# Salt content per test so it never collides with assets left over from
193+
# earlier tests. Delete is now always a soft delete (content is preserved),
194+
# so the suite can no longer rely on hard-deleting content for isolation.
195+
# Deterministic within a test: the same (name, size) yields the same bytes.
196+
salt = uuid.uuid4().bytes
197+
191198
def _make(name: str, size: int = 8192) -> bytes:
192199
seed = sum(ord(c) for c in name) % 251
193-
return bytes((i * 31 + seed) % 256 for i in range(size))
200+
body = bytearray((i * 31 + seed) % 256 for i in range(size))
201+
body[: len(salt)] = salt[:size]
202+
return bytes(body)
194203
return _make
195204

196205

@@ -227,7 +236,11 @@ def seeded_asset(request: pytest.FixtureRequest, http: requests.Session, api_bas
227236
if tags is None:
228237
tags = ["models", "checkpoints", "unit-tests", "alpha"]
229238
meta = {"purpose": "test", "epoch": 1, "flags": ["x", "y"], "nullable": None}
230-
files = {"file": (name, b"A" * 4096, "application/octet-stream")}
239+
# Unique content per test so the seed always creates a fresh asset (201).
240+
# Delete is now always a soft delete, so content from a prior test survives
241+
# and would otherwise dedup this upload into an existing asset (200).
242+
content = uuid.uuid4().bytes + b"A" * (4096 - 16)
243+
files = {"file": (name, content, "application/octet-stream")}
231244
form_data = {
232245
"tags": json.dumps(tags),
233246
"name": name,

0 commit comments

Comments
 (0)