Skip to content

Commit 1fac5bd

Browse files
committed
raise exception if aquire session from stopped pool
1 parent 72dfff9 commit 1fac5bd

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

tests/aio/test_table.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import pytest
2+
import ydb.aio
3+
4+
5+
@pytest.mark.asyncio
6+
class TestSessionPool:
7+
async def test_checkout_from_stopped_pool(self, driver):
8+
pool = ydb.aio.SessionPool(driver, 1)
9+
await pool.stop()
10+
11+
with pytest.raises(ValueError):
12+
await pool.acquire()

tests/table/table_test.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
1+
import pytest
12
import ydb
23

34

5+
class TestSessionPool:
6+
def test_checkout_from_stopped_pool(self, driver_sync):
7+
pool = ydb.SessionPool(driver_sync, 1)
8+
pool.stop()
9+
10+
with pytest.raises(ValueError):
11+
pool.acquire()
12+
13+
414
class TestTable:
515
def test_create_table_with_not_null_primary_key_by_api(self, driver_sync, database):
616
table_path = database + "/test_table"

ydb/_sp_impl.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,10 @@ def _on_keep_alive(self, session, f):
335335
self._destroy(session, "keep-alive-error")
336336

337337
def acquire(self, blocking=True, timeout=None):
338+
if self._should_stop.is_set():
339+
self._logger.debug("Acquired not inited session")
340+
raise ValueError("Take session from closed session pool.")
341+
338342
waiter = self.subscribe()
339343
has_result = False
340344
if blocking:

ydb/aio/table.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ async def acquire(self, timeout: float = None, retry_timeout: float = None, retr
342342

343343
if self._should_stop.is_set():
344344
self._logger.debug("Acquired not inited session")
345-
return self._create()
345+
raise ValueError("Take session from closed session pool.")
346346

347347
if retry_timeout is None:
348348
retry_timeout = timeout

0 commit comments

Comments
 (0)