Fix CI integration tests.

This commit is contained in:
febux 2026-09-06 21:23:42 +03:00
parent 5aff6e569e
commit 07b1994c32
3 changed files with 23 additions and 5 deletions

View file

@ -167,6 +167,11 @@ def _set_env() -> None:
# `timeout` event). Keep it short so streaming tests finish fast. # `timeout` event). Keep it short so streaming tests finish fast.
"SSE_POLL_INTERVAL_SECONDS": "0.25", "SSE_POLL_INTERVAL_SECONDS": "0.25",
"SSE_MAX_STREAM_SECONDS": "5", "SSE_MAX_STREAM_SECONDS": "5",
# CI has no .env, so the Settings default (true) would route
# ExtractHandler to prescreen.q instead of analyze.q. The prescreen
# stage is exercised directly in test_prescreen_worker.py; the
# extract-handler tests assert the analyze.q path.
"PRESCREEN_ENABLED": "false",
} }
for k, v in env_vars.items(): for k, v in env_vars.items():
os.environ[k] = v os.environ[k] = v

View file

@ -8,7 +8,7 @@ from __future__ import annotations
import hashlib import hashlib
import hmac import hmac
import time import time
from urllib.parse import urlencode from urllib.parse import urlencode, urlsplit, urlunsplit
import httpx import httpx
import pytest import pytest
@ -181,7 +181,12 @@ async def _strict_rate_limit_client() -> httpx.AsyncClient:
from contract_check.api.app import create_app from contract_check.api.app import create_app
from contract_check.core.config import get_settings from contract_check.core.config import get_settings
isolated_redis_url = "redis://localhost:17379/15" # Reuse the infra Redis (set by conftest `_set_env`, test-stack port);
# fall back to the dev-stack port for standalone local runs. DB 15 is
# isolated so concurrent/sequential tests do not share buckets.
base_url = os.environ.get("REDIS_URL", "redis://localhost:27379/0")
parts = urlsplit(base_url)
isolated_redis_url = urlunsplit((parts.scheme, parts.netloc, "/15", "", ""))
r = redis.from_url(isolated_redis_url) r = redis.from_url(isolated_redis_url)
await r.flushdb() await r.flushdb()
await r.aclose() await r.aclose()

View file

@ -74,8 +74,13 @@ class FakeProvider(PaymentProvider):
async def factory(): async def factory():
import os import os
os.environ["DATABASE_URL"] = ( # Integration conftest (_set_env) already points DATABASE_URL at the test
"postgresql+asyncpg://contract_check:contract_check@localhost:15432/contract_check" # infra (:25432); only fall back to the dev port when it is unset, and
# restore the previous value afterwards.
prev_url = os.environ.get("DATABASE_URL")
os.environ.setdefault(
"DATABASE_URL",
"postgresql+asyncpg://contract_check:contract_check@localhost:15432/contract_check",
) )
os.environ["PLANS_ENABLED"] = "true" os.environ["PLANS_ENABLED"] = "true"
os.environ["YOOKASSA_ENABLED"] = "true" os.environ["YOOKASSA_ENABLED"] = "true"
@ -85,7 +90,10 @@ async def factory():
get_settings.cache_clear() get_settings.cache_clear()
f = create_session_factory() f = create_session_factory()
yield f yield f
if prev_url is None:
os.environ.pop("DATABASE_URL", None) os.environ.pop("DATABASE_URL", None)
else:
os.environ["DATABASE_URL"] = prev_url
os.environ.pop("PLANS_ENABLED", None) os.environ.pop("PLANS_ENABLED", None)
os.environ.pop("YOOKASSA_ENABLED", None) os.environ.pop("YOOKASSA_ENABLED", None)
os.environ.pop("YOOKASSA_SHOP_ID", None) os.environ.pop("YOOKASSA_SHOP_ID", None)