@@ -78,6 +78,19 @@ async def _exercise_es(es):
78
78
# Test
79
79
80
80
81
+ @pytest .fixture (scope = "session" )
82
+ def async_clients (loop ):
83
+ clients = []
84
+ for db in ES_MULTIPLE_SETTINGS :
85
+ es_url = f"http://{ db ['host' ]} :{ db ['port' ]} "
86
+ clients .append (AsyncElasticsearch (es_url ))
87
+
88
+ yield clients
89
+
90
+ for client in clients :
91
+ loop .run_until_complete (client .close ())
92
+
93
+
81
94
@pytest .mark .skipif (len (ES_MULTIPLE_SETTINGS ) < 2 , reason = "Test environment not configured with multiple databases." )
82
95
@override_application_settings (_enable_instance_settings )
83
96
@validate_transaction_metrics (
@@ -87,11 +100,11 @@ async def _exercise_es(es):
87
100
background_task = True ,
88
101
)
89
102
@background_task ()
90
- def test_async_multiple_dbs_enabled (loop ):
91
- for db in ES_MULTIPLE_SETTINGS :
92
- es_url = f"http:// { db [ 'host' ] } : { db [ 'port' ] } "
93
- client = AsyncElasticsearch ( es_url )
94
- loop .run_until_complete (_exercise_es (client ))
103
+ def test_async_multiple_dbs_enabled (loop , async_clients ):
104
+ import asyncio
105
+
106
+ # Run multiple queries in parallel
107
+ loop .run_until_complete (asyncio . gather ( * ( _exercise_es (client ) for client in async_clients ) ))
95
108
96
109
97
110
@pytest .mark .skipif (len (ES_MULTIPLE_SETTINGS ) < 2 , reason = "Test environment not configured with multiple databases." )
@@ -103,8 +116,8 @@ def test_async_multiple_dbs_enabled(loop):
103
116
background_task = True ,
104
117
)
105
118
@background_task ()
106
- def test_async_multiple_dbs_disabled (loop ):
107
- for db in ES_MULTIPLE_SETTINGS :
108
- es_url = f"http:// { db [ 'host' ] } : { db [ 'port' ] } "
109
- client = AsyncElasticsearch ( es_url )
110
- loop .run_until_complete (_exercise_es (client ))
119
+ def test_async_multiple_dbs_disabled (loop , async_clients ):
120
+ import asyncio
121
+
122
+ # Run multiple queries in parallel
123
+ loop .run_until_complete (asyncio . gather ( * ( _exercise_es (client ) for client in async_clients ) ))
0 commit comments