@@ -97,6 +97,51 @@ public function testConnectWillRejectWhenServerClosesConnection()
9797 $ loop ->run ();
9898 }
9999
100+ public function testConnectWillRejectOnExplicitTimeoutDespiteValidAuth ()
101+ {
102+ $ loop = \React \EventLoop \Factory::create ();
103+ $ factory = new Factory ($ loop );
104+
105+ $ uri = $ this ->getConnectionString () . '?timeout=0 ' ;
106+
107+ $ promise = $ factory ->createConnection ($ uri );
108+
109+ $ promise ->then (null , $ this ->expectCallableOnceWith (
110+ $ this ->logicalAnd (
111+ $ this ->isInstanceOf ('Exception ' ),
112+ $ this ->callback (function (\Exception $ e ) {
113+ return $ e ->getMessage () === 'Connection to database server timed out after 0 seconds ' ;
114+ })
115+ )
116+ ));
117+
118+ $ loop ->run ();
119+ }
120+
121+ public function testConnectWillRejectOnDefaultTimeoutFromIniDespiteValidAuth ()
122+ {
123+ $ loop = \React \EventLoop \Factory::create ();
124+ $ factory = new Factory ($ loop );
125+
126+ $ uri = $ this ->getConnectionString ();
127+
128+ $ old = ini_get ('default_socket_timeout ' );
129+ ini_set ('default_socket_timeout ' , '0 ' );
130+ $ promise = $ factory ->createConnection ($ uri );
131+ ini_set ('default_socket_timeout ' , $ old );
132+
133+ $ promise ->then (null , $ this ->expectCallableOnceWith (
134+ $ this ->logicalAnd (
135+ $ this ->isInstanceOf ('Exception ' ),
136+ $ this ->callback (function (\Exception $ e ) {
137+ return $ e ->getMessage () === 'Connection to database server timed out after 0 seconds ' ;
138+ })
139+ )
140+ ));
141+
142+ $ loop ->run ();
143+ }
144+
100145 public function testConnectWithValidAuthWillRunUntilQuit ()
101146 {
102147 $ this ->expectOutputString ('connected.closed. ' );
@@ -115,6 +160,24 @@ public function testConnectWithValidAuthWillRunUntilQuit()
115160 $ loop ->run ();
116161 }
117162
163+ public function testConnectWithValidAuthWillIgnoreNegativeTimeoutAndRunUntilQuit ()
164+ {
165+ $ this ->expectOutputString ('connected.closed. ' );
166+
167+ $ loop = \React \EventLoop \Factory::create ();
168+ $ factory = new Factory ($ loop );
169+
170+ $ uri = $ this ->getConnectionString () . '?timeout=-1 ' ;
171+ $ factory ->createConnection ($ uri )->then (function (ConnectionInterface $ connection ) {
172+ echo 'connected. ' ;
173+ $ connection ->quit ()->then (function () {
174+ echo 'closed. ' ;
175+ });
176+ }, 'printf ' )->then (null , 'printf ' );
177+
178+ $ loop ->run ();
179+ }
180+
118181 public function testConnectWithValidAuthCanPingAndThenQuit ()
119182 {
120183 $ this ->expectOutputString ('connected.ping.closed. ' );
0 commit comments