File tree Expand file tree Collapse file tree 3 files changed +29
-3
lines changed Expand file tree Collapse file tree 3 files changed +29
-3
lines changed Original file line number Diff line number Diff line change 12
12
$ client = $ factory ->createLazyClient ('localhost ' );
13
13
$ client ->subscribe ($ channel )->then (function () {
14
14
echo 'Now subscribed to channel ' . PHP_EOL ;
15
- }, function (Exception $ e ) {
15
+ }, function (Exception $ e ) use ($ client ) {
16
+ $ client ->close ();
16
17
echo 'Unable to subscribe: ' . $ e ->getMessage () . PHP_EOL ;
17
18
});
18
19
Original file line number Diff line number Diff line change @@ -166,8 +166,10 @@ public function close()
166
166
$ this ->promise ->then (function (Client $ client ) {
167
167
$ client ->close ();
168
168
});
169
- $ this ->promise ->cancel ();
170
- $ this ->promise = null ;
169
+ if ($ this ->promise !== null ) {
170
+ $ this ->promise ->cancel ();
171
+ $ this ->promise = null ;
172
+ }
171
173
}
172
174
173
175
if ($ this ->idleTimer !== null ) {
Original file line number Diff line number Diff line change @@ -310,6 +310,29 @@ public function testCloseAfterPingWillCancelIdleTimerWhenPingIsAlreadyResolved()
310
310
$ this ->client ->close ();
311
311
}
312
312
313
+ public function testCloseAfterPingRejectsWillEmitClose ()
314
+ {
315
+ $ deferred = new Deferred ();
316
+ $ client = $ this ->getMockBuilder ('Clue\React\Redis\StreamingClient ' )->disableOriginalConstructor ()->setMethods (array ('__call ' , 'close ' ))->getMock ();
317
+ $ client ->expects ($ this ->once ())->method ('__call ' )->willReturn ($ deferred ->promise ());
318
+ $ client ->expects ($ this ->once ())->method ('close ' )->willReturnCallback (function () use ($ client ) {
319
+ $ client ->emit ('close ' );
320
+ });
321
+
322
+ $ this ->factory ->expects ($ this ->once ())->method ('createClient ' )->willReturn (\React \Promise \resolve ($ client ));
323
+
324
+ $ timer = $ this ->getMockBuilder ('React\EventLoop\TimerInterface ' )->getMock ();
325
+ $ this ->loop ->expects ($ this ->once ())->method ('addTimer ' )->willReturn ($ timer );
326
+ $ this ->loop ->expects ($ this ->once ())->method ('cancelTimer ' )->with ($ timer );
327
+
328
+ $ ref = $ this ->client ;
329
+ $ ref ->ping ()->then (null , function () use ($ ref , $ client ) {
330
+ $ ref ->close ();
331
+ });
332
+ $ ref ->on ('close ' , $ this ->expectCallableOnce ());
333
+ $ deferred ->reject (new \RuntimeException ());
334
+ }
335
+
313
336
public function testEndWillCloseClientIfUnderlyingConnectionIsNotPending ()
314
337
{
315
338
$ this ->client ->on ('close ' , $ this ->expectCallableOnce ());
You can’t perform that action at this time.
0 commit comments