1616
1717import asyncio
1818import os
19- import time
2019from typing import Union
2120
2221from aiohttp import ClientResponseError
3130from google .cloud .sql .connector .connection_name import ConnectionName
3231from google .cloud .sql .connector .exceptions import CloudSQLIPTypeError
3332from google .cloud .sql .connector .exceptions import IncompatibleDriverError
33+ from google .cloud .sql .connector .exceptions import ClosedConnectionError
3434from google .cloud .sql .connector .instance import RefreshAheadCache
3535
3636
@@ -481,17 +481,18 @@ async def test_connect_async_closed_connector(
481481 ) as connector :
482482 connector ._client = fake_client
483483 await connector .close_async ()
484- # wait for close to complete
485- # await asyncio.sleep(0.1)
486- with pytest .raises (RuntimeError ) as exc_info :
484+ with pytest .raises (ClosedConnectionError ) as exc_info :
487485 await connector .connect_async (
488486 "test-project:test-region:test-instance" ,
489487 "asyncpg" ,
490488 user = "my-user" ,
491489 password = "my-pass" ,
492490 db = "my-db" ,
493491 )
494- assert exc_info .value .args [0 ] == "Cannot connect using a closed Connector."
492+ assert (
493+ exc_info .value .args [0 ]
494+ == "Connection attempt failed because the connector has already been closed."
495+ )
495496
496497
497498def test_connect_closed_connector (
@@ -501,13 +502,15 @@ def test_connect_closed_connector(
501502 with Connector (credentials = fake_credentials ) as connector :
502503 connector ._client = fake_client
503504 connector .close ()
504- # time.sleep(3.1)
505- with pytest .raises (RuntimeError ) as exc_info :
505+ with pytest .raises (ClosedConnectionError ) as exc_info :
506506 connector .connect (
507507 "test-project:test-region:test-instance" ,
508508 "pg8000" ,
509509 user = "my-user" ,
510510 password = "my-pass" ,
511511 db = "my-db" ,
512512 )
513- assert exc_info .value .args [0 ] == "Cannot connect using a closed Connector."
513+ assert (
514+ exc_info .value .args [0 ]
515+ == "Connection attempt failed because the connector has already been closed."
516+ )
0 commit comments