Skip to content

Commit

Permalink
Improve worker shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
bzikarsky committed Apr 28, 2021
1 parent b9eda1e commit 4645211
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Protocol/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public function getCommandFactory(): CommandFactoryInterface
*/
public function isClosed(): bool
{
return $this->stream->isWritable();
return !$this->stream->isWritable();
}

/**
Expand Down
12 changes: 8 additions & 4 deletions tests/Protocol/ConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class ConnectionTest extends \PHPUnit\Framework\TestCase
protected $packetStr;

protected $stream;
private $writableStream;
protected Connection $connection;

public function setUp(): void
Expand All @@ -27,9 +28,11 @@ protected function setUpStream()
$fac = new CommandFactory();
$fac->addType($this->type);

$this->writableStream = $this->createMock(\React\Stream\WritableStreamInterface::class);

$this->stream = new \React\Stream\CompositeStream(
$this->createMock(\React\Stream\ReadableStreamInterface::class),
$this->createMock(\React\Stream\WritableStreamInterface::class)
$this->writableStream
);

$this->connection = new Connection($this->stream, $fac);
Expand All @@ -53,6 +56,7 @@ public function testStreamClose()
$closeCalled = true;
});

$this->writableStream->method('isWritable')->willReturn(false);
$this->stream->emit("close");
self::assertTrue($closeCalled);
self::assertTrue($this->connection->isClosed());
Expand All @@ -65,11 +69,11 @@ public function testStreamClose()
*/
public function testSendFailOnClosedConnection(Connection $connection)
{
$this->writableStream->method('isWritable')->willReturn(false);

$this->expectException(BadMethodCallException::class);
$thrown = null;
$connection->send($this->packet)->otherwise(function ($e) use (&$thrown) {
$thrown = $e;
});
$connection->send($this->packet);
}

public function testHandledPacketEvent()
Expand Down

0 comments on commit 4645211

Please sign in to comment.