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):
475
475
try :
476
476
if self ._unix_socket and self ._host in ('localhost' , '127.0.0.1' ):
477
477
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 )
480
483
self .host_info = "Localhost via UNIX socket: " + \
481
484
self ._unix_socket
482
485
else :
483
486
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 )
486
493
self ._set_keep_alive ()
487
494
self .host_info = "socket %s:%d" % (self ._host , self ._port )
488
495
Original file line number Diff line number Diff line change @@ -22,6 +22,12 @@ def fill_my_cnf(self):
22
22
with open (path2 , 'w' ) as f2 :
23
23
f2 .write (tmpl .format_map (self .__dict__ ))
24
24
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
+
25
31
@run_until_complete
26
32
def test_config_file (self ):
27
33
self .fill_my_cnf ()
You can’t perform that action at this time.
0 commit comments