mirror of
https://github.com/danog/file.git
synced 2024-11-26 11:54:54 +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);
|
||||
|
||||
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();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user