|
16 | 16 | from typing import Union |
17 | 17 |
|
18 | 18 | from google.api_core.exceptions import RetryError |
| 19 | +from google.api_core.retry.retry_unary_async import AsyncRetry |
19 | 20 | from mock import patch |
20 | 21 | from mocks import FakeAlloyDBClient |
21 | 22 | from mocks import FakeConnectionInfo |
|
24 | 25 |
|
25 | 26 | from google.cloud.alloydb.connector import AsyncConnector |
26 | 27 | from google.cloud.alloydb.connector import IPTypes |
| 28 | +from google.cloud.alloydb.connector.client import AlloyDBClient |
27 | 29 | from google.cloud.alloydb.connector.exceptions import ClosedConnectorError |
28 | 30 | from google.cloud.alloydb.connector.exceptions import IPTypeNotFoundError |
29 | 31 | from google.cloud.alloydb.connector.instance import RefreshAheadCache |
@@ -335,6 +337,19 @@ async def test_Connector_remove_cached_bad_instance( |
335 | 337 | """ |
336 | 338 | instance_uri = "projects/test-project/locations/test-region/clusters/test-cluster/instances/bad-test-instance" |
337 | 339 | async with AsyncConnector(credentials=credentials) as connector: |
| 340 | + # The timeout of AlloyDB API methods is set to 60s by default. |
| 341 | + # We override it to 1s to shorten the duration of the test. |
| 342 | + connector._client = AlloyDBClient( |
| 343 | + "alloydb.googleapis.com", "test-project", credentials, driver="asyncpg" |
| 344 | + ) |
| 345 | + transport = connector._client._client.transport |
| 346 | + transport._wrapped_methods[transport.get_connection_info]._retry = AsyncRetry( |
| 347 | + timeout=1 |
| 348 | + ) |
| 349 | + transport._wrapped_methods[ |
| 350 | + transport.generate_client_certificate |
| 351 | + ]._retry = AsyncRetry(timeout=1) |
| 352 | + |
338 | 353 | with pytest.raises(RetryError): |
339 | 354 | await connector.connect(instance_uri, "asyncpg") |
340 | 355 | assert instance_uri not in connector._cache |
|
0 commit comments