File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -89,7 +89,7 @@ private function idle()
89
89
{
90
90
--$ this ->pending ;
91
91
92
- if ($ this ->pending < 1 && $ this ->idlePeriod >= 0 ) {
92
+ if ($ this ->pending < 1 && $ this ->idlePeriod >= 0 && $ this -> connecting !== null ) {
93
93
$ this ->idleTimer = $ this ->loop ->addTimer ($ this ->idlePeriod , function () {
94
94
$ this ->connecting ->then (function (ConnectionInterface $ connection ) {
95
95
$ this ->disconnecting = $ connection ;
Original file line number Diff line number Diff line change @@ -513,6 +513,29 @@ public function testPingWillRejectAndStartTimerWhenPingFromUnderlyingConnectionR
513
513
$ ret ->then ($ this ->expectCallableNever (), $ this ->expectCallableOnceWith ($ error ));
514
514
}
515
515
516
+ public function testPingWillRejectAndNotStartIdleTimerWhenPingFromUnderlyingConnectionRejectsBecauseConnectionIsDead ()
517
+ {
518
+ $ error = new \RuntimeException ();
519
+
520
+ $ base = $ this ->getMockBuilder ('React\MySQL\Io\LazyConnection ' )->setMethods (array ('ping ' , 'close ' ))->disableOriginalConstructor ()->getMock ();
521
+ $ base ->expects ($ this ->once ())->method ('ping ' )->willReturnCallback (function () use ($ base , $ error ) {
522
+ $ base ->emit ('close ' );
523
+ return \React \Promise \reject ($ error );
524
+ });
525
+ $ base ->expects ($ this ->never ())->method ('close ' );
526
+
527
+ $ factory = $ this ->getMockBuilder ('React\MySQL\Factory ' )->disableOriginalConstructor ()->getMock ();
528
+ $ factory ->expects ($ this ->once ())->method ('createConnection ' )->willReturn (\React \Promise \resolve ($ base ));
529
+
530
+ $ loop = $ this ->getMockBuilder ('React\EventLoop\LoopInterface ' )->getMock ();
531
+ $ loop ->expects ($ this ->never ())->method ('addTimer ' );
532
+
533
+ $ connection = new LazyConnection ($ factory , '' , $ loop );
534
+
535
+ $ ret = $ connection ->ping ();
536
+ $ ret ->then ($ this ->expectCallableNever (), $ this ->expectCallableOnceWith ($ error ));
537
+ }
538
+
516
539
public function testQuitResolvesAndEmitsCloseImmediatelyWhenConnectionIsNotAlreadyPending ()
517
540
{
518
541
$ factory = $ this ->getMockBuilder ('React\MySQL\Factory ' )->disableOriginalConstructor ()->getMock ();
You can’t perform that action at this time.
0 commit comments