File tree 2 files changed +28
-6
lines changed
2 files changed +28
-6
lines changed Original file line number Diff line number Diff line change @@ -349,9 +349,7 @@ def master_for(
349
349
connection_kwargs = dict (self .connection_kwargs )
350
350
connection_kwargs .update (kwargs )
351
351
return redis_class (
352
- connection_pool = connection_pool_class (
353
- service_name , self , ** connection_kwargs
354
- )
352
+ from_pool = connection_pool_class (service_name , self , ** connection_kwargs )
355
353
)
356
354
357
355
def slave_for (
@@ -382,7 +380,5 @@ def slave_for(
382
380
connection_kwargs = dict (self .connection_kwargs )
383
381
connection_kwargs .update (kwargs )
384
382
return redis_class (
385
- connection_pool = connection_pool_class (
386
- service_name , self , ** connection_kwargs
387
- )
383
+ from_pool = connection_pool_class (service_name , self , ** connection_kwargs )
388
384
)
Original file line number Diff line number Diff line change 1
1
import socket
2
+ from unittest import mock
2
3
3
4
import pytest
4
5
import redis .sentinel
@@ -240,3 +241,28 @@ def test_flushconfig(cluster, sentinel):
240
241
def test_reset (cluster , sentinel ):
241
242
cluster .master ["is_odown" ] = True
242
243
assert sentinel .sentinel_reset ("mymaster" )
244
+
245
+
246
+ @pytest .mark .onlynoncluster
247
+ @pytest .mark .parametrize ("method_name" , ["master_for" , "slave_for" ])
248
+ def test_auto_close_pool (cluster , sentinel , method_name ):
249
+ """
250
+ Check that the connection pool created by the sentinel client is
251
+ automatically closed
252
+ """
253
+
254
+ method = getattr (sentinel , method_name )
255
+ client = method ("mymaster" , db = 9 )
256
+ pool = client .connection_pool
257
+ assert client .auto_close_connection_pool is True
258
+ calls = 0
259
+
260
+ def mock_disconnect ():
261
+ nonlocal calls
262
+ calls += 1
263
+
264
+ with mock .patch .object (pool , "disconnect" , mock_disconnect ):
265
+ client .close ()
266
+
267
+ assert calls == 1
268
+ pool .disconnect ()
You can’t perform that action at this time.
0 commit comments