forked from mtusi2026/mtusi2026lab4
lab4 трек 2: reconciler S3/PostgreSQL, тесты вложений, отказов и согласованности
- python -m messenger.reconcile: merge-join листинга S3 и attachments по object_key; dry-run read-only конструктивно (default_transaction_read_only + S3 без записи), --apply: orphan/stale intent удаляются, ready-строки только в карантин (обратимо), перепроверка под FOR UPDATE, предохранитель от массового удаления; - attachment_ids хранится в строке сообщения (история остаётся одним index range scan), message_attachments — для FK и обратного поиска; - семафор полной проверки изображений (IMAGE_VERIFY_CONCURRENCY); - тесты: вложения (56), отказ/пауза S3 и деградированный режим LB, failover загрузки, приватность bucket, FAULT_POINTS после PUT/после COMMIT, janitor, reconciler; - бенчмарки памяти загрузок и стоимости обхода reconciler. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
335df4b2b2
commit
a2d867bec6
@@ -114,6 +114,29 @@ def test_argon2id_hash_and_verify():
|
||||
|
||||
|
||||
# ------------------------------------------------------------------ config
|
||||
@pytest.fixture(autouse=True)
|
||||
def s3_credentials(monkeypatch):
|
||||
"""Lab 4: Settings require the API's S3 key pair; synthetic values for the unit tests."""
|
||||
monkeypatch.setenv("S3_ACCESS_KEY_ID", "AKTEST")
|
||||
monkeypatch.setenv("S3_SECRET_ACCESS_KEY", "secret-for-unit-tests")
|
||||
|
||||
|
||||
def test_s3_settings_are_validated_and_contract_limits_cannot_be_raised(monkeypatch):
|
||||
monkeypatch.setenv("DATABASE_URL", "postgresql://x@y/z")
|
||||
settings = Settings.from_env()
|
||||
assert (settings.max_upload_bytes, settings.max_image_pixels) == (10 * 1024 * 1024, 40_000_000)
|
||||
assert settings.fault_points == frozenset() and settings.upload_concurrency == 4
|
||||
for name, value in (("MAX_UPLOAD_BYTES", "10485761"), ("MAX_IMAGE_PIXELS", "40000001"),
|
||||
("FAULT_POINTS", "drop_database"), ("S3_ENDPOINT", "ftp://s3"), ("S3_BUCKET", "Bad_Bucket")):
|
||||
monkeypatch.setenv(name, value)
|
||||
with pytest.raises(ConfigError):
|
||||
Settings.from_env()
|
||||
monkeypatch.delenv(name)
|
||||
monkeypatch.delenv("S3_SECRET_ACCESS_KEY")
|
||||
with pytest.raises(ConfigError):
|
||||
Settings.from_env()
|
||||
|
||||
|
||||
def test_settings_read_secret_files_and_contract_names(tmp_path, monkeypatch):
|
||||
url_file = tmp_path / "database_url"
|
||||
url_file.write_text("postgresql://u:p@db/x\n", encoding="utf-8")
|
||||
|
||||
Reference in New Issue
Block a user