Skip to content

Commit 1ae557a

Browse files
authored
Merge pull request #2 from EmiM/chore/organize-tests
Reorganize vector mode tests into proper unit test structure with typ…
2 parents a390431 + 8a70523 commit 1ae557a

File tree

13 files changed

+773
-680
lines changed

13 files changed

+773
-680
lines changed

.github/workflows/unit-tests.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Unit Tests
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
pull_request:
7+
branches: [ main, develop ]
8+
9+
permissions:
10+
contents: read
11+
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.ref }}
14+
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
15+
16+
jobs:
17+
unit-tests:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v4
21+
- uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5
22+
with:
23+
python-version: '3.12'
24+
- uses: snok/install-poetry@v1
25+
with:
26+
version: latest
27+
virtualenvs-create: true
28+
virtualenvs-in-project: true
29+
virtualenvs-path: .venv
30+
installer-parallel: true
31+
- uses: actions/cache@v4
32+
with:
33+
path: .venv
34+
key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}
35+
restore-keys: |
36+
${{ runner.os }}-poetry-
37+
- run: poetry install --with dev
38+
- run: poetry run pip install pytest-xdist pytest-timeout
39+
- run: poetry run pytest tests/unit -n 32 --timeout=90 --timeout-method=thread

tests/conftest.py

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import pytest
1414
import pytest_asyncio
15+
from _pytest.fixtures import FixtureRequest
1516

1617
from mcp_code_indexer.database.database import DatabaseManager
1718
from mcp_code_indexer.database.models import FileDescription, Project
@@ -41,6 +42,26 @@ async def temp_db() -> AsyncGenerator[Path, None]:
4142
db_path.unlink()
4243

4344

45+
@pytest_asyncio.fixture
46+
async def temp_db_with_test_table(temp_db: Path) -> AsyncGenerator[Path, None]:
47+
"""Create a temporary database with a test table for retry testing."""
48+
import aiosqlite
49+
50+
# Create database with tables
51+
async with aiosqlite.connect(temp_db) as db:
52+
await db.execute(
53+
"""
54+
CREATE TABLE test_table (
55+
id INTEGER PRIMARY KEY,
56+
data TEXT NOT NULL
57+
)
58+
"""
59+
)
60+
await db.commit()
61+
62+
yield temp_db
63+
64+
4465
@pytest_asyncio.fixture
4566
async def db_manager(temp_db: Path) -> AsyncGenerator[DatabaseManager, None]:
4667
"""Create and initialize a database manager for testing."""
@@ -53,6 +74,24 @@ async def db_manager(temp_db: Path) -> AsyncGenerator[DatabaseManager, None]:
5374
await manager.close_pool()
5475

5576

77+
@pytest_asyncio.fixture
78+
async def temp_db_manager_pool(
79+
temp_db: Path, request: FixtureRequest
80+
) -> AsyncGenerator[DatabaseManager, None]:
81+
"""Create and initialize a database manager with specified pool size for testing.
82+
83+
Use with @pytest.mark.parametrize("temp_db_manager_pool", [pool_size], indirect=True)
84+
"""
85+
pool_size = request.param
86+
manager = DatabaseManager(temp_db, pool_size=pool_size)
87+
await manager.initialize()
88+
89+
yield manager
90+
91+
# Cleanup
92+
await manager.close_pool()
93+
94+
5695
@pytest_asyncio.fixture
5796
async def sample_project(db_manager: DatabaseManager) -> Project:
5897
"""Create a sample project for testing."""
@@ -293,10 +332,8 @@ async def mcp_server(tmp_path: Path):
293332

294333
# Import here to avoid circular imports
295334
from mcp_code_indexer.server.mcp_server import MCPCodeIndexServer
296-
297-
server = MCPCodeIndexServer(
298-
token_limit=1000, db_path=db_path, cache_dir=cache_dir
299-
)
335+
336+
server = MCPCodeIndexServer(token_limit=1000, db_path=db_path, cache_dir=cache_dir)
300337
await server.initialize()
301338

302339
yield server

0 commit comments

Comments
 (0)