Skip to content

Commit ec33be1

Browse files
committed
Add tests for the Sentinel connection pool auto-close
1 parent ba0dcea commit ec33be1

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

tests/test_asyncio/test_sentinel.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import socket
2+
from unittest import mock
23

34
import pytest
45
import pytest_asyncio
@@ -239,3 +240,27 @@ async def test_flushconfig(cluster, sentinel):
239240
async def test_reset(cluster, sentinel):
240241
cluster.master["is_odown"] = True
241242
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()

0 commit comments

Comments
 (0)