Files
mtusi2026lab6/service-tests/unit/conftest.py
T
ricoromaandClaude Opus 5.5 509afca89e feat: telemetry cost profile with head sampling, coarse buckets and balanced tail sampling
- [telemetry] trace_sample_ratio (ParentBased(TraceIdRatioBased), 1 keeps
  ParentBased(ALWAYS_ON)) and metric_buckets (default|coarse with SLO bounds),
  export interval <= 30 s; otel.sdk.span.started, span.live dropped; startup
  records name ratio, buckets and interval
- bench: telemetry services on mtusi-bench, TELEMETRY=on switch for uploads
  and queue, make bench_telemetry[_quick] with off/full/full-aa/head/tail/
  metrics/balanced, rare events, lookup from Tempo/Loki/Prometheus, cost
  sampler, verdicts H1-H8 and B1-B5; collector layers and lean Prometheus in
  bench/otel with preflight checks
- REPORT: telemetry cost hypotheses and criteria before the label

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 19:17:25 +03:00

85 lines
2.4 KiB
Python

"""Быстрые тесты сервисов: без PostgreSQL, Valkey, S3, брокера, docker и сети.
`settings` читает `.env` и `config.toml` по абсолютному пути, поэтому поля, от
которых зависят ветки сервисов, подставляются здесь: результат не зависит от
локальных файлов и окружения (design change `unit-of-work`, решение 13).
"""
import pytest
from fakes import (
FakeCache,
FakeDatabase,
FakeJobPublisher,
FakeObjectStorage,
FakeUnitOfWork,
)
from src.config import settings
from src.schemas.enums import MetricBucketsEnum
@pytest.fixture
def anyio_backend() -> str:
return "asyncio"
@pytest.fixture(autouse=True)
def fixed_settings(monkeypatch: pytest.MonkeyPatch) -> None:
fixed = (
(
settings.worker,
{
"max_attempts": 3,
"job_timeout_seconds": 60,
"lease_margin_seconds": 10,
"retry_base_delay_seconds": 5,
"retry_max_delay_seconds": 300,
"reconnect_seconds": 0.01,
},
),
(settings.auth, {"session_ttl_seconds": 3600}),
(settings.idempotency, {"ttl_seconds": 86400}),
(settings.cache, {"chat_ttl_seconds": 600}),
(
settings.uploads,
{"body_timeout_seconds": 1, "max_unfinished_jobs": 0},
),
(settings.app, {"instance_id": "test-instance"}),
(
settings.telemetry,
{
"trace_sample_ratio": 1.0,
"metric_buckets": MetricBucketsEnum.DEFAULT,
"metric_export_interval_seconds": 15,
},
),
)
for section, fields in fixed:
for name, value in fields.items():
monkeypatch.setattr(section, name, value)
@pytest.fixture
def database() -> FakeDatabase:
return FakeDatabase()
@pytest.fixture
def uow(database: FakeDatabase) -> FakeUnitOfWork:
return FakeUnitOfWork(database)
@pytest.fixture
def cache(database: FakeDatabase) -> FakeCache:
return FakeCache(database)
@pytest.fixture
def storage(database: FakeDatabase) -> FakeObjectStorage:
return FakeObjectStorage(database)
@pytest.fixture
def publisher(database: FakeDatabase) -> FakeJobPublisher:
return FakeJobPublisher(database)