Skip to content

Commit e6ab57f

Browse files
Remove close() from AlloyDBClient because it is a no-op
1 parent ab5100b commit e6ab57f

File tree

6 files changed

+1
-28
lines changed

6 files changed

+1
-28
lines changed

google/cloud/alloydb/connector/async_connector.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,5 +235,3 @@ async def close(self) -> None:
235235
"""Helper function to cancel RefreshAheadCaches' tasks
236236
and close client."""
237237
await asyncio.gather(*[cache.close() for cache in self._cache.values()])
238-
if self._client:
239-
await self._client.close()

google/cloud/alloydb/connector/client.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,3 @@ async def get_connection_info(
244244
ip_addrs,
245245
expiration,
246246
)
247-
248-
async def close(self) -> None:
249-
"""Close AlloyDBClient gracefully."""
250-
logger.debug("Closed AlloyDBClient")

google/cloud/alloydb/connector/connector.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,5 +392,3 @@ async def close_async(self) -> None:
392392
"""Helper function to cancel RefreshAheadCaches' tasks
393393
and close client."""
394394
await asyncio.gather(*[cache.close() for cache in self._cache.values()])
395-
if self._client:
396-
await self._client.close()

tests/unit/mocks.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ def __init__(
233233
self, instance: Optional[FakeInstance] = None, driver: str = "pg8000"
234234
) -> None:
235235
self.instance = FakeInstance() if instance is None else instance
236-
self.closed = False
237236
self._user_agent = f"test-user-agent+{driver}"
238237
self._credentials = FakeCredentials()
239238

@@ -318,9 +317,6 @@ async def get_connection_info(
318317
expiration,
319318
)
320319

321-
async def close(self) -> None:
322-
self.closed = True
323-
324320

325321
def metadata_exchange(sock: ssl.SSLSocket) -> None:
326322
"""
@@ -466,14 +462,12 @@ async def get_connection_info(
466462
if instance == "test-instance":
467463
ci.public_ip_address = ""
468464
ci.psc_dns_name = ""
469-
return ci
470465
elif instance == "public-instance":
471466
ci.psc_dns_name = ""
472-
return ci
473467
else:
474468
ci.ip_address = ""
475469
ci.public_ip_address = ""
476-
return ci
470+
return ci
477471

478472
async def generate_client_certificate(
479473
self, request: alloydb_v1beta.GenerateClientCertificateRequest

tests/unit/test_async_connector.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,6 @@ async def test_connect_and_close(credentials: FakeCredentials) -> None:
163163

164164
# check connection is returned
165165
assert connection.result() is True
166-
# outside of context manager check close cleaned up
167-
assert connector._client.closed is True
168166

169167

170168
@pytest.mark.asyncio
@@ -244,8 +242,6 @@ async def test_context_manager_connect_and_close(
244242

245243
# check connection is returned
246244
assert connection.result() is True
247-
# outside of context manager check close cleaned up
248-
assert fake_client.closed is True
249245

250246

251247
@pytest.mark.asyncio

tests/unit/test_client.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ async def test__get_metadata_error(
9696
await client._get_metadata(
9797
"my-project", "my-region", "my-cluster", "my-instance"
9898
)
99-
await client.close()
10099

101100

102101
@pytest.mark.asyncio
@@ -131,7 +130,6 @@ async def test__get_client_certificate_error(
131130
await client._get_client_certificate(
132131
"my-project", "my-region", "my-cluster", ""
133132
)
134-
await client.close()
135133

136134

137135
@pytest.mark.asyncio
@@ -146,8 +144,6 @@ async def test_AlloyDBClient_init_(credentials: FakeCredentials) -> None:
146144
# verify proper headers are set
147145
assert client._user_agent.startswith(f"alloydb-python-connector/{version}")
148146
assert client._client._client._client_options.quota_project_id == "my-quota-project"
149-
# close client
150-
await client.close()
151147

152148

153149
@pytest.mark.asyncio
@@ -166,7 +162,6 @@ async def test_AlloyDBClient_init_custom_user_agent(
166162
assert client._user_agent.startswith(
167163
f"alloydb-python-connector/{version} custom-agent/v1.0.0 other-agent/v2.0.0"
168164
)
169-
await client.close()
170165

171166

172167
@pytest.mark.parametrize(
@@ -190,8 +185,6 @@ async def test_AlloyDBClient_user_agent(
190185
assert client._user_agent.startswith(
191186
f"alloydb-python-connector/{version}+{driver}"
192187
)
193-
# close client
194-
await client.close()
195188

196189

197190
@pytest.mark.parametrize(
@@ -210,5 +203,3 @@ async def test_AlloyDBClient_use_metadata(
210203
"www.test-endpoint.com", "my-quota-project", credentials, driver=driver
211204
)
212205
assert client._use_metadata == expected
213-
# close client
214-
await client.close()

0 commit comments

Comments
 (0)