test(ollama): align slow recovery with gcp routing policy
Some checks failed
CD Pipeline / tests (push) Failing after 1m51s
CD Pipeline / build-and-deploy (push) Has been skipped
CD Pipeline / post-deploy-checks (push) Has been skipped
Code Review / ai-code-review (push) Successful in 33s

This commit is contained in:
Your Name
2026-05-05 13:21:16 +08:00
parent b3d412f9eb
commit 33d4326cce

View File

@@ -8,7 +8,7 @@ OllamaAutoRecoveryService 單元測試 - P1.1d
測試覆蓋:
1. 111 OFFLINE → HEALTHY × 3 → 觸發 _switch_back_to_ollama
2. 111 OFFLINE → HEALTHY × 2 → OFFLINE → counter 歸零
3. 中途 SLOW/DEGRADED → counter 歸零
3. 中途 DEGRADED/OFFLINE → counter 歸零SLOW 視為可用GCP 高負載仍優於 Gemini
4. stop() 優雅取消 task
5. start() 重複呼叫不重複建立 task
6. _switch_back_to_ollamaclear_cache + notify_recovery + Telegram alerter
@@ -22,17 +22,16 @@ OllamaAutoRecoveryService 單元測試 - P1.1d
from __future__ import annotations
import asyncio
from unittest.mock import AsyncMock, MagicMock, call, patch
from unittest.mock import AsyncMock, MagicMock, patch
import pytest
from src.services.ollama_health_monitor import HealthReport, HealthStatus
from src.services.ollama_auto_recovery import (
OllamaAutoRecoveryService,
get_ollama_auto_recovery_service,
reset_ollama_auto_recovery_service,
)
from src.services.ollama_health_monitor import HealthReport, HealthStatus
# =============================================================================
# Fixtures / Helpers
@@ -115,15 +114,15 @@ class TestCheckAndRecover:
assert svc.consecutive_healthy == 0
@pytest.mark.asyncio
async def test_slow_resets_counter(self):
"""SLOW → counter 歸零(不算穩定"""
async def test_slow_increments_counter(self):
"""SLOW → counter +1GCP 高負載仍優於 Gemini fallback"""
svc, mock_monitor, _ = _make_service(current_primary="gemini")
svc._consecutive_healthy = 1
mock_monitor.check.return_value = _make_health(HealthStatus.SLOW)
await svc._check_and_recover()
assert svc.consecutive_healthy == 0
assert svc.consecutive_healthy == 2
@pytest.mark.asyncio
async def test_degraded_resets_counter(self):