并发版
This commit is contained in:
1 parent
cd2ca406a5
commit
d39b58255d
11 files changed
+530
-73
No files matched your search
@@ -11,6 +11,7 @@ import pytest
|
||||
from app.gateway.routers import system_settings as ss_router
|
||||
from app.gateway.services import (
|
||||
_get_model_concurrency_limit,
|
||||
_get_user_model_concurrency_limit,
|
||||
_resolve_effective_run_model_name,
|
||||
)
|
||||
from deerflow.config import system_settings as ss
|
||||
@@ -52,23 +53,31 @@ async def test_model_concurrency_settings_round_trip(
|
||||
enabled=True,
|
||||
default_limit=8,
|
||||
model_limits={"glm5": 10, "deepseek": 4},
|
||||
user_default_limit=2,
|
||||
user_model_limits={"glm5": 1},
|
||||
),
|
||||
req,
|
||||
)
|
||||
assert saved.enabled is True
|
||||
assert saved.default_limit == 8
|
||||
assert saved.model_limits == {"glm5": 10, "deepseek": 4}
|
||||
assert saved.user_default_limit == 2
|
||||
assert saved.user_model_limits == {"glm5": 1}
|
||||
|
||||
file_path = tmp_runtime_home / "system_settings.json"
|
||||
payload = json.loads(file_path.read_text(encoding="utf-8"))
|
||||
assert payload["model_concurrency"]["enabled"] is True
|
||||
assert payload["model_concurrency"]["default_limit"] == 8
|
||||
assert payload["model_concurrency"]["model_limits"]["glm5"] == 10
|
||||
assert payload["model_concurrency"]["user_default_limit"] == 2
|
||||
assert payload["model_concurrency"]["user_model_limits"]["glm5"] == 1
|
||||
|
||||
loaded = await ss_router.get_model_concurrency(req)
|
||||
assert loaded.enabled is True
|
||||
assert loaded.default_limit == 8
|
||||
assert loaded.model_limits["deepseek"] == 4
|
||||
assert loaded.user_default_limit == 2
|
||||
assert loaded.user_model_limits["glm5"] == 1
|
||||
|
||||
|
||||
def test_resolve_effective_run_model_name_prefers_requested_model(
|
||||
@@ -183,6 +192,44 @@ async def test_run_manager_rejects_model_limit_atomically(
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_run_manager_rejects_user_model_limit_atomically(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
monkeypatch.setattr(
|
||||
"app.gateway.services.load_system_settings",
|
||||
lambda: SimpleNamespace(
|
||||
model_concurrency=SimpleNamespace(
|
||||
enabled=True,
|
||||
default_limit=10,
|
||||
model_limits={},
|
||||
user_default_limit=3,
|
||||
user_model_limits={"glm5": 1},
|
||||
)
|
||||
),
|
||||
)
|
||||
assert _get_user_model_concurrency_limit("glm5") == 1
|
||||
assert _get_user_model_concurrency_limit("other") == 3
|
||||
|
||||
run_mgr = RunManager()
|
||||
await run_mgr.create_or_reject("t1", metadata={"model_name": "glm5", "user_id": "u1"})
|
||||
await run_mgr.create_or_reject(
|
||||
"t2",
|
||||
metadata={"model_name": "glm5", "user_id": "u2"},
|
||||
user_model_concurrency_limit=("glm5", "u2", 1),
|
||||
)
|
||||
|
||||
with pytest.raises(ModelConcurrencyLimitError) as exc_info:
|
||||
await run_mgr.create_or_reject(
|
||||
"t3",
|
||||
metadata={"model_name": "glm5", "user_id": "u1"},
|
||||
user_model_concurrency_limit=("glm5", "u1", 1),
|
||||
)
|
||||
|
||||
assert exc_info.value.scope == "user_model"
|
||||
assert exc_info.value.user_id == "u1"
|
||||
|
||||
|
||||
def test_get_model_concurrency_limit_skips_when_disabled(
|
||||
monkeypatch: pytest.MonkeyPatch,
|
||||
) -> None:
|
||||
@@ -193,7 +240,10 @@ def test_get_model_concurrency_limit_skips_when_disabled(
|
||||
enabled=False,
|
||||
default_limit=1,
|
||||
model_limits={"glm5": 1},
|
||||
user_default_limit=1,
|
||||
user_model_limits={"glm5": 1},
|
||||
)
|
||||
),
|
||||
)
|
||||
assert _get_model_concurrency_limit("glm5") is None
|
||||
assert _get_user_model_concurrency_limit("glm5") is None
|
||||
Reference in new issue
Block a user