mirror of
https://github.com/hwchase17/langchain.git
synced 2026-06-09 10:17:00 +00:00
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.
19 lines
507 B
Python
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,
|
|
)
|