feat: add tiered durable state and memory bounds

This commit is contained in:
CoolBoy
2026-08-22 14:15:25 +08:00
parent 6eb7ded984
commit 5b1ec4d3eb
11 changed files with 722 additions and 40 deletions

View File

@@ -3,6 +3,7 @@ from __future__ import annotations
import sys
import unittest
from pathlib import Path
from unittest.mock import patch
PACKAGE_DIR = Path(__file__).resolve().parents[1] / "modelhub_submmit_api"
@@ -68,6 +69,17 @@ class ModelScopeDiscoveryTests(unittest.TestCase):
self.assertEqual(1786294389, int(first.timestamp())) # type: ignore[union-attr]
self.assertEqual(1, metadata_client.calls)
def test_model_detail_cache_evicts_old_entries_at_fixed_limit(self) -> None:
metadata_client = ModelMetadataClient()
with patch.dict("os.environ", {"MODELSCOPE_DETAIL_CACHE_MAX_MODELS": "32"}):
discovery = HuggingFaceDiscovery(legacy_http_client=metadata_client) # type: ignore[arg-type]
for index in range(40):
discovery.get_model_last_modified(f"owner/model-{index}")
self.assertEqual(32, len(discovery._model_last_modified_cache))
discovery.get_model_last_modified("owner/model-0")
self.assertEqual(41, metadata_client.calls)
def test_openapi_page_size_never_exceeds_platform_limit(self) -> None:
http_client = RecordingHttpClient()
discovery = HuggingFaceDiscovery(http_client=http_client) # type: ignore[arg-type]