Skip to content

Commit 2c2f69c

Browse files
committed
Update vsession settings
1 parent 437f4d2 commit 2c2f69c

File tree

2 files changed

+85
-1
lines changed

2 files changed

+85
-1
lines changed

cx_Oracle_async/connections.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,42 @@ def msgproperties(self , *args , **kwargs):
4242
def encoding(self):
4343
return self._conn.encoding
4444

45+
@property
46+
def dsn(self):
47+
return self._conn.dsn
48+
49+
@property
50+
def module(self):
51+
return self._conn.module
52+
53+
@module.setter
54+
def module(self , arg):
55+
self._conn.module = arg
56+
57+
@property
58+
def action(self):
59+
return self._conn.action
60+
61+
@action.setter
62+
def action(self , arg):
63+
self._conn.action = arg
64+
65+
@property
66+
def client_identifier(self):
67+
return self._conn.client_identifier
68+
69+
@client_identifier.setter
70+
def client_identifier(self , arg):
71+
self._conn.client_identifier = arg
72+
73+
@property
74+
def clientinfo(self):
75+
return self._conn.clientinfo
76+
77+
@clientinfo.setter
78+
def clientinfo(self , arg):
79+
self._conn.clientinfo = arg
80+
4581
async def queue(self , *args , **kwargs):
4682
return AsyncQueueWrapper(self._conn.queue(*args , **kwargs) , self._loop , self._thread_pool , self)
4783

tests/test_connection.py

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import pytest
44
import asyncio
55
from cx_Oracle_async import *
6+
import time
67

78
@pytest.mark.asyncio
89
async def test_different_connect_ways():
@@ -35,4 +36,51 @@ async def test_different_connect_ways():
3536

3637
ret = await oracle_pool.close()
3738
assert ret == None
38-
39+
40+
@pytest.mark.asyncio
41+
async def test_properties():
42+
INAQ = 0.5
43+
dsn = makedsn(
44+
host = 'localhost',
45+
port = '1521',
46+
sid = 'xe'
47+
)
48+
oracle_pool = await create_pool(
49+
user = 'system',
50+
password = 'oracle',
51+
dsn = dsn
52+
)
53+
54+
async with oracle_pool.acquire() as conn:
55+
st_time = time.time()
56+
conn.module = 'hello world'
57+
conn.action = 'test_action'
58+
conn.client_identifier = 'test_identifier'
59+
conn.clientinfo = 'test_info'
60+
ed_time = time.time()
61+
assert (ed_time - st_time) <= INAQ
62+
63+
async with conn.cursor() as cursor:
64+
await cursor.execute("SELECT SID, MODULE ,ACTION ,CLIENT_IDENTIFIER , CLIENT_INFO FROM V$SESSION WHERE MODULE='hello world'")
65+
r = await cursor.fetchall()
66+
assert len(r) == 1
67+
_ , _module , _action , _ciden , _cinfo = r[0]
68+
assert _module == 'hello world'
69+
assert _action == 'test_action'
70+
assert _ciden == 'test_identifier'
71+
assert _cinfo == 'test_info'
72+
73+
# test no update
74+
st_time = time.time()
75+
conn.module = 'hello world2'
76+
conn.action = 'test_action2'
77+
conn.client_identifier = 'test_identifier2'
78+
conn.clientinfo = 'test_info2'
79+
ed_time = time.time()
80+
assert (ed_time - st_time) <= INAQ
81+
82+
conn2 = await oracle_pool.acquire()
83+
async with conn2.cursor() as cursor:
84+
await cursor.execute("SELECT SID, MODULE ,ACTION ,CLIENT_IDENTIFIER , CLIENT_INFO FROM V$SESSION WHERE MODULE='hello world2'")
85+
r = await cursor.fetchall()
86+
assert len(r) == 0

0 commit comments

Comments
 (0)