Files
wehub-resource-sync e4dcfc49aa
Tests / Import Check (Python 3.13) (push) Has been cancelled
Tests / Import Check (Python 3.14) (push) Has been cancelled
Tests / Python Tests (Python 3.11) (push) Has been cancelled
Tests / Python Tests (Python 3.12) (push) Has been cancelled
Tests / Python Tests (Python 3.14) (push) Has been cancelled
Tests / Test Summary (push) Has been cancelled
Tests / Lint and Format (push) Has been cancelled
Tests / Web Node Tests (push) Has been cancelled
Tests / Import Check (Python 3.11) (push) Has been cancelled
Tests / Import Check (Python 3.12) (push) Has been cancelled
Tests / Python Tests (Python 3.13) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:00:43 +08:00

39 lines
1.2 KiB
Python

"""Tests for BaseLLMProvider retry behavior."""
import asyncio
from deeptutor.services.llm.config import LLMConfig
from deeptutor.services.llm.exceptions import LLMRateLimitError
from deeptutor.services.llm.providers.base_provider import BaseLLMProvider
class DummyProvider(BaseLLMProvider):
"""Minimal provider used for retry tests."""
async def complete(self, prompt: str, **kwargs: object):
raise NotImplementedError
async def stream(self, prompt: str, **kwargs: object):
raise NotImplementedError
def test_execute_with_retry_succeeds_after_rate_limit() -> None:
"""execute_with_retry should retry on rate limit errors."""
config = LLMConfig(model="test", api_key="", base_url="http://localhost:1234")
provider = DummyProvider(config)
attempts = {"count": 0}
async def _call() -> str:
attempts["count"] += 1
if attempts["count"] < 3:
raise LLMRateLimitError("rate limited", provider="test")
return "ok"
async def _no_sleep(_delay: float) -> None:
return None
result = asyncio.run(provider.execute_with_retry(_call, max_retries=2, sleep=_no_sleep))
assert result == "ok"
assert attempts["count"] == 3