DFiP_Budget_planing/perf/tests/test_api_split.py
Andrey Epifancev d9aa47388a perf(analysis): api_split — размер ответа на проводе (wire_bytes)
Цикл замера вынесен в measure(); добавлен wire_bytes (num_bytes_downloaded,
байты после сжатия) рядом с декодированным размером. В .md - колонка
«на проводе, МБ». Docstring: актуальные места X-DB-Time-Ms и остаток после
задач A (склейка строк, gzip, передача, распаковка; без pydantic).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 21:27:08 +04:00

29 lines
1.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import gzip
import json
import sys
from pathlib import Path
import httpx
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "analysis"))
from api_split import measure # noqa: E402
def test_measure_reports_wire_and_decoded_bytes():
raw = json.dumps({"result": [{"a": 1}] * 50}).encode()
gz = gzip.compress(raw)
def handler(request):
assert request.headers["authorization"] == "Bearer tok"
# stream, а не content=: у httpx num_bytes_downloaded считается при чтении потока (как у сетевого транспорта)
return httpx.Response(200, headers={"content-encoding": "gzip", "x-db-time-ms": "12.50"}, stream=httpx.ByteStream(gz))
with httpx.Client(transport=httpx.MockTransport(handler), base_url="http://t") as c:
m = measure(c, "/x", "tok", repeats=3)
assert m["rows"] == 50
assert m["bytes"] == len(raw)
assert m["wire_bytes"] == len(gz)
assert m["db_ms"] == 12.5
assert m["content_encoding"] == "gzip"