File tree Expand file tree Collapse file tree 2 files changed +17
-4
lines changed
Expand file tree Collapse file tree 2 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -475,14 +475,21 @@ async def _connect(self):
475475 try :
476476 if self ._unix_socket and self ._host in ('localhost' , '127.0.0.1' ):
477477 self ._reader , self ._writer = await \
478- asyncio .open_unix_connection (self ._unix_socket ,
479- loop = self ._loop )
478+ asyncio .wait_for (
479+ asyncio .open_unix_connection (
480+ self ._unix_socket ,
481+ loop = self ._loop ),
482+ timeout = self .connect_timeout )
480483 self .host_info = "Localhost via UNIX socket: " + \
481484 self ._unix_socket
482485 else :
483486 self ._reader , self ._writer = await \
484- asyncio .open_connection (self ._host , self ._port ,
485- loop = self ._loop )
487+ asyncio .wait_for (
488+ asyncio .open_connection (
489+ self ._host ,
490+ self ._port ,
491+ loop = self ._loop ),
492+ timeout = self .connect_timeout )
486493 self ._set_keep_alive ()
487494 self .host_info = "socket %s:%d" % (self ._host , self ._port )
488495
Original file line number Diff line number Diff line change @@ -22,6 +22,12 @@ def fill_my_cnf(self):
2222 with open (path2 , 'w' ) as f2 :
2323 f2 .write (tmpl .format_map (self .__dict__ ))
2424
25+ @run_until_complete
26+ def test_connect_timeout (self ):
27+ # All exceptions are caught and raised as operational errors
28+ with self .assertRaises (aiomysql .OperationalError ):
29+ yield from self .connect (connect_timeout = 0.000000000001 )
30+
2531 @run_until_complete
2632 def test_config_file (self ):
2733 self .fill_my_cnf ()
You can’t perform that action at this time.
0 commit comments