Forward the lab 4 foundation and migrate the lab 5 pipeline to SQLAlchemy

This commit is contained in:
Artyom
2026-11-06 09:12:25 +03:00
parent ae9f60fe1f
commit 1217da5f5e
134 changed files with 8243 additions and 1409 deletions
+2 -2
View File
@@ -17,7 +17,7 @@ from dishka import Provider, Scope, make_async_container, provide
from dishka_faststream import setup_dishka
from faststream.rabbit import Channel, RabbitBroker
from conftest import ROOT, STARTUP_SECONDS, container, image, published
from conftest import ROOT, STARTUP_SECONDS, container, free_port, image, published
from fakes import NullLogger
from messenger.attachments.application.bus import AttachmentsCommandBus
from messenger.attachments.application.commands import ProcessJob
@@ -90,7 +90,7 @@ def rabbitmq() -> Iterator[dict[str, Any]]:
"100:101",
*volumes,
"-p",
"127.0.0.1::5672",
f"127.0.0.1:{free_port()}:5672",
image(RABBITMQ_IMAGE),
)
try:
+28 -3
View File
@@ -9,7 +9,7 @@ from uuid import uuid4
import httpx
import pytest
from conftest import STARTUP_SECONDS, container, image, published
from conftest import STARTUP_SECONDS, container, free_port, image, published
from messenger.attachments.application.errors import ObjectMissingError
from messenger.attachments.infrastructure.s3 import S3ObjectStorage, s3_client
from messenger.shared.application.errors import Unavailable
@@ -23,7 +23,7 @@ BUCKET = "messenger-attachments"
def rustfs() -> Iterator[str]:
name = f"mtusi-lab5-test-rustfs-{uuid4().hex[:8]}"
keys = ["-e", f"RUSTFS_ACCESS_KEY={ROOT_KEY}", "-e", f"RUSTFS_SECRET_KEY={ROOT_SECRET}"]
container(name, *keys, "-p", "127.0.0.1::9000", image(RUSTFS_IMAGE))
container(name, *keys, "-p", f"127.0.0.1:{free_port()}:9000", image(RUSTFS_IMAGE))
try:
endpoint = f"http://127.0.0.1:{published(name, 9000)}"
deadline = time.monotonic() + STARTUP_SECONDS
@@ -71,6 +71,27 @@ async def test_round_trip_of_the_largest_object(rustfs: str) -> None:
await objects.delete(key)
async def test_listing_is_paged_in_byte_order_and_stat_reads_size(rustfs: str) -> None:
prefix = f"reconcile-{uuid4().hex}/"
keys = [f"{prefix}{name}" for name in ("b", "a", "Z", "a-1", "é")]
async with storage(rustfs) as objects:
for size, key in enumerate(keys, start=1):
await objects.put(key, b"x" * size, "image/png")
pages = [page async for page in objects.listing(prefix, 2)]
assert [len(page) for page in pages] == [2, 2, 1]
listed = [item.key for page in pages for item in page]
assert listed == sorted(keys, key=str.encode)
sizes = {item.key: item.size for page in pages for item in page}
assert sizes == {key: size for size, key in enumerate(keys, start=1)}
found = await objects.stat(keys[0])
assert found is not None
assert found.size == 1
assert await objects.stat(f"{prefix}absent") is None
for key in keys:
await objects.delete(key)
assert not [item async for page in objects.listing(prefix, 2) for item in page]
async def test_unreachable_endpoint_is_unavailable_in_bounded_time() -> None:
started = time.monotonic()
async with storage_without_bucket("http://127.0.0.1:1") as objects:
@@ -78,7 +99,11 @@ async def test_unreachable_endpoint_is_unavailable_in_bounded_time() -> None:
await objects.put("attachments/x", b"x", "image/png")
with pytest.raises(Unavailable):
await objects.open("attachments/x")
assert time.monotonic() - started < 8
with pytest.raises(Unavailable):
await objects.stat("attachments/x")
with pytest.raises(Unavailable):
await anext(aiter(objects.listing("attachments/", 10)))
assert time.monotonic() - started < 12
@asynccontextmanager