File tree Expand file tree Collapse file tree 2 files changed +28
-6
lines changed Expand file tree Collapse file tree 2 files changed +28
-6
lines changed Original file line number Diff line number Diff line change @@ -354,9 +354,7 @@ def master_for(
354
354
connection_kwargs = dict (self .connection_kwargs )
355
355
connection_kwargs .update (kwargs )
356
356
return redis_class (
357
- connection_pool = connection_pool_class (
358
- service_name , self , ** connection_kwargs
359
- )
357
+ from_pool = connection_pool_class (service_name , self , ** connection_kwargs )
360
358
)
361
359
362
360
def slave_for (
@@ -387,7 +385,5 @@ def slave_for(
387
385
connection_kwargs = dict (self .connection_kwargs )
388
386
connection_kwargs .update (kwargs )
389
387
return redis_class (
390
- connection_pool = connection_pool_class (
391
- service_name , self , ** connection_kwargs
392
- )
388
+ from_pool = connection_pool_class (service_name , self , ** connection_kwargs )
393
389
)
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