88from redis .asyncio .sentinel import (
99 MasterNotFoundError ,
1010 Sentinel ,
11+ SentinelBlockingConnectionPool ,
1112 SentinelConnectionPool ,
1213 SlaveNotFoundError ,
1314)
@@ -182,40 +183,77 @@ async def test_discover_slaves(cluster, sentinel):
182183
183184
184185@pytest .mark .onlynoncluster
185- async def test_master_for (cluster , sentinel , master_ip ):
186- async with sentinel .master_for ("mymaster" , db = 9 ) as master :
186+ @pytest .mark .parametrize (
187+ "connection_pool_class" ,
188+ [SentinelConnectionPool , SentinelBlockingConnectionPool ],
189+ )
190+ async def test_master_for (cluster , sentinel , master_ip , connection_pool_class ):
191+ async with sentinel .master_for (
192+ "mymaster" ,
193+ db = 9 ,
194+ connection_pool_class = connection_pool_class ,
195+ ) as master :
187196 assert await master .ping ()
188197 assert master .connection_pool .master_address == (master_ip , 6379 )
189198
190199 # Use internal connection check
191- async with sentinel .master_for ("mymaster" , db = 9 , check_connection = True ) as master :
200+ async with sentinel .master_for (
201+ "mymaster" ,
202+ db = 9 ,
203+ check_connection = True ,
204+ connection_pool_class = connection_pool_class ,
205+ ) as master :
192206 assert await master .ping ()
193207
194208
195209@pytest .mark .onlynoncluster
196- async def test_slave_for (cluster , sentinel ):
210+ @pytest .mark .parametrize (
211+ "connection_pool_class" ,
212+ [SentinelConnectionPool , SentinelBlockingConnectionPool ],
213+ )
214+ async def test_slave_for (cluster , sentinel , connection_pool_class ):
197215 cluster .slaves = [
198216 {"ip" : "127.0.0.1" , "port" : 6379 , "is_odown" : False , "is_sdown" : False }
199217 ]
200- async with sentinel .slave_for ("mymaster" , db = 9 ) as slave :
218+ async with sentinel .slave_for (
219+ "mymaster" ,
220+ db = 9 ,
221+ connection_pool_class = connection_pool_class ,
222+ ) as slave :
201223 assert await slave .ping ()
202224
203225
204226@pytest .mark .onlynoncluster
205- async def test_slave_for_slave_not_found_error (cluster , sentinel ):
227+ @pytest .mark .parametrize (
228+ "connection_pool_class" ,
229+ [SentinelConnectionPool , SentinelBlockingConnectionPool ],
230+ )
231+ async def test_slave_for_slave_not_found_error (
232+ cluster ,
233+ sentinel ,
234+ connection_pool_class ,
235+ ):
206236 cluster .master ["is_odown" ] = True
207- async with sentinel .slave_for ("mymaster" , db = 9 ) as slave :
237+ async with sentinel .slave_for (
238+ "mymaster" ,
239+ db = 9 ,
240+ connection_pool_class = connection_pool_class ,
241+ ) as slave :
208242 with pytest .raises (SlaveNotFoundError ):
209243 await slave .ping ()
210244
211245
212246@pytest .mark .onlynoncluster
213- async def test_slave_round_robin (cluster , sentinel , master_ip ):
247+ @pytest .mark .parametrize (
248+ "connection_pool_class" ,
249+ [SentinelConnectionPool , SentinelBlockingConnectionPool ],
250+ )
251+ async def test_slave_round_robin (cluster , sentinel , master_ip , connection_pool_class ):
214252 cluster .slaves = [
215253 {"ip" : "slave0" , "port" : 6379 , "is_odown" : False , "is_sdown" : False },
216254 {"ip" : "slave1" , "port" : 6379 , "is_odown" : False , "is_sdown" : False },
217255 ]
218- pool = SentinelConnectionPool ("mymaster" , sentinel )
256+ pool = connection_pool_class ("mymaster" , sentinel )
219257 rotator = pool .rotate_slaves ()
220258 assert await rotator .__anext__ () in (("slave0" , 6379 ), ("slave1" , 6379 ))
221259 assert await rotator .__anext__ () in (("slave0" , 6379 ), ("slave1" , 6379 ))
@@ -242,15 +280,39 @@ async def test_reset(cluster, sentinel):
242280
243281
244282@pytest .mark .onlynoncluster
245- @pytest .mark .parametrize ("method_name" , ["master_for" , "slave_for" ])
246- async def test_auto_close_pool (cluster , sentinel , method_name ):
283+ @pytest .mark .parametrize (
284+ "method_name,connection_pool_class" ,
285+ [
286+ pytest .param (
287+ "master_for" ,
288+ SentinelConnectionPool ,
289+ id = "master_for__SentinelConnectionPool" ,
290+ ),
291+ pytest .param (
292+ "slave_for" ,
293+ SentinelConnectionPool ,
294+ id = "slave_for__SentinelConnectionPool" ,
295+ ),
296+ pytest .param (
297+ "master_for" ,
298+ SentinelBlockingConnectionPool ,
299+ id = "master_for__SentinelBlockingConnectionPool" ,
300+ ),
301+ pytest .param (
302+ "slave_for" ,
303+ SentinelBlockingConnectionPool ,
304+ id = "slave_for__SentinelBlockingConnectionPool" ,
305+ ),
306+ ],
307+ )
308+ async def test_auto_close_pool (cluster , sentinel , method_name , connection_pool_class ):
247309 """
248310 Check that the connection pool created by the sentinel client is
249311 automatically closed
250312 """
251313
252314 method = getattr (sentinel , method_name )
253- client = method ("mymaster" , db = 9 )
315+ client = method ("mymaster" , db = 9 , connection_pool_class = connection_pool_class )
254316 pool = client .connection_pool
255317 assert client .auto_close_connection_pool is True
256318 calls = 0
0 commit comments