haiku.rag/tests/ingester/conftest.py
Yiorgis Gozadinos 44089e5b1f
Support a dburi for the ingester queue (SQLite + Postgres)
Migrate the ingester queue storage from raw aiosqlite to SQLAlchemy Core
async. The backend is chosen by ingester.queue.dburi: a SQLAlchemy async
URL points the queue at a database server, and SQLite remains the default
when unset. The Postgres path claims jobs with FOR UPDATE SKIP LOCKED so
multiple ingester processes can share one queue; SQLite caps the pool to a
single connection to keep the select-then-update claim atomic.
2026-06-03 14:34:09 +03:00

34 lines
902 B
Python

import aiosqlite
import pytest
from haiku.rag.config import QueueConfig
from haiku.rag.ingester.queue.migrations import open_queue
from haiku.rag.ingester.queue.repository import JobRepo, SyncStateRepo
@pytest.fixture
async def engine(tmp_path):
eng = await open_queue(QueueConfig(path=tmp_path / "queue.db"))
yield eng
await eng.dispose()
@pytest.fixture
async def conn(tmp_path, engine):
"""Raw connection to the queue file for test-only SQL inspection and
backdating. Shares the WAL database the engine writes through."""
connection = await aiosqlite.connect(str(tmp_path / "queue.db"))
connection.row_factory = aiosqlite.Row
await connection.execute("PRAGMA busy_timeout=30000")
yield connection
await connection.close()
@pytest.fixture
def jobs(engine):
return JobRepo(engine)
@pytest.fixture
def sync(engine):
return SyncStateRepo(engine)