8
8
from redis .asyncio .sentinel import (
9
9
MasterNotFoundError ,
10
10
Sentinel ,
11
+ SentinelBlockingConnectionPool ,
11
12
SentinelConnectionPool ,
12
13
SlaveNotFoundError ,
13
14
)
@@ -182,40 +183,68 @@ async def test_discover_slaves(cluster, sentinel):
182
183
183
184
184
185
@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 :
187
195
assert await master .ping ()
188
196
assert master .connection_pool .master_address == (master_ip , 6379 )
189
197
190
198
# 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 :
192
200
assert await master .ping ()
193
201
194
202
195
203
@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 ):
197
212
cluster .slaves = [
198
213
{"ip" : "127.0.0.1" , "port" : 6379 , "is_odown" : False , "is_sdown" : False }
199
214
]
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 :
201
216
assert await slave .ping ()
202
217
203
218
204
219
@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 ):
206
228
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 :
208
230
with pytest .raises (SlaveNotFoundError ):
209
231
await slave .ping ()
210
232
211
233
212
234
@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 ):
214
243
cluster .slaves = [
215
244
{"ip" : "slave0" , "port" : 6379 , "is_odown" : False , "is_sdown" : False },
216
245
{"ip" : "slave1" , "port" : 6379 , "is_odown" : False , "is_sdown" : False },
217
246
]
218
- pool = SentinelConnectionPool ("mymaster" , sentinel )
247
+ pool = connection_pool_class ("mymaster" , sentinel )
219
248
rotator = pool .rotate_slaves ()
220
249
assert await rotator .__anext__ () in (("slave0" , 6379 ), ("slave1" , 6379 ))
221
250
assert await rotator .__anext__ () in (("slave0" , 6379 ), ("slave1" , 6379 ))
@@ -242,15 +271,23 @@ async def test_reset(cluster, sentinel):
242
271
243
272
244
273
@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 ):
247
284
"""
248
285
Check that the connection pool created by the sentinel client is
249
286
automatically closed
250
287
"""
251
288
252
289
method = getattr (sentinel , method_name )
253
- client = method ("mymaster" , db = 9 )
290
+ client = method ("mymaster" , db = 9 , connection_pool_class = connection_pool_class )
254
291
pool = client .connection_pool
255
292
assert client .auto_close_connection_pool is True
256
293
calls = 0
0 commit comments