Skip to content

Commit 5ad8713

Browse files
committed
switch back to QuerySessionPool
1 parent dffffb9 commit 5ad8713

File tree

9 files changed

+22
-15
lines changed

9 files changed

+22
-15
lines changed

.github/workflows/run-tests.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,13 @@ jobs:
1313
steps:
1414
- name: Checkout code
1515
uses: actions/checkout@v4
16+
- name: Set up Python
17+
uses: actions/setup-python@v4
18+
with:
19+
python-version: '3.11'
20+
- name: Install dependencies
21+
run: |
22+
python -m pip install --upgrade pip
23+
pip install -r requirements-dev.txt
1624
- name: Run tests
1725
run: make test

pytest.ini

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ testpaths = tests
33
python_files = test_*.py
44
python_classes = Test*
55
python_functions = test_*
6-
addopts = --cov=ydb_mcp --cov-report=term-missing --cov-report=xml --cov-report=html --no-cov-on-fail
76

87
markers =
98
unit: mark a test as a unit test
@@ -26,4 +25,6 @@ filterwarnings =
2625
ignore::RuntimeWarning:ydb_mcp.patches:
2726
ignore:Task was destroyed but it is pending:RuntimeWarning:asyncio.base_events
2827
ignore:Error handling discovery task:RuntimeWarning:tests.integration.conftest
29-
ignore:Error stopping driver:RuntimeWarning:tests.integration.conftest
28+
ignore:Error stopping driver:RuntimeWarning:tests.integration.conftest
29+
30+
addopts = --cov=ydb_mcp --cov-report=term-missing --cov-report=xml --cov-report=html --no-cov-on-fail

tests/integration/conftest.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@
4242
asyncio_logger = logging.getLogger("asyncio")
4343
asyncio_logger.setLevel(logging.ERROR)
4444

45-
# Use pytest-asyncio's built-in event_loop fixture
46-
pytestmark = pytest.mark.asyncio(scope="session")
47-
4845

4946
async def cleanup_pending_tasks():
5047
"""Clean up any pending tasks in the current event loop."""

tests/integration/test_authentication_integration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
logger = logging.getLogger(__name__)
2727

2828
# Use loop_scope instead of scope for the asyncio marker
29-
pytestmark = [pytest.mark.integration, pytest.mark.asyncio(loop_scope="session")]
29+
pytestmark = [pytest.mark.integration, pytest.mark.asyncio]
3030

3131

3232
async def test_login_password_authentication(mcp_server):

tests/integration/test_directory_operations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
logger = logging.getLogger(__name__)
2323

2424
# Mark these tests as integration and asyncio tests
25-
pytestmark = [pytest.mark.integration, pytest.mark.asyncio(scope="session")]
25+
pytestmark = [pytest.mark.integration, pytest.mark.asyncio]
2626

2727

2828
def parse_text_content(response):

tests/integration/test_mcp_server_integration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
logger = logging.getLogger(__name__)
3131

3232
# Use loop_scope instead of scope for the asyncio marker
33-
pytestmark = [pytest.mark.integration, pytest.mark.asyncio(loop_scope="session")]
33+
pytestmark = [pytest.mark.integration, pytest.mark.asyncio]
3434

3535

3636
async def test_simple_query(mcp_server):

tests/integration/test_table_operations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
logger = logging.getLogger(__name__)
1818

1919
# Mark these tests as integration and asyncio tests
20-
pytestmark = [pytest.mark.integration, pytest.mark.asyncio(loop_scope="session")]
20+
pytestmark = [pytest.mark.integration, pytest.mark.asyncio]
2121

2222
# We'll use the root directory which should already exist
2323
ROOT_DIR = "/"

tests/test_connection.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ async def test_connect(self, mock_driver_class):
5050
)
5151
mock_driver_class.return_value = mock_driver
5252

53-
with patch("ydb.SessionPool") as mock_session_pool_class:
53+
with patch("ydb.aio.QuerySessionPool") as mock_session_pool_class:
5454
# Setup session pool mock
5555
mock_session_pool = MagicMock()
5656
mock_session_pool_class.return_value = mock_session_pool
@@ -89,7 +89,7 @@ async def test_connect_with_database_in_endpoint(self, mock_driver_class):
8989
)
9090
mock_driver_class.return_value = mock_driver
9191

92-
with patch("ydb.SessionPool") as mock_session_pool_class:
92+
with patch("ydb.aio.QuerySessionPool") as mock_session_pool_class:
9393
# Setup session pool mock
9494
mock_session_pool = MagicMock()
9595
mock_session_pool_class.return_value = mock_session_pool
@@ -130,7 +130,7 @@ async def test_connect_with_explicit_database(self, mock_driver_class):
130130
)
131131
mock_driver_class.return_value = mock_driver
132132

133-
with patch("ydb.SessionPool") as mock_session_pool_class:
133+
with patch("ydb.aio.QuerySessionPool") as mock_session_pool_class:
134134
# Setup session pool mock
135135
mock_session_pool = MagicMock()
136136
mock_session_pool_class.return_value = mock_session_pool

ydb_mcp/connection.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from urllib.parse import urlparse
66

77
import ydb
8+
from ydb.aio import QuerySessionPool
89

910
logger = logging.getLogger(__name__)
1011

@@ -21,7 +22,7 @@ def __init__(self, connection_string: str, database: str = None):
2122
"""
2223
self.connection_string = connection_string
2324
self.driver: Optional[ydb.Driver] = None
24-
self.session_pool: Optional[ydb.SessionPool] = None
25+
self.session_pool: Optional[ydb.aio.QuerySessionPool] = None
2526
self._database = database
2627
self.last_error = None
2728

@@ -68,7 +69,7 @@ def _parse_endpoint_and_database(self) -> Tuple[str, str]:
6869

6970
return endpoint, database
7071

71-
async def connect(self) -> Tuple[ydb.Driver, ydb.SessionPool]:
72+
async def connect(self) -> Tuple[ydb.Driver, ydb.aio.QuerySessionPool]:
7273
"""Connect to YDB and setup session pool asynchronously.
7374
7475
Returns:
@@ -104,7 +105,7 @@ async def connect(self) -> Tuple[ydb.Driver, ydb.SessionPool]:
104105
logger.info("Connected to YDB successfully")
105106

106107
# Create session pool
107-
self.session_pool = ydb.SessionPool(self.driver)
108+
self.session_pool = ydb.aio.QuerySessionPool(self.driver)
108109

109110
return self.driver, self.session_pool
110111

0 commit comments

Comments
 (0)