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
4 changes: 2 additions & 2 deletions src/ChildProcess/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ public function callFilesystem($function, $args, $errorResultCode = -1)
{
return $this->pool->rpc(Factory::rpc($function, $args))->then(function (Payload $payload) {
return \React\Promise\resolve($payload->getPayload());
}, function (Payload $payload) {
return \React\Promise\reject(new Exception($payload->getPayload()['error']['error']['message']));
}, function ($payload) {
return \React\Promise\reject(new Exception($payload['error']['message']));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The title suggests there must be a way to verify this is "the correct way"? :shipit:

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah using array access and ditching the extra error index solve the errors.

(Also updated the title.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this tested or can we add some tests for this? 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a test for this 👍

});
}

Expand Down
14 changes: 14 additions & 0 deletions tests/ChildProcess/AdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace React\Tests\Filesystem\ChildProcess;

use React\EventLoop\Factory;
use React\Filesystem\ChildProcess\Adapter;
use React\Filesystem\Filesystem;
use React\Filesystem\Node\NodeInterface;
Expand Down Expand Up @@ -324,4 +325,17 @@ public function testLs()
]);
$this->assertTrue($calledOnData);
}

public function testErrorFromPool()
{
$this->setExpectedException('\Exception', 'oops');

$loop = Factory::create();
$adapter = new Adapter($loop, [
'pool' => [
'class' => 'React\Tests\Filesystem\ChildProcess\PoolRpcErrorMockFactory',
],
]);
$this->await($adapter->touch('foo.bar'), $loop, 1);
}
}
44 changes: 44 additions & 0 deletions tests/ChildProcess/PoolRpcErrorMock.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace React\Tests\Filesystem\ChildProcess;

use Evenement\EventEmitter;
use React\EventLoop\LoopInterface;
use React\Promise\FulfilledPromise;
use React\Promise\RejectedPromise;
use WyriHaximus\React\ChildProcess\Messenger\Messages\Message;
use WyriHaximus\React\ChildProcess\Messenger\Messages\Rpc;
use WyriHaximus\React\ChildProcess\Pool\PoolInterface;
use WyriHaximus\React\ChildProcess\Pool\ProcessCollectionInterface;

final class PoolRpcErrorMock extends EventEmitter implements PoolInterface
{
public function __construct(ProcessCollectionInterface $processCollection, LoopInterface $loop, array $options = [])
{
// void
}

public function rpc(Rpc $message)
{
return new RejectedPromise([
'error' => [
'message' => 'oops',
],
]);
}

public function message(Message $message)
{
return new FulfilledPromise();
}

public function terminate(Message $message, $timeout = 5, $signal = null)
{
return new FulfilledPromise();
}

public function info()
{
return [];
}
}
32 changes: 32 additions & 0 deletions tests/ChildProcess/PoolRpcErrorMockFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace React\Tests\Filesystem\ChildProcess;

use React\ChildProcess\Process;
use React\EventLoop\Factory;
use React\EventLoop\LoopInterface;
use React\Promise\FulfilledPromise;
use WyriHaximus\React\ChildProcess\Pool\PoolFactoryInterface;
use WyriHaximus\React\ChildProcess\Pool\ProcessCollection\Single;

final class PoolRpcErrorMockFactory implements PoolFactoryInterface
{
public static function create(Process $childProcess, LoopInterface $loop, array $options = [])
{
return new FulfilledPromise(new PoolRpcErrorMock(
new Single(function () {}),
Factory::create(),
[]
));
}

public static function createFromClass($class, LoopInterface $loop, array $options = [])
{
return new FulfilledPromise(new PoolRpcErrorMock(
new Single(function () {}),
Factory::create(),
[]
));
}

}