From 053764ec72c59691da98461cd71b8845d22fc662 Mon Sep 17 00:00:00 2001 From: Cees-Jan Kiewiet Date: Mon, 28 May 2018 18:43:46 +0200 Subject: [PATCH 1/2] Get the error from the child process in the correct way --- src/ChildProcess/Adapter.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ChildProcess/Adapter.php b/src/ChildProcess/Adapter.php index 65ed53a0..45fdd484 100644 --- a/src/ChildProcess/Adapter.php +++ b/src/ChildProcess/Adapter.php @@ -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'])); }); } From 284fd8e0a2986c4c5f3964146da471b0e0b1aab3 Mon Sep 17 00:00:00 2001 From: Cees-Jan Kiewiet Date: Fri, 15 Jun 2018 08:03:39 +0200 Subject: [PATCH 2/2] Test the error coming from the pool is pickup and passed up through the promises to the callee, via @clue at https://github.com/reactphp/filesystem/pull/25#discussion_r191571410 --- tests/ChildProcess/AdapterTest.php | 14 ++++++ tests/ChildProcess/PoolRpcErrorMock.php | 44 +++++++++++++++++++ .../ChildProcess/PoolRpcErrorMockFactory.php | 32 ++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 tests/ChildProcess/PoolRpcErrorMock.php create mode 100644 tests/ChildProcess/PoolRpcErrorMockFactory.php diff --git a/tests/ChildProcess/AdapterTest.php b/tests/ChildProcess/AdapterTest.php index 3a27d5be..8fbbf83d 100644 --- a/tests/ChildProcess/AdapterTest.php +++ b/tests/ChildProcess/AdapterTest.php @@ -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; @@ -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); + } } diff --git a/tests/ChildProcess/PoolRpcErrorMock.php b/tests/ChildProcess/PoolRpcErrorMock.php new file mode 100644 index 00000000..d029a836 --- /dev/null +++ b/tests/ChildProcess/PoolRpcErrorMock.php @@ -0,0 +1,44 @@ + [ + '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 []; + } +} diff --git a/tests/ChildProcess/PoolRpcErrorMockFactory.php b/tests/ChildProcess/PoolRpcErrorMockFactory.php new file mode 100644 index 00000000..4ff77615 --- /dev/null +++ b/tests/ChildProcess/PoolRpcErrorMockFactory.php @@ -0,0 +1,32 @@ +