Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/LazyClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public function idle()
{
--$this->pending;

if ($this->pending < 1 && $this->idlePeriod >= 0 && !$this->subscribed && !$this->psubscribed) {
if ($this->pending < 1 && $this->idlePeriod >= 0 && !$this->subscribed && !$this->psubscribed && $this->promise !== null) {
$idleTimer =& $this->idleTimer;
$promise =& $this->promise;
$idleTimer = $this->loop->addTimer($this->idlePeriod, function () use (&$idleTimer, &$promise) {
Expand Down
27 changes: 27 additions & 0 deletions tests/LazyClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,33 @@ public function testUnsubscribeAfterSubscribeWillResolveWhenUnderlyingClientReso
$promise->then($this->expectCallableOnceWith(array('unsubscribe', 'foo', 0)));
}

public function testBlpopWillRejectWhenUnderlyingClientClosesWhileWaitingForResponse()
{
$closeHandler = null;
$deferred = new Deferred();
$client = $this->getMockBuilder('Clue\React\Redis\Client')->getMock();
$client->expects($this->once())->method('__call')->with('blpop')->willReturn($deferred->promise());
$client->expects($this->any())->method('on')->withConsecutive(
array('close', $this->callback(function ($arg) use (&$closeHandler) {
$closeHandler = $arg;
return true;
}))
);

$this->factory->expects($this->once())->method('createClient')->willReturn(\React\Promise\resolve($client));

$this->loop->expects($this->never())->method('addTimer');

$promise = $this->client->blpop('list');

$this->assertTrue(is_callable($closeHandler));
$closeHandler();

$deferred->reject($e = new \RuntimeException());

$promise->then(null, $this->expectCallableOnceWith($e));
}

public function createCallableMockWithOriginalConstructorDisabled($array)
{
if (method_exists('PHPUnit\Framework\MockObject\MockBuilder', 'addMethods')) {
Expand Down