Skip to content

Commit 3b82b22

Browse files
committed
Test runtime::kill && close methods
1 parent 5e1b13d commit 3b82b22

File tree

4 files changed

+107
-2
lines changed

4 files changed

+107
-2
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
},
1818
"require-dev": {
1919
"thecodingmachine/safe": "^0.1.16",
20-
"wyrihaximus/async-test-utilities": "^1.1"
20+
"wyrihaximus/async-test-utilities": "^1.1",
21+
"wyrihaximus/ticking-promise": "^1.6"
2122
},
2223
"config": {
2324
"platform": {

composer.lock

Lines changed: 48 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpstan.neon

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
parameters:
22
ignoreErrors:
33
- '#Do not throw the \\Exception base class. Instead, extend the \\Exception base class. More info: http:\/\/bit.ly\/subtypeexception#'
4+
- '#Invalid type Throwable|null to throw.#'
5+
- '#Thrown exceptions in a catch block must bundle the previous exception \(see throw statement line 88\). More info: http:\/\/bit.ly\/bundleexception#'
6+
- '#Thrown exceptions in a catch block must bundle the previous exception \(see throw statement line 114\). More info: http:\/\/bit.ly\/bundleexception#'
47

58
includes:
69
- vendor/wyrihaximus/async-test-utilities/rules.neon

tests/RuntimeTest.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
use WyriHaximus\AsyncTestUtilities\AsyncTestCase;
88
use WyriHaximus\React\Parallel\FutureToPromiseConverter;
99
use WyriHaximus\React\Parallel\Runtime;
10+
use parallel\Runtime\Error\Closed;
1011
use function Safe\sleep;
12+
use function WyriHaximus\React\timedPromise;
1113

1214
/**
1315
* @internal
@@ -60,4 +62,56 @@ public function testConvertFailure(): void
6062

6163
self::assertSame(3, $three);
6264
}
65+
66+
public function testWeClosedTheThread(): void
67+
{
68+
self::expectException(Closed::class);
69+
self::expectExceptionMessage('Runtime closed');
70+
71+
$loop = Factory::create();
72+
$runtime = new Runtime(new FutureToPromiseConverter($loop), \dirname(__DIR__) . '/vendor/autoload.php');
73+
74+
/** @var ExtendedPromiseInterface $promise */
75+
$promise = timedPromise($loop, 1, $runtime)->then(function (Runtime $runtime) {
76+
return $runtime->run(function (): int {
77+
return 3;
78+
});
79+
});
80+
81+
$loop->futureTick(function () use ($runtime): void {
82+
$runtime->close();
83+
});
84+
85+
try {
86+
$this->await($promise, $loop, 3.3);
87+
} catch (\Exception $exception) {
88+
throw $exception->getPrevious();
89+
}
90+
}
91+
92+
public function testWeKilledTheThread(): void
93+
{
94+
self::expectException(Closed::class);
95+
self::expectExceptionMessage('Runtime closed');
96+
97+
$loop = Factory::create();
98+
$runtime = new Runtime(new FutureToPromiseConverter($loop), \dirname(__DIR__) . '/vendor/autoload.php');
99+
100+
/** @var ExtendedPromiseInterface $promise */
101+
$promise = timedPromise($loop, 1, $runtime)->then(function (Runtime $runtime) {
102+
return $runtime->run(function (): int {
103+
return 3;
104+
});
105+
});
106+
107+
$loop->futureTick(function () use ($runtime): void {
108+
$runtime->kill();
109+
});
110+
111+
try {
112+
$this->await($promise, $loop, 3.3);
113+
} catch (\Exception $exception) {
114+
throw $exception->getPrevious();
115+
}
116+
}
63117
}

0 commit comments

Comments
 (0)