File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -146,8 +146,13 @@ def import_dbapi(cls) -> Any:
146146 return aio
147147
148148 def connect (self , * cargs : Any , ** cparams : Any ) -> Any :
149- """Create and wrap an async connection."""
149+ """Create and wrap an async connection.
150+
151+ Eagerly establishes the TCP connection so errors surface at
152+ connect-time rather than on the first query.
153+ """
150154 raw_conn = self .loaded_dbapi .connect (* cargs , ** cparams )
155+ await_only (raw_conn .connect ())
151156 return AsyncAdaptedConnection (raw_conn )
152157
153158 def get_driver_connection (self , connection : Any ) -> Any :
Original file line number Diff line number Diff line change @@ -392,6 +392,36 @@ def test_sync_dialect_does_not_use_nullpool(self) -> None:
392392 )
393393
394394
395+ class TestAsyncConnect :
396+ def test_connect_calls_await_only_on_raw_connect (self ) -> None :
397+ """Async dialect connect() should eagerly establish the TCP connection."""
398+ import ast
399+ import inspect
400+ import textwrap
401+
402+ from sqlalchemydqlite .aio import DqliteDialect_aio
403+
404+ source = textwrap .dedent (inspect .getsource (DqliteDialect_aio .connect ))
405+ tree = ast .parse (source )
406+
407+ # Look for await_only(raw_conn.connect()) or similar eager connect call
408+ has_eager_connect = False
409+ for node in ast .walk (tree ):
410+ if isinstance (node , ast .Call ):
411+ func = node .func
412+ if isinstance (func , ast .Name ) and func .id == "await_only" and node .args :
413+ arg = node .args [0 ]
414+ if isinstance (arg , ast .Call ):
415+ inner = arg .func
416+ if isinstance (inner , ast .Attribute ) and inner .attr == "connect" :
417+ has_eager_connect = True
418+
419+ assert has_eager_connect , (
420+ "DqliteDialect_aio.connect() should eagerly establish TCP with "
421+ "await_only(raw_conn.connect())"
422+ )
423+
424+
395425class TestURLParsing :
396426 def test_parse_basic_url (self ) -> None :
397427 url = URL .create ("dqlite" , host = "localhost" , port = 9001 , database = "test" )
You can’t perform that action at this time.
0 commit comments