fix(simulation): reserve disk space before artifact import
This commit is contained in:
@@ -611,6 +611,63 @@ def test_failed_project_retries_from_retained_source_and_releases_old_job(tmp_pa
|
||||
assert queued["source"]["uploaded_byte_length"] == queued["source"]["total_byte_length"]
|
||||
|
||||
|
||||
def test_import_evicts_only_worker_backed_archive_staging_when_disk_is_low(
|
||||
tmp_path: Path,
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
store = SimulationProjectStore(tmp_path)
|
||||
project = store.create(
|
||||
name="Worker-backed archive",
|
||||
scene_type="outdoor",
|
||||
source_kind="archive",
|
||||
files=[{"logical_path": "scene.rar", "byte_length": 6}],
|
||||
)
|
||||
source_file = project["source"]["files"][0]
|
||||
store.append_upload(
|
||||
project["project_id"],
|
||||
source_file["file_id"],
|
||||
offset=0,
|
||||
payload=b"source",
|
||||
)
|
||||
store.begin_build(project["project_id"])
|
||||
store.update_processing(
|
||||
project["project_id"],
|
||||
status="processing",
|
||||
provider_job_id="gsp-20260826000000-deadbeef",
|
||||
provider_state="ready",
|
||||
)
|
||||
service = SimulationProjectService(store, provider_factory=lambda: None)
|
||||
source_path = store.source_root(project["project_id"]) / "scene.rar"
|
||||
|
||||
class _DiskUsage:
|
||||
def __init__(self, free: int) -> None:
|
||||
self.free = free
|
||||
|
||||
monkeypatch.setattr(
|
||||
"k1link.simulation.projects.shutil.disk_usage",
|
||||
lambda _path: _DiskUsage(0 if source_path.exists() else 10 * 1024**3),
|
||||
)
|
||||
artifacts = [
|
||||
{
|
||||
"role": "preview",
|
||||
"logical_path": "preview.sog",
|
||||
"media_type": "application/octet-stream",
|
||||
"sha256": "a" * 64,
|
||||
"byte_length": 1024,
|
||||
}
|
||||
]
|
||||
|
||||
service._ensure_import_capacity(
|
||||
project["project_id"],
|
||||
artifacts,
|
||||
store.artifacts_root(project["project_id"]),
|
||||
)
|
||||
|
||||
assert not source_path.exists()
|
||||
retained_metadata = store.get(project["project_id"])["source"]
|
||||
assert retained_metadata["uploaded_byte_length"] == retained_metadata["total_byte_length"]
|
||||
|
||||
|
||||
def test_failed_local_project_reattaches_to_live_provider_job_without_rebuild(
|
||||
tmp_path: Path,
|
||||
) -> None:
|
||||
|
||||
Reference in New Issue
Block a user