Skip to content

Commit 0ba6a00

Browse files
committed
Update
1 parent 16e649c commit 0ba6a00

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

cx_Oracle_async/pools.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from .context import AbstractContextManager as BaseManager
22
from .connections import AsyncConnectionWrapper , AsyncConnectionWrapper_context
33
from ThreadPoolExecutorPlus import ThreadPoolExecutor
4-
from cx_Oracle import SessionPool
4+
from cx_Oracle import Connection , SessionPool
55
from types import CoroutineType
66
import asyncio
77
import platform
@@ -52,6 +52,12 @@ def _acquire(self):
5252
def _unoccupied(self , obj):
5353
self._occupied.remove(obj)
5454

55+
async def release(self , conn: Connection):
56+
return await self._loop.run_in_executor(self._thread_pool , self._pool.release , conn)
57+
58+
async def drop(self , conn: Connection):
59+
return await self._loop.run_in_executor(self._thread_pool , self._pool.drop , conn)
60+
5561
async def close(self , force = False):
5662
if force:
5763
while self._occupied:

tests/test_drop.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import os , sys
2+
sys.path.append(os.getcwd())
3+
import pytest
4+
import asyncio
5+
import time
6+
from cx_Oracle_async import *
7+
import cx_Oracle
8+
9+
async def create_long_query(oracle_pool):
10+
async with oracle_pool.acquire() as conn:
11+
cursor = await conn.cursor()
12+
try:
13+
await cursor.execute("BEGIN DBMS_LOCK.SLEEP(:a); END;",(20,))
14+
except Exception as e:
15+
assert isinstance(e , cx_Oracle.OperationalError)
16+
17+
@pytest.mark.asyncio
18+
async def test_force_close():
19+
loop = asyncio.get_running_loop()
20+
dsn = makedsn('localhost','1521',sid='xe')
21+
INAQ = 0.5
22+
oracle_pool = await create_pool(user='system',password='oracle',dsn=dsn,max=4)
23+
loop = asyncio.get_running_loop()
24+
loop.create_task(create_long_query(oracle_pool))
25+
st_time = time.time()
26+
await asyncio.sleep(2)
27+
await oracle_pool.close(force = True)
28+
ed_time = time.time()
29+
assert (ed_time - st_time) <= (20 - INAQ)

0 commit comments

Comments
 (0)