feat: serialize official record imports
CI / backend-and-migrations (push) Canceled after 0s
CI / astro-build (push) Canceled after 0s
CI / compose-e2e (push) Canceled after 0s

This commit is contained in:
ik
2026-09-07 07:54:07 +07:00
parent 687b4c9cb5
commit c45b4511b7
9 changed files with 115 additions and 13 deletions
@@ -0,0 +1,27 @@
import os
import pytest
from sqlalchemy import create_engine
from sqlalchemy.orm import Session
from app.importer import ImportAlreadyRunning, _official_import_lock
@pytest.mark.skipif(not os.environ.get("DATABASE_URL", "").startswith("postgresql"), reason="requires PostgreSQL")
def test_postgresql_import_lock_blocks_only_same_source_category() -> None:
engine = create_engine(os.environ["DATABASE_URL"])
first = Session(engine)
second = Session(engine)
try:
with _official_import_lock(first, url="https://example.test/records", region="RU", category="records"):
with pytest.raises(ImportAlreadyRunning):
with _official_import_lock(second, url="https://example.test/records", region="RU", category="records"):
pass
with _official_import_lock(second, url="https://example.test/records", region="RU", category="weekly"):
pass
with _official_import_lock(second, url="https://example.test/records", region="RU", category="records"):
pass
finally:
first.close()
second.close()
engine.dispose()