mirror of
https://github.com/Routstr/routstr-core.git
synced 2026-08-09 11:04:36 +00:00
Fixes three issues that caused per-mint rate-limit state to never recover: 1. _is_mint_rate_limited: remove substring matching on 'rate limit' / 'too many requests' in exception messages. Only HTTP 429 (httpx.HTTPStatusError) is now classified as a rate limit, preventing false positives (e.g. a 503 with 'database rate exceeded' in its body). 2. _run_probe: use apply_cooldown() instead of apply_rate_limit_cooldown() when a probe fails due to a rate limit. The probe is a recovery check, not a new request, so it should not escalate the exponential backoff counter (_consecutive_rate_limits). This prevents the cooldown from ratcheting 60s → 120s → 240s → ... → 7h on repeated probe failures. 3. classify_redemption_error: split the combined _is_mint_rate_limited || is_mint_connection_error check into two separate classifications: - mint_rate_limited / cashu_mint_rate_limited (503, retryable) - mint_unreachable / cashu_mint_unreachable (503, retryable) Callers (routstrd) can now distinguish temporary rate limits from permanent connection failures when deciding fallback strategy. Tests: 20 new tests covering strict 429 detection, classification priority, probe non-escalation, and cooldown reset behaviour.
FastAPI Async Unit Tests
This directory contains async unit tests for the Routstr proxy FastAPI application.
Installation
First, ensure you have the development dependencies installed:
uv pip install -e ".[dev]"
Running Tests
To run all tests:
pytest
To run tests with coverage:
pytest --cov=routstr --cov-report=html
To run specific test files:
pytest tests/test_main.py
pytest tests/test_models.py
pytest tests/test_proxy.py
To run only async tests:
pytest -m asyncio
Test Structure
conftest.py- Pytest fixtures and configurationtest_main.py- Tests for main app endpointstest_account.py- Tests for wallet/account management endpointstest_proxy.py- Tests for the proxy functionality with mocked upstreamtest_models.py- Tests for model pricing and data structures
Key Fixtures
async_client- Async HTTP client for testing FastAPI endpointstest_session- In-memory SQLite database session for teststest_api_key- Pre-configured API key with balanceapi_key_with_balance- API key with sufficient balance for proxy tests
Environment Variables
The tests automatically set up required environment variables in conftest.py. No manual configuration needed.
Writing New Tests
- Use
@pytest.mark.asynciofor async tests - Use the provided fixtures for database and client access
- Mock external dependencies (like upstream API calls)
- Test both success and error cases
- Verify database state changes when applicable