88from redis .asyncio .sentinel import (
99 MasterNotFoundError ,
1010 Sentinel ,
11+ SentinelBlockingConnectionPool ,
1112 SentinelConnectionPool ,
1213 SlaveNotFoundError ,
1314)
@@ -182,40 +183,68 @@ 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+ [
189+ pytest .param (SentinelConnectionPool , id = 'SentinelConnectionPool' ),
190+ pytest .param (SentinelBlockingConnectionPool , id = 'SentinelBlockingConnectionPool' ),
191+ ],
192+ )
193+ async def test_master_for (cluster , sentinel , master_ip , connection_pool_class ):
194+ async with sentinel .master_for ("mymaster" , db = 9 , connection_pool_class = connection_pool_class ) as master :
187195 assert await master .ping ()
188196 assert master .connection_pool .master_address == (master_ip , 6379 )
189197
190198 # Use internal connection check
191- async with sentinel .master_for ("mymaster" , db = 9 , check_connection = True ) as master :
199+ async with sentinel .master_for ("mymaster" , db = 9 , check_connection = True , connection_pool_class = connection_pool_class ) as master :
192200 assert await master .ping ()
193201
194202
195203@pytest .mark .onlynoncluster
196- async def test_slave_for (cluster , sentinel ):
204+ @pytest .mark .parametrize (
205+ "connection_pool_class" ,
206+ [
207+ pytest .param (SentinelConnectionPool , id = 'SentinelConnectionPool' ),
208+ pytest .param (SentinelBlockingConnectionPool , id = 'SentinelBlockingConnectionPool' ),
209+ ],
210+ )
211+ async def test_slave_for (cluster , sentinel , connection_pool_class ):
197212 cluster .slaves = [
198213 {"ip" : "127.0.0.1" , "port" : 6379 , "is_odown" : False , "is_sdown" : False }
199214 ]
200- async with sentinel .slave_for ("mymaster" , db = 9 ) as slave :
215+ async with sentinel .slave_for ("mymaster" , db = 9 , connection_pool_class = connection_pool_class ) as slave :
201216 assert await slave .ping ()
202217
203218
204219@pytest .mark .onlynoncluster
205- async def test_slave_for_slave_not_found_error (cluster , sentinel ):
220+ @pytest .mark .parametrize (
221+ "connection_pool_class" ,
222+ [
223+ pytest .param (SentinelConnectionPool , id = 'SentinelConnectionPool' ),
224+ pytest .param (SentinelBlockingConnectionPool , id = 'SentinelBlockingConnectionPool' ),
225+ ],
226+ )
227+ async def test_slave_for_slave_not_found_error (cluster , sentinel , connection_pool_class ):
206228 cluster .master ["is_odown" ] = True
207- async with sentinel .slave_for ("mymaster" , db = 9 ) as slave :
229+ async with sentinel .slave_for ("mymaster" , db = 9 , connection_pool_class = connection_pool_class ) as slave :
208230 with pytest .raises (SlaveNotFoundError ):
209231 await slave .ping ()
210232
211233
212234@pytest .mark .onlynoncluster
213- async def test_slave_round_robin (cluster , sentinel , master_ip ):
235+ @pytest .mark .parametrize (
236+ "connection_pool_class" ,
237+ [
238+ pytest .param (SentinelConnectionPool , id = 'SentinelConnectionPool' ),
239+ pytest .param (SentinelBlockingConnectionPool , id = 'SentinelBlockingConnectionPool' ),
240+ ],
241+ )
242+ async def test_slave_round_robin (cluster , sentinel , master_ip , connection_pool_class ):
214243 cluster .slaves = [
215244 {"ip" : "slave0" , "port" : 6379 , "is_odown" : False , "is_sdown" : False },
216245 {"ip" : "slave1" , "port" : 6379 , "is_odown" : False , "is_sdown" : False },
217246 ]
218- pool = SentinelConnectionPool ("mymaster" , sentinel )
247+ pool = connection_pool_class ("mymaster" , sentinel )
219248 rotator = pool .rotate_slaves ()
220249 assert await rotator .__anext__ () in (("slave0" , 6379 ), ("slave1" , 6379 ))
221250 assert await rotator .__anext__ () in (("slave0" , 6379 ), ("slave1" , 6379 ))
@@ -242,15 +271,23 @@ async def test_reset(cluster, sentinel):
242271
243272
244273@pytest .mark .onlynoncluster
245- @pytest .mark .parametrize ("method_name" , ["master_for" , "slave_for" ])
246- async def test_auto_close_pool (cluster , sentinel , method_name ):
274+ @pytest .mark .parametrize (
275+ "method_name,connection_pool_class" ,
276+ [
277+ pytest .param ("master_for" , SentinelConnectionPool , id = "master_for__SentinelConnectionPool" ),
278+ pytest .param ("slave_for" , SentinelConnectionPool , id = "slave_for__SentinelConnectionPool" ),
279+ pytest .param ("master_for" , SentinelBlockingConnectionPool , id = "master_for__SentinelBlockingConnectionPool" ),
280+ pytest .param ("slave_for" , SentinelBlockingConnectionPool , id = "slave_for__SentinelBlockingConnectionPool" ),
281+ ]
282+ )
283+ async def test_auto_close_pool (cluster , sentinel , method_name , connection_pool_class ):
247284 """
248285 Check that the connection pool created by the sentinel client is
249286 automatically closed
250287 """
251288
252289 method = getattr (sentinel , method_name )
253- client = method ("mymaster" , db = 9 )
290+ client = method ("mymaster" , db = 9 , connection_pool_class = connection_pool_class )
254291 pool = client .connection_pool
255292 assert client .auto_close_connection_pool is True
256293 calls = 0
0 commit comments