Keep embedding retry on GCP when 111 fallback disabled
All checks were successful
CD Pipeline / deploy (push) Successful in 1m5s

This commit is contained in:
OoO
2026-05-25 09:59:00 +08:00
parent f3a199434f
commit 3fd349c830
7 changed files with 44 additions and 5 deletions

View File

@@ -378,7 +378,32 @@ def test_embedding_can_disable_111_fallback_for_background_rag_work():
posted_hosts = [call.args[0].split('/api/embed')[0] for call in mock_post.call_args_list]
assert vec == []
assert posted_hosts == [oss.OLLAMA_HOST_SECONDARY]
assert posted_hosts == [oss.OLLAMA_HOST_SECONDARY, oss.OLLAMA_HOST_PRIMARY]
assert oss.OLLAMA_HOST_FALLBACK not in posted_hosts
def test_embedding_fallback_disabled_uses_gcp_chain_when_resolver_returns_111():
"""resolver 若因 unhealthy cache 回 111背景 embedding 仍要嘗試 GCP-A/GCP-B。"""
import requests
from services import ollama_service as oss
from services.ollama_service import OllamaService
svc = OllamaService()
with patch(
'services.ollama_service.resolve_ollama_host',
side_effect=[oss.OLLAMA_HOST_FALLBACK, oss.OLLAMA_HOST_FALLBACK],
), patch.dict('os.environ', {}, clear=False), patch(
'services.ollama_service.requests.post',
side_effect=requests.Timeout('gcp timeout'),
) as mock_post:
import os
os.environ.pop('EMBEDDING_HOST', None)
vec = svc.generate_embedding('test text', allow_111_fallback=False)
posted_hosts = [call.args[0].split('/api/embed')[0] for call in mock_post.call_args_list]
assert vec == []
assert posted_hosts == [oss.OLLAMA_HOST_PRIMARY, oss.OLLAMA_HOST_SECONDARY]
assert oss.OLLAMA_HOST_FALLBACK not in posted_hosts