File tree Expand file tree Collapse file tree 2 files changed +36
-1
lines changed
Expand file tree Collapse file tree 2 files changed +36
-1
lines changed Original file line number Diff line number Diff line change 11from .context import AbstractContextManager as BaseManager
22from .connections import AsyncConnectionWrapper , AsyncConnectionWrapper_context
33from ThreadPoolExecutorPlus import ThreadPoolExecutor
4- from cx_Oracle import SessionPool
4+ from cx_Oracle import Connection , SessionPool
55from types import CoroutineType
66import asyncio
77import 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 :
Original file line number Diff line number Diff line change 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 )
You can’t perform that action at this time.
0 commit comments