File tree 1 file changed +25
-0
lines changed 1 file changed +25
-0
lines changed 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 pytest_asyncio
@@ -239,3 +240,27 @@ async def test_flushconfig(cluster, sentinel):
239
240
async def test_reset (cluster , sentinel ):
240
241
cluster .master ["is_odown" ] = True
241
242
assert await sentinel .sentinel_reset ("mymaster" )
243
+
244
+
245
+ @pytest .mark .onlynoncluster
246
+ @pytest .mark .parametrize ("method_name" , ["master_for" , "slave_for" ])
247
+ async def test_auto_close_pool (cluster , sentinel , method_name ):
248
+ """
249
+ Check that the connection pool created by the sentinel client is automatically closed
250
+ """
251
+
252
+ method = getattr (sentinel , method_name )
253
+ client = method ("mymaster" , db = 9 )
254
+ pool = client .connection_pool
255
+ assert client .auto_close_connection_pool is True
256
+ calls = 0
257
+
258
+ async def mock_disconnect ():
259
+ nonlocal calls
260
+ calls += 1
261
+
262
+ with mock .patch .object (pool , "disconnect" , mock_disconnect ) as disconnect :
263
+ await client .close ()
264
+
265
+ assert calls == 1
266
+ await pool .disconnect ()
You can’t perform that action at this time.
0 commit comments