|
7 | 7 | use WyriHaximus\AsyncTestUtilities\AsyncTestCase;
|
8 | 8 | use WyriHaximus\React\Parallel\FutureToPromiseConverter;
|
9 | 9 | use WyriHaximus\React\Parallel\Runtime;
|
| 10 | +use parallel\Runtime\Error\Closed; |
10 | 11 | use function Safe\sleep;
|
| 12 | +use function WyriHaximus\React\timedPromise; |
11 | 13 |
|
12 | 14 | /**
|
13 | 15 | * @internal
|
@@ -60,4 +62,56 @@ public function testConvertFailure(): void
|
60 | 62 |
|
61 | 63 | self::assertSame(3, $three);
|
62 | 64 | }
|
| 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 | + } |
63 | 117 | }
|
0 commit comments