Skip to content

Commit 284fd8e

Browse files
committed
Test the error coming from the pool is pickup and passed up through the promises to the callee, via @clue at #25 (comment)
1 parent 053764e commit 284fd8e

File tree

3 files changed

+90
-0
lines changed

3 files changed

+90
-0
lines changed

tests/ChildProcess/AdapterTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace React\Tests\Filesystem\ChildProcess;
44

5+
use React\EventLoop\Factory;
56
use React\Filesystem\ChildProcess\Adapter;
67
use React\Filesystem\Filesystem;
78
use React\Filesystem\Node\NodeInterface;
@@ -324,4 +325,17 @@ public function testLs()
324325
]);
325326
$this->assertTrue($calledOnData);
326327
}
328+
329+
public function testErrorFromPool()
330+
{
331+
$this->setExpectedException('\Exception', 'oops');
332+
333+
$loop = Factory::create();
334+
$adapter = new Adapter($loop, [
335+
'pool' => [
336+
'class' => 'React\Tests\Filesystem\ChildProcess\PoolRpcErrorMockFactory',
337+
],
338+
]);
339+
$this->await($adapter->touch('foo.bar'), $loop, 1);
340+
}
327341
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace React\Tests\Filesystem\ChildProcess;
4+
5+
use Evenement\EventEmitter;
6+
use React\EventLoop\LoopInterface;
7+
use React\Promise\FulfilledPromise;
8+
use React\Promise\RejectedPromise;
9+
use WyriHaximus\React\ChildProcess\Messenger\Messages\Message;
10+
use WyriHaximus\React\ChildProcess\Messenger\Messages\Rpc;
11+
use WyriHaximus\React\ChildProcess\Pool\PoolInterface;
12+
use WyriHaximus\React\ChildProcess\Pool\ProcessCollectionInterface;
13+
14+
final class PoolRpcErrorMock extends EventEmitter implements PoolInterface
15+
{
16+
public function __construct(ProcessCollectionInterface $processCollection, LoopInterface $loop, array $options = [])
17+
{
18+
// void
19+
}
20+
21+
public function rpc(Rpc $message)
22+
{
23+
return new RejectedPromise([
24+
'error' => [
25+
'message' => 'oops',
26+
],
27+
]);
28+
}
29+
30+
public function message(Message $message)
31+
{
32+
return new FulfilledPromise();
33+
}
34+
35+
public function terminate(Message $message, $timeout = 5, $signal = null)
36+
{
37+
return new FulfilledPromise();
38+
}
39+
40+
public function info()
41+
{
42+
return [];
43+
}
44+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace React\Tests\Filesystem\ChildProcess;
4+
5+
use React\ChildProcess\Process;
6+
use React\EventLoop\Factory;
7+
use React\EventLoop\LoopInterface;
8+
use React\Promise\FulfilledPromise;
9+
use WyriHaximus\React\ChildProcess\Pool\PoolFactoryInterface;
10+
use WyriHaximus\React\ChildProcess\Pool\ProcessCollection\Single;
11+
12+
final class PoolRpcErrorMockFactory implements PoolFactoryInterface
13+
{
14+
public static function create(Process $childProcess, LoopInterface $loop, array $options = [])
15+
{
16+
return new FulfilledPromise(new PoolRpcErrorMock(
17+
new Single(function () {}),
18+
Factory::create(),
19+
[]
20+
));
21+
}
22+
23+
public static function createFromClass($class, LoopInterface $loop, array $options = [])
24+
{
25+
return new FulfilledPromise(new PoolRpcErrorMock(
26+
new Single(function () {}),
27+
Factory::create(),
28+
[]
29+
));
30+
}
31+
32+
}

0 commit comments

Comments
 (0)