1
1
import asyncio
2
2
import pytest
3
3
import ydb
4
- from ydb .aio .query .pool import QuerySessionPoolAsync
5
- from ydb .aio .query .session import QuerySessionAsync , QuerySessionStateEnum
4
+ from ydb .aio .query .pool import QuerySessionPool
5
+ from ydb .aio .query .session import QuerySession , QuerySessionStateEnum
6
6
7
7
8
- class TestQuerySessionPoolAsync :
8
+ class TestQuerySessionPool :
9
9
@pytest .mark .asyncio
10
- async def test_checkout_provides_created_session (self , pool : QuerySessionPoolAsync ):
10
+ async def test_checkout_provides_created_session (self , pool : QuerySessionPool ):
11
11
async with pool .checkout () as session :
12
12
assert session ._state ._state == QuerySessionStateEnum .CREATED
13
13
14
14
@pytest .mark .asyncio
15
- async def test_oneshot_query_normal (self , pool : QuerySessionPoolAsync ):
15
+ async def test_oneshot_query_normal (self , pool : QuerySessionPool ):
16
16
res = await pool .execute_with_retries ("select 1;" )
17
17
assert len (res ) == 1
18
18
19
19
@pytest .mark .asyncio
20
- async def test_oneshot_ddl_query (self , pool : QuerySessionPoolAsync ):
20
+ async def test_oneshot_ddl_query (self , pool : QuerySessionPool ):
21
21
await pool .execute_with_retries ("drop table if exists Queen;" )
22
22
await pool .execute_with_retries ("create table Queen(key UInt64, PRIMARY KEY (key));" )
23
23
await pool .execute_with_retries ("drop table Queen;" )
24
24
25
25
@pytest .mark .asyncio
26
- async def test_oneshot_query_raises (self , pool : QuerySessionPoolAsync ):
26
+ async def test_oneshot_query_raises (self , pool : QuerySessionPool ):
27
27
with pytest .raises (ydb .GenericError ):
28
28
await pool .execute_with_retries ("Is this the real life? Is this just fantasy?" )
29
29
30
30
@pytest .mark .asyncio
31
- async def test_retry_op_uses_created_session (self , pool : QuerySessionPoolAsync ):
32
- async def callee (session : QuerySessionAsync ):
31
+ async def test_retry_op_uses_created_session (self , pool : QuerySessionPool ):
32
+ async def callee (session : QuerySession ):
33
33
assert session ._state ._state == QuerySessionStateEnum .CREATED
34
34
35
35
await pool .retry_operation_async (callee )
36
36
37
37
@pytest .mark .asyncio
38
- async def test_retry_op_normal (self , pool : QuerySessionPoolAsync ):
39
- async def callee (session : QuerySessionAsync ):
38
+ async def test_retry_op_normal (self , pool : QuerySessionPool ):
39
+ async def callee (session : QuerySession ):
40
40
async with session .transaction () as tx :
41
41
iterator = await tx .execute ("select 1;" , commit_tx = True )
42
42
return [result_set async for result_set in iterator ]
@@ -45,18 +45,18 @@ async def callee(session: QuerySessionAsync):
45
45
assert len (res ) == 1
46
46
47
47
@pytest .mark .asyncio
48
- async def test_retry_op_raises (self , pool : QuerySessionPoolAsync ):
48
+ async def test_retry_op_raises (self , pool : QuerySessionPool ):
49
49
class CustomException (Exception ):
50
50
pass
51
51
52
- async def callee (session : QuerySessionAsync ):
52
+ async def callee (session : QuerySession ):
53
53
raise CustomException ()
54
54
55
55
with pytest .raises (CustomException ):
56
56
await pool .retry_operation_async (callee )
57
57
58
58
@pytest .mark .asyncio
59
- async def test_pool_size_limit_logic (self , pool : QuerySessionPoolAsync ):
59
+ async def test_pool_size_limit_logic (self , pool : QuerySessionPool ):
60
60
target_size = 5
61
61
pool ._size = target_size
62
62
ids = set ()
@@ -78,7 +78,7 @@ async def test_pool_size_limit_logic(self, pool: QuerySessionPoolAsync):
78
78
assert pool ._current_size == target_size
79
79
80
80
@pytest .mark .asyncio
81
- async def test_checkout_do_not_increase_size (self , pool : QuerySessionPoolAsync ):
81
+ async def test_checkout_do_not_increase_size (self , pool : QuerySessionPool ):
82
82
session_id = None
83
83
for _ in range (10 ):
84
84
async with pool .checkout () as session :
@@ -88,7 +88,7 @@ async def test_checkout_do_not_increase_size(self, pool: QuerySessionPoolAsync):
88
88
assert session_id == session ._state .session_id
89
89
90
90
@pytest .mark .asyncio
91
- async def test_pool_recreates_bad_sessions (self , pool : QuerySessionPoolAsync ):
91
+ async def test_pool_recreates_bad_sessions (self , pool : QuerySessionPool ):
92
92
async with pool .checkout () as session :
93
93
session_id = session ._state .session_id
94
94
await session .delete ()
@@ -98,20 +98,20 @@ async def test_pool_recreates_bad_sessions(self, pool: QuerySessionPoolAsync):
98
98
assert pool ._current_size == 1
99
99
100
100
@pytest .mark .asyncio
101
- async def test_acquire_from_closed_pool_raises (self , pool : QuerySessionPoolAsync ):
101
+ async def test_acquire_from_closed_pool_raises (self , pool : QuerySessionPool ):
102
102
await pool .stop ()
103
103
with pytest .raises (RuntimeError ):
104
104
await pool .acquire ()
105
105
106
106
@pytest .mark .asyncio
107
- async def test_acquire_with_timeout_from_closed_pool_raises (self , pool : QuerySessionPoolAsync ):
107
+ async def test_acquire_with_timeout_from_closed_pool_raises (self , pool : QuerySessionPool ):
108
108
await pool .stop ()
109
109
with pytest .raises (RuntimeError ):
110
110
await asyncio .wait_for (pool .acquire (), timeout = 0.1 )
111
111
112
112
@pytest .mark .asyncio
113
113
async def test_no_session_leak (self , driver , docker_project ):
114
- pool = ydb .aio .QuerySessionPoolAsync (driver , 1 )
114
+ pool = ydb .aio .QuerySessionPool (driver , 1 )
115
115
docker_project .stop ()
116
116
try :
117
117
await asyncio .wait_for (pool .acquire (), timeout = 0.1 )
0 commit comments