Fix test in CI.

This commit is contained in:
febux 2026-08-12 23:03:48 +03:00
parent 464d895eb6
commit c77ba029a3
3 changed files with 31 additions and 5 deletions

View file

@ -60,7 +60,7 @@ jobs:
run: uv run pytest -m "not integration" run: uv run pytest -m "not integration"
test-integration: test-integration:
name: Integration tests (testcontainers) name: Integration tests
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
@ -77,5 +77,16 @@ jobs:
- name: Sync dev dependencies - name: Sync dev dependencies
run: uv sync --group dev --frozen run: uv sync --group dev --frozen
# Integration tests talk to postgres/redis/rabbitmq/minio on localhost
# (see tests/integration/conftest.py). The default compose profile starts
# only infra; the app runs in-process via create_app(). `--wait` blocks
# until every healthcheck passes before pytest runs.
- name: Start infrastructure (postgres/redis/rabbitmq/minio)
run: docker compose up -d --wait
- name: Run integration tests - name: Run integration tests
run: uv run pytest -m integration run: uv run pytest -m integration
- name: Teardown infrastructure
if: always()
run: docker compose down -v

View file

@ -5,6 +5,8 @@ Run against the Docker Compose infrastructure (`docker compose up -d`).
from __future__ import annotations from __future__ import annotations
import asyncio
import time
import uuid import uuid
from pathlib import Path from pathlib import Path
@ -105,11 +107,16 @@ async def test_b2b_analyze_upload_returns_202_and_enqueues(
queue = await channel.get_queue("extract.q", ensure=False) queue = await channel.get_queue("extract.q", ensure=False)
deadline = 10.0 deadline = 10.0
found = False found = False
import time
while deadline > 0: while deadline > 0:
start = time.monotonic() start = time.monotonic()
try:
message = await queue.get(timeout=deadline) message = await queue.get(timeout=deadline)
except aio_pika.exceptions.QueueEmpty:
# basic_get is non-blocking; the routed message may not be
# visible yet. Treat as transient and retry until the deadline.
await asyncio.sleep(0.25)
deadline -= time.monotonic() - start
continue
await message.ack() await message.ack()
msg_body = message.body.decode("utf-8") msg_body = message.body.decode("utf-8")
if str(document_id) in msg_body: if str(document_id) in msg_body:

View file

@ -12,6 +12,7 @@ Scenarios:
from __future__ import annotations from __future__ import annotations
import asyncio
import json import json
import time import time
import uuid import uuid
@ -163,7 +164,14 @@ async def test_extract_worker_pdf_uploads_text_and_publishes_analyze(
found = False found = False
while deadline > 0: while deadline > 0:
start = time.monotonic() start = time.monotonic()
try:
message = await queue.get(timeout=deadline) message = await queue.get(timeout=deadline)
except aio_pika.exceptions.QueueEmpty:
# basic_get is non-blocking; the routed message may not be
# visible yet. Treat as transient and retry until the deadline.
await asyncio.sleep(0.25)
deadline -= time.monotonic() - start
continue
await message.ack() await message.ack()
body = json.loads(message.body.decode("utf-8")) body = json.loads(message.body.decode("utf-8"))
if body["document_id"] == str(document_id): if body["document_id"] == str(document_id):