Include ongoing downloads in calculate_used_storage

This commit is contained in:
ciaranbor
2026-03-10 11:27:56 +00:00
parent 9832f161e7
commit a0fad061e2
3 changed files with 28 additions and 3 deletions
@@ -536,3 +536,28 @@ class TestClearRejections:
assert isinstance(coordinator.download_status[MODEL_A], DownloadEvicted)
# Rejected should be cleared to Pending
assert isinstance(coordinator.download_status[MODEL_B], DownloadPending)
async def test_clear_rejections_on_policy_only_change(self) -> None:
"""clear_rejections fires even when only the policy changes (no limit change)."""
config = StorageConfig(
max_storage=Memory.from_gb(10), storage_policy="manual"
)
rejected = DownloadRejected(
node_id=NODE_ID,
shard_metadata=_shard(MODEL_A, 4),
reason="Manual policy",
required=Memory.from_gb(4),
available=Memory.from_gb(1),
limit=Memory.from_gb(10),
)
coordinator, _ = _make_coordinator(
config,
{MODEL_A: rejected, MODEL_B: _completed(MODEL_B, 3)},
)
await coordinator.clear_rejections()
# Rejected should be cleared to Pending
assert isinstance(coordinator.download_status[MODEL_A], DownloadPending)
# Completed should be unchanged
assert isinstance(coordinator.download_status[MODEL_B], DownloadCompleted)
+1 -1
View File
@@ -17,7 +17,7 @@ def calculate_used_storage(downloads: Sequence[DownloadProgress]) -> Memory:
if isinstance(dp, DownloadCompleted):
total = total + dp.total
elif isinstance(dp, DownloadOngoing):
total = total + dp.download_progress.downloaded
total = total + dp.download_progress.total
return total
+2 -2
View File
@@ -193,8 +193,8 @@ class TestCalculateUsedStorage:
),
]
used = calculate_used_storage(downloads)
# 5 GiB completed + 3 GiB ongoing downloaded = 8 GiB
assert abs(used.in_gb - 8.0) < 0.01
# 5 GiB completed + 10 GiB ongoing total = 15 GiB
assert abs(used.in_gb - 15.0) < 0.01
def test_empty_downloads(self) -> None:
assert calculate_used_storage([]).in_bytes == 0