From 4519cdf08691b3fa7e3ed7ac8dbd1e7d2ecec64c Mon Sep 17 00:00:00 2001 From: rhatgadkar-goog Date: Wed, 13 Nov 2024 16:36:53 +0000 Subject: [PATCH] Fix unit tests for sync connector --- tests/unit/test_connector.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/tests/unit/test_connector.py b/tests/unit/test_connector.py index 4625053f..31f3fce4 100644 --- a/tests/unit/test_connector.py +++ b/tests/unit/test_connector.py @@ -208,10 +208,7 @@ def test_Connector_close_called_multiple_times(credentials: FakeCredentials) -> connector.close() -@pytest.mark.asyncio -async def test_Connector_remove_cached_bad_instance( - credentials: FakeCredentials, fake_client: FakeAlloyDBClient -) -> None: +async def test_Connector_remove_cached_bad_instance(credentials: FakeCredentials) -> None: """When a Connector attempts to retrieve connection info for a non-existent instance, it should delete the instance from the cache and ensure no background refresh happens (which would be @@ -220,14 +217,11 @@ async def test_Connector_remove_cached_bad_instance( instance_uri = "projects/test-project/locations/test-region/clusters/test-cluster/instances/bad-test-instance" with Connector(credentials) as connector: connector._client = FakeAlloyDBClient(instance = FakeInstance(name = "bad-test-instance")) - # patch db connection creation - with patch("google.cloud.alloydb.connector.pg8000.connect") as mock_connect: - mock_connect.return_value = True - cache = RefreshAheadCache(instance_uri, fake_client, connector._keys) - connector._cache[instance_uri] = cache - with pytest.raises(ClientResponseError): - await connector.connect_async(instance_uri, "pg8000") - assert instance_uri not in connector._cache + cache = RefreshAheadCache(instance_uri, connector._client, connector._keys) + connector._cache[instance_uri] = cache + with pytest.raises(ClientResponseError): + await connector.connect_async(instance_uri, "pg8000") + assert instance_uri not in connector._cache # def test_Connector_remove_cached_no_ip_type(