Files
langchain/libs/partners/mistralai/tests/integration_tests/_rate_limiter.py
Mason Daugherty 4d2efcd756 test(mistralai): stabilize integration tests with rate limiting and retries (#37588)
Mistral integration tests have been flaky against the live API. This
adds a shared, xdist-aware rate limiter and a global retry policy so
transient 429s no longer fail the suite.
2026-05-20 19:49:25 -05:00

19 lines
507 B
Python

"""Shared rate limiter for Mistral integration tests.
Scaled by ``PYTEST_XDIST_WORKER_COUNT`` so aggregate QPS across all xdist
workers stays bounded near the target rate.
"""
from __future__ import annotations
import os
from langchain_core.rate_limiters import InMemoryRateLimiter
_TARGET_REQUESTS_PER_SECOND = 0.5
_WORKER_COUNT = max(1, int(os.environ.get("PYTEST_XDIST_WORKER_COUNT", "1")))
rate_limiter = InMemoryRateLimiter(
requests_per_second=_TARGET_REQUESTS_PER_SECOND / _WORKER_COUNT,
)