Лабораторная 6: наблюдаемость мессенджера

This commit is contained in:
2026-11-21 11:32:12 +03:00
parent 470d9d6f1e
commit 59a3f96a82
94 changed files with 6746 additions and 35 deletions
+24
View File
@@ -0,0 +1,24 @@
"""Regression: HTTP histogram includes response transmission."""
from email.message import Message
import logging
from types import SimpleNamespace
import time
from unittest.mock import Mock, patch
from messenger.server import ApiHandler
from messenger import telemetry
handler = object.__new__(ApiHandler)
handler.command = 'GET'
handler.path = '/api/v1/users/me'
handler.headers = Message()
handler.client_address = ('127.0.0.1', 1)
handler.server = SimpleNamespace(
shutting_down=False, config=SimpleNamespace(), logger=logging.getLogger('test'),
api=SimpleNamespace(dispatch=lambda _: (200, {})), enter=Mock(), leave=Mock())
handler._read_body = lambda: b''
handler._send = lambda *_: time.sleep(.08)
with patch.object(telemetry.http_duration, 'record') as record:
handler._handle_request()
assert record.call_args.args[0] >= .075, 'histogram omits response transmission'
handler.server.leave.assert_called_once()
print('PASS: HTTP histogram includes response transmission')