forked from mtusi2026/mtusi2026lab7
fix: close cheap known issues before final measurements
- reject inf/nan in every float setting; service.version 1.7.0 - close API storage clients within one 0.5 s window on shutdown - SeaweedFS admin identity via -s3.config, no access key id in log - RabbitMQ CLI distribution listener on loopback only - fix timing-dependent checks: test_issue_not_after, test_hung_worker_lease_fencing, reconcile-cycle, reconcile-signal User decision 2026-12-02: fix the cheap known issues; two scenarios added to main specs directly, without an OpenSpec change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -4,12 +4,14 @@
|
||||
`Settings` только из аргументов: настоящий читает `.env` и `config.toml`.
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import re
|
||||
import socket
|
||||
import time
|
||||
from typing import Any
|
||||
|
||||
import pytest
|
||||
from pydantic import ValidationError
|
||||
from pydantic import BaseModel, ValidationError
|
||||
from pydantic_settings import (
|
||||
BaseSettings,
|
||||
PydanticBaseSettingsSource,
|
||||
@@ -30,6 +32,7 @@ from src.config.settings import (
|
||||
)
|
||||
from src.schemas.enums import MetricBucketsEnum
|
||||
from src.utils.constants import (
|
||||
API_CLOSE_TIMEOUT_SECONDS,
|
||||
API_STOP_BUDGET_SECONDS,
|
||||
CONTAINER_STOP_TIMEOUT_SECONDS,
|
||||
HTTP_DURATION_BUCKETS,
|
||||
@@ -80,6 +83,43 @@ def test_wrong_value_names_field(field: str, value: object) -> None:
|
||||
assert [error["loc"] for error in caught.value.errors()] == [(field,)]
|
||||
|
||||
|
||||
def _float_fields() -> list[tuple[type[BaseModel], str]]:
|
||||
"""Поля `float` всех секций `Settings`."""
|
||||
return [
|
||||
(section, name)
|
||||
for holder in Settings.model_fields.values()
|
||||
if isinstance(section := holder.annotation, type)
|
||||
and issubclass(section, BaseModel)
|
||||
for name, field in section.model_fields.items()
|
||||
if field.annotation is float
|
||||
]
|
||||
|
||||
|
||||
def test_float_fields_found() -> None:
|
||||
names = {(section.__name__, name) for section, name in _float_fields()}
|
||||
assert ("Database", "request_timeout_seconds") in names
|
||||
assert ("Reconciler", "interval_seconds") in names
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("section", "field"),
|
||||
_float_fields(),
|
||||
ids=lambda item: getattr(item, "__name__", item),
|
||||
)
|
||||
@pytest.mark.parametrize("value", [float("inf"), "inf", "-inf", "nan"])
|
||||
def test_float_rejects_inf_and_nan(
|
||||
section: type[BaseModel],
|
||||
field: str,
|
||||
value: object,
|
||||
) -> None:
|
||||
"""Срок без конца — ошибка с именем поля, а не `Infinity` в записи
|
||||
старта (спек `service-configuration`, «Некорректное значение
|
||||
останавливает запуск»)."""
|
||||
with pytest.raises(ValidationError) as caught:
|
||||
section(**{field: value})
|
||||
assert (field,) in [error["loc"] for error in caught.value.errors()]
|
||||
|
||||
|
||||
def test_zero_turns_backlog_limit_off() -> None:
|
||||
assert Uploads(max_unfinished_jobs=0).max_unfinished_jobs == 0
|
||||
assert Uploads().max_unfinished_jobs == 250
|
||||
@@ -154,6 +194,36 @@ def test_budgets_fit_container_stop() -> None:
|
||||
Worker(graceful_shutdown_seconds=8.01)
|
||||
worker_worst = 8 + 3 * worker_main._CLOSE_TIMEOUT_SECONDS
|
||||
assert worker_worst < CONTAINER_STOP_TIMEOUT_SECONDS
|
||||
api_worst = (
|
||||
8 + API_CLOSE_TIMEOUT_SECONDS + TELEMETRY_SHUTDOWN_TIMEOUT_SECONDS
|
||||
)
|
||||
assert api_worst < CONTAINER_STOP_TIMEOUT_SECONDS
|
||||
|
||||
|
||||
def test_api_closes_clients_within_one_window() -> None:
|
||||
"""Спек `graceful-shutdown`, «docker stop при замороженном PostgreSQL»:
|
||||
закрытие, которое не кончается (простаивающее соединение замороженного
|
||||
сервера), не держит остановку дольше окна; остальные клиенты закрыты."""
|
||||
from src.main import close_clients
|
||||
|
||||
closed: list[str] = []
|
||||
|
||||
async def hangs() -> None:
|
||||
await asyncio.sleep(3600)
|
||||
|
||||
async def closes(name: str) -> None:
|
||||
closed.append(name)
|
||||
|
||||
async def run() -> tuple[bool, float]:
|
||||
began = time.monotonic()
|
||||
done = await close_clients(hangs(), closes("cache"), closes("s3"))
|
||||
return done, time.monotonic() - began
|
||||
|
||||
done, took = asyncio.run(run())
|
||||
assert done is False
|
||||
assert API_CLOSE_TIMEOUT_SECONDS <= took < API_CLOSE_TIMEOUT_SECONDS + 0.5
|
||||
assert closed == ["cache", "s3"]
|
||||
assert asyncio.run(close_clients(closes("engine"))) is True
|
||||
|
||||
|
||||
# выбор трасс в голове и набор границ (design change `track1-telemetry-cost`,
|
||||
|
||||
Reference in New Issue
Block a user