diff --git a/tests/test_connections.py b/tests/test_connections.py index 95531f861..f37c1b4f5 100644 --- a/tests/test_connections.py +++ b/tests/test_connections.py @@ -190,6 +190,34 @@ def test_add_connection_then_connect(self, uri): with mock.patch(f"{mock_prefix}.close", return_value=None): connections.remove_connection(alias) + + def test_connect_with_reuse_grpc(self): + alias = "default" + default_addr = {"address": "localhost:19530", "user": ""} + + reuse_alias = "reuse" + + assert connections.has_connection(alias) is False + addr = connections.get_connection_addr(alias) + assert addr == default_addr + + with mock.patch(f"{mock_prefix}.__init__", return_value=None): + with mock.patch(f"{mock_prefix}._wait_for_channel_ready", return_value=None): + connections.connect(alias=alias, **default_addr) + connections.connect(alias=reuse_alias, **default_addr) + assert connections._connected_alias[alias] == connections._connected_alias[reuse_alias] + assert list(connections._connection_references.values())[0] == 2 + + with mock.patch(f"{mock_prefix}.close", return_value=None): + connections.disconnect(alias) + + + assert list(connections._connection_references.values())[0] == 1 + + with mock.patch(f"{mock_prefix}.close", return_value=None): + connections.disconnect(reuse_alias) + + assert len(connections._connection_references) == 0 class TestAddConnection: