3030DB_SETTINGS = redis_settings ()[0 ]
3131REDIS_PY_VERSION = get_package_version_tuple ("redis" )
3232
33- # Metrics
33+ # Metrics for publish test
34+
35+ datastore_all_metric_count = 5 if REDIS_PY_VERSION >= (5 , 0 ) else 3
3436
3537_base_scoped_metrics = [("Datastore/operation/Redis/publish" , 3 )]
3638
3739if REDIS_PY_VERSION >= (5 , 0 ):
38- _base_scoped_metrics .append (( 'Datastore/operation/Redis/client_setinfo' , 2 ),)
39-
40- datastore_all_metric_count = 5 if REDIS_PY_VERSION >= ( 5 , 0 ) else 3
40+ _base_scoped_metrics .append (
41+ ( "Datastore/operation/Redis/client_setinfo" , 2 ),
42+ )
4143
4244_base_rollup_metrics = [
4345 ("Datastore/all" , datastore_all_metric_count ),
4446 ("Datastore/allOther" , datastore_all_metric_count ),
4547 ("Datastore/Redis/all" , datastore_all_metric_count ),
4648 ("Datastore/Redis/allOther" , datastore_all_metric_count ),
4749 ("Datastore/operation/Redis/publish" , 3 ),
48- ("Datastore/instance/Redis/%s/%s" % (instance_hostname (DB_SETTINGS ["host" ]), DB_SETTINGS ["port" ]), datastore_all_metric_count ),
50+ (
51+ "Datastore/instance/Redis/%s/%s" % (instance_hostname (DB_SETTINGS ["host" ]), DB_SETTINGS ["port" ]),
52+ datastore_all_metric_count ,
53+ ),
4954]
5055if REDIS_PY_VERSION >= (5 , 0 ):
51- _base_rollup_metrics .append (('Datastore/operation/Redis/client_setinfo' , 2 ),)
56+ _base_rollup_metrics .append (
57+ ("Datastore/operation/Redis/client_setinfo" , 2 ),
58+ )
59+
60+
61+ # Metrics for connection pool test
62+
63+ _base_pool_scoped_metrics = [
64+ ("Datastore/operation/Redis/get" , 1 ),
65+ ("Datastore/operation/Redis/set" , 1 ),
66+ ("Datastore/operation/Redis/client_list" , 1 ),
67+ ]
68+
69+ _base_pool_rollup_metrics = [
70+ ("Datastore/all" , 3 ),
71+ ("Datastore/allOther" , 3 ),
72+ ("Datastore/Redis/all" , 3 ),
73+ ("Datastore/Redis/allOther" , 3 ),
74+ ("Datastore/operation/Redis/get" , 1 ),
75+ ("Datastore/operation/Redis/set" , 1 ),
76+ ("Datastore/operation/Redis/client_list" , 1 ),
77+ ("Datastore/instance/Redis/%s/%s" % (instance_hostname (DB_SETTINGS ["host" ]), DB_SETTINGS ["port" ]), 3 ),
78+ ]
79+
5280
5381# Tests
5482
@@ -60,6 +88,31 @@ def client(loop): # noqa
6088 return loop .run_until_complete (redis .asyncio .Redis (host = DB_SETTINGS ["host" ], port = DB_SETTINGS ["port" ], db = 0 ))
6189
6290
91+ @pytest .fixture ()
92+ def client_pool (loop ): # noqa
93+ import redis .asyncio
94+
95+ connection_pool = redis .asyncio .ConnectionPool (host = DB_SETTINGS ["host" ], port = DB_SETTINGS ["port" ], db = 0 )
96+ return loop .run_until_complete (redis .asyncio .Redis (connection_pool = connection_pool ))
97+
98+
99+ @pytest .mark .skipif (REDIS_PY_VERSION < (4 , 2 ), reason = "This functionality exists in Redis 4.2+" )
100+ @validate_transaction_metrics (
101+ "test_asyncio:test_async_connection_pool" ,
102+ scoped_metrics = _base_pool_scoped_metrics ,
103+ rollup_metrics = _base_pool_rollup_metrics ,
104+ background_task = True ,
105+ )
106+ @background_task ()
107+ def test_async_connection_pool (client_pool , loop ): # noqa
108+ async def _test_async_pool (client_pool ):
109+ await client_pool .set ("key1" , "value1" )
110+ await client_pool .get ("key1" )
111+ await client_pool .execute_command ("CLIENT" , "LIST" )
112+
113+ loop .run_until_complete (_test_async_pool (client_pool ))
114+
115+
63116@pytest .mark .skipif (REDIS_PY_VERSION < (4 , 2 ), reason = "This functionality exists in Redis 4.2+" )
64117@validate_transaction_metrics ("test_asyncio:test_async_pipeline" , background_task = True )
65118@background_task ()
@@ -104,4 +157,4 @@ async def _test_pubsub():
104157 await future
105158
106159 loop .run_until_complete (_test_pubsub ())
107- assert messages_received == ["Hello" , "World" , "NOPE" ]
160+ assert messages_received == ["Hello" , "World" , "NOPE" ]
0 commit comments