mirror of
https://github.com/danog/file.git
synced 2024-11-26 20:04:51 +01:00
Close handle after each test; Fix pool startup and shutdown
This commit is contained in:
parent
d32ab898ba
commit
5e5c8ab85b
@ -56,6 +56,8 @@ abstract class HandleTest extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->assertSame((yield file\get(__FILE__)), $contents);
|
$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);
|
$expected = \substr((yield file\get(__FILE__)), 0, 20);
|
||||||
$this->assertSame($expected, $contents);
|
$this->assertSame($expected, $contents);
|
||||||
|
|
||||||
|
yield $handle->close();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,6 +90,8 @@ abstract class HandleTest extends TestCase {
|
|||||||
$this->assertSame(100, $handle->tell());
|
$this->assertSame(100, $handle->tell());
|
||||||
$expected = \substr((yield file\get(__FILE__)), 10, 90);
|
$expected = \substr((yield file\get(__FILE__)), 10, 90);
|
||||||
$this->assertSame($expected, $chunk);
|
$this->assertSame($expected, $chunk);
|
||||||
|
|
||||||
|
yield $handle->close();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,8 +100,12 @@ abstract class HandleTest extends TestCase {
|
|||||||
*/
|
*/
|
||||||
public function testSeekThrowsOnInvalidWhence() {
|
public function testSeekThrowsOnInvalidWhence() {
|
||||||
$this->lRun(function () {
|
$this->lRun(function () {
|
||||||
$handle = (yield file\open(__FILE__, "r"));
|
try {
|
||||||
yield $handle->seek(0, 99999);
|
$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());
|
$this->assertSame(10, $handle->tell());
|
||||||
yield $handle->seek(-10, \SEEK_CUR);
|
yield $handle->seek(-10, \SEEK_CUR);
|
||||||
$this->assertSame(0, $handle->tell());
|
$this->assertSame(0, $handle->tell());
|
||||||
|
yield $handle->close();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -117,6 +128,7 @@ abstract class HandleTest extends TestCase {
|
|||||||
$this->assertSame(0, $handle->tell());
|
$this->assertSame(0, $handle->tell());
|
||||||
yield $handle->seek(-10, \SEEK_END);
|
yield $handle->seek(-10, \SEEK_END);
|
||||||
$this->assertSame($size - 10, $handle->tell());
|
$this->assertSame($size - 10, $handle->tell());
|
||||||
|
yield $handle->close();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,6 +136,7 @@ abstract class HandleTest extends TestCase {
|
|||||||
$this->lRun(function () {
|
$this->lRun(function () {
|
||||||
$handle = (yield file\open(__FILE__, "r"));
|
$handle = (yield file\open(__FILE__, "r"));
|
||||||
$this->assertSame(__FILE__, $handle->path());
|
$this->assertSame(__FILE__, $handle->path());
|
||||||
|
yield $handle->close();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,6 +144,7 @@ abstract class HandleTest extends TestCase {
|
|||||||
$this->lRun(function () {
|
$this->lRun(function () {
|
||||||
$handle = (yield file\open(__FILE__, "r"));
|
$handle = (yield file\open(__FILE__, "r"));
|
||||||
$this->assertSame("r", $handle->mode());
|
$this->assertSame("r", $handle->mode());
|
||||||
|
yield $handle->close();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,28 +2,21 @@
|
|||||||
|
|
||||||
namespace Amp\File\Test;
|
namespace Amp\File\Test;
|
||||||
|
|
||||||
|
use Amp\File;
|
||||||
use Amp\Loop;
|
use Amp\Loop;
|
||||||
use Amp\Parallel\Worker\DefaultPool;
|
use Amp\Parallel\Worker\DefaultPool;
|
||||||
|
use function Amp\call;
|
||||||
|
|
||||||
class ParallelDriverTest extends DriverTest {
|
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) {
|
protected function lRun(callable $cb) {
|
||||||
\Amp\Loop::run(function() use ($cb) {
|
Loop::run(function() use ($cb) {
|
||||||
\Amp\File\filesystem(new \Amp\File\ParallelDriver($this->pool));
|
$pool = new DefaultPool;
|
||||||
\Amp\Promise\rethrow(new \Amp\Coroutine($cb()));
|
$pool->start();
|
||||||
|
|
||||||
|
File\filesystem(new File\ParallelDriver($pool));
|
||||||
|
yield call($cb);
|
||||||
|
|
||||||
|
yield $pool->shutdown();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,28 +2,21 @@
|
|||||||
|
|
||||||
namespace Amp\File\Test;
|
namespace Amp\File\Test;
|
||||||
|
|
||||||
|
use Amp\File;
|
||||||
use Amp\Loop;
|
use Amp\Loop;
|
||||||
use Amp\Parallel\Worker\DefaultPool;
|
use Amp\Parallel\Worker\DefaultPool;
|
||||||
|
use function Amp\call;
|
||||||
|
|
||||||
class ParallelHandleTest extends HandleTest {
|
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) {
|
protected function lRun(callable $cb) {
|
||||||
\Amp\Loop::run(function() use ($cb) {
|
Loop::run(function() use ($cb) {
|
||||||
\Amp\File\filesystem(new \Amp\File\ParallelDriver($this->pool));
|
$pool = new DefaultPool;
|
||||||
\Amp\Promise\rethrow(new \Amp\Coroutine($cb()));
|
$pool->start();
|
||||||
|
|
||||||
|
File\filesystem(new File\ParallelDriver($pool));
|
||||||
|
yield call($cb);
|
||||||
|
|
||||||
|
yield $pool->shutdown();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user