chore: checkpoint current backend/runtime changes

This commit is contained in:
qzl
2026-03-06 17:28:17 +08:00
parent 2c59fe5ee2
commit b6087fd195
32 changed files with 1641 additions and 469 deletions
@@ -3,7 +3,7 @@ from __future__ import annotations
import pytest
from core.config.settings import RedisSettings
from services.base.redis import RedisService
from services.base.redis import RedisService, get_or_init_redis_client, redis_service
class _FakeRedisClient:
@@ -96,3 +96,35 @@ def test_get_client_raises_before_init() -> None:
with pytest.raises(RuntimeError):
service.get_client()
@pytest.mark.asyncio
async def test_get_or_init_redis_client_initializes_when_needed(
monkeypatch: pytest.MonkeyPatch,
) -> None:
fake_client = _FakeRedisClient()
async def _fake_initialize() -> bool:
return True
monkeypatch.setattr(type(redis_service), "is_initialized", property(lambda _: False))
monkeypatch.setattr(redis_service, "initialize", _fake_initialize)
monkeypatch.setattr(redis_service, "get_client", lambda: fake_client)
client = await get_or_init_redis_client()
assert client is fake_client
@pytest.mark.asyncio
async def test_get_or_init_redis_client_raises_when_init_fails(
monkeypatch: pytest.MonkeyPatch,
) -> None:
async def _fake_initialize() -> bool:
return False
monkeypatch.setattr(type(redis_service), "is_initialized", property(lambda _: False))
monkeypatch.setattr(redis_service, "initialize", _fake_initialize)
with pytest.raises(RuntimeError, match="Redis service initialization failed"):
await get_or_init_redis_client()