From 4c3c93e46a0108f04990352b0d084ded2ec2cc17 Mon Sep 17 00:00:00 2001 From: Aaron Piotrowski Date: Sat, 27 Oct 2018 11:16:10 -0500 Subject: [PATCH] Fix DefaultPool::shutdown() Forgot to update this to match Worker::shutdown() behavior. --- lib/Worker/DefaultPool.php | 9 ++++++--- test/Worker/AbstractPoolTest.php | 10 +++------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/Worker/DefaultPool.php b/lib/Worker/DefaultPool.php index 7165cce..1e5efd8 100644 --- a/lib/Worker/DefaultPool.php +++ b/lib/Worker/DefaultPool.php @@ -35,6 +35,9 @@ final class DefaultPool implements Pool /** @var \Closure */ private $push; + /** @var \Amp\Promise|null */ + private $exitStatus; + /** * Creates a new worker pool. * @@ -162,8 +165,8 @@ final class DefaultPool implements Pool */ public function shutdown(): Promise { - if (!$this->isRunning()) { - throw new StatusError("The pool was shutdown"); + if ($this->exitStatus) { + return $this->exitStatus; } $this->running = false; @@ -175,7 +178,7 @@ final class DefaultPool implements Pool } } - return Promise\all($shutdowns); + return $this->exitStatus = Promise\all($shutdowns); } /** diff --git a/test/Worker/AbstractPoolTest.php b/test/Worker/AbstractPoolTest.php index 53f20c6..62f60d2 100644 --- a/test/Worker/AbstractPoolTest.php +++ b/test/Worker/AbstractPoolTest.php @@ -42,19 +42,15 @@ abstract class AbstractPoolTest extends TestCase }); } - /** - * @expectedException \Amp\Parallel\Context\StatusError - * @expectedExceptionMessage The pool was shutdown - */ - public function testShutdownShouldThrowStatusError() + public function testShutdownShouldReturnSameResult() { Loop::run(function () { $pool = $this->createPool(); $this->assertTrue($pool->isIdle()); - yield $pool->shutdown(); - yield $pool->shutdown(); + $result = yield $pool->shutdown(); + $this->assertSame($result, yield $pool->shutdown()); }); }