diff --git a/test/HandleTest.php b/test/HandleTest.php index 517c5b8..2fcfe0c 100644 --- a/test/HandleTest.php +++ b/test/HandleTest.php @@ -56,6 +56,8 @@ abstract class HandleTest extends TestCase { } $this->assertSame((yield file\get(__FILE__)), $contents); + + yield $handle->close(); }); } @@ -73,6 +75,8 @@ abstract class HandleTest extends TestCase { $expected = \substr((yield file\get(__FILE__)), 0, 20); $this->assertSame($expected, $contents); + + yield $handle->close(); }); } @@ -86,6 +90,8 @@ abstract class HandleTest extends TestCase { $this->assertSame(100, $handle->tell()); $expected = \substr((yield file\get(__FILE__)), 10, 90); $this->assertSame($expected, $chunk); + + yield $handle->close(); }); } @@ -94,8 +100,12 @@ abstract class HandleTest extends TestCase { */ public function testSeekThrowsOnInvalidWhence() { $this->lRun(function () { - $handle = (yield file\open(__FILE__, "r")); - yield $handle->seek(0, 99999); + try { + $handle = (yield file\open(__FILE__, "r")); + yield $handle->seek(0, 99999); + } finally { + yield $handle->close(); + } }); } @@ -107,6 +117,7 @@ abstract class HandleTest extends TestCase { $this->assertSame(10, $handle->tell()); yield $handle->seek(-10, \SEEK_CUR); $this->assertSame(0, $handle->tell()); + yield $handle->close(); }); } @@ -117,6 +128,7 @@ abstract class HandleTest extends TestCase { $this->assertSame(0, $handle->tell()); yield $handle->seek(-10, \SEEK_END); $this->assertSame($size - 10, $handle->tell()); + yield $handle->close(); }); } @@ -124,6 +136,7 @@ abstract class HandleTest extends TestCase { $this->lRun(function () { $handle = (yield file\open(__FILE__, "r")); $this->assertSame(__FILE__, $handle->path()); + yield $handle->close(); }); } @@ -131,6 +144,7 @@ abstract class HandleTest extends TestCase { $this->lRun(function () { $handle = (yield file\open(__FILE__, "r")); $this->assertSame("r", $handle->mode()); + yield $handle->close(); }); } diff --git a/test/ParallelDriverTest.php b/test/ParallelDriverTest.php index 5dc7723..8cdb5fc 100644 --- a/test/ParallelDriverTest.php +++ b/test/ParallelDriverTest.php @@ -2,28 +2,21 @@ namespace Amp\File\Test; +use Amp\File; use Amp\Loop; use Amp\Parallel\Worker\DefaultPool; +use function Amp\call; class ParallelDriverTest extends DriverTest { - /** @var \Amp\Parallel\Worker\Pool */ - private $pool; - - public function setUp() { - $this->pool = new DefaultPool; - $this->pool->start(); - } - - public function tearDown() { - Loop::run(function () { - yield $this->pool->shutdown(); - }); - } - protected function lRun(callable $cb) { - \Amp\Loop::run(function() use ($cb) { - \Amp\File\filesystem(new \Amp\File\ParallelDriver($this->pool)); - \Amp\Promise\rethrow(new \Amp\Coroutine($cb())); + Loop::run(function() use ($cb) { + $pool = new DefaultPool; + $pool->start(); + + File\filesystem(new File\ParallelDriver($pool)); + yield call($cb); + + yield $pool->shutdown(); }); } } diff --git a/test/ParallelHandleTest.php b/test/ParallelHandleTest.php index 6d98d42..cde0f47 100644 --- a/test/ParallelHandleTest.php +++ b/test/ParallelHandleTest.php @@ -2,28 +2,21 @@ namespace Amp\File\Test; +use Amp\File; use Amp\Loop; use Amp\Parallel\Worker\DefaultPool; +use function Amp\call; class ParallelHandleTest extends HandleTest { - /** @var \Amp\Parallel\Worker\Pool */ - private $pool; - - public function setUp() { - $this->pool = new DefaultPool; - $this->pool->start(); - } - - public function tearDown() { - Loop::run(function () { - yield $this->pool->shutdown(); - }); - } - protected function lRun(callable $cb) { - \Amp\Loop::run(function() use ($cb) { - \Amp\File\filesystem(new \Amp\File\ParallelDriver($this->pool)); - \Amp\Promise\rethrow(new \Amp\Coroutine($cb())); + Loop::run(function() use ($cb) { + $pool = new DefaultPool; + $pool->start(); + + File\filesystem(new File\ParallelDriver($pool)); + yield call($cb); + + yield $pool->shutdown(); }); } }