2016-12-30 03:59:59 +01:00
|
|
|
<?php
|
2016-08-30 21:05:14 +02:00
|
|
|
|
|
|
|
namespace Amp\File\Test;
|
|
|
|
|
2017-05-18 17:31:20 +02:00
|
|
|
use Amp\File;
|
2017-05-18 05:59:17 +02:00
|
|
|
use Amp\Loop;
|
2016-08-30 21:05:14 +02:00
|
|
|
use Amp\Parallel\Worker\DefaultPool;
|
2017-05-18 17:31:20 +02:00
|
|
|
use function Amp\call;
|
2016-08-30 21:05:14 +02:00
|
|
|
|
2017-06-20 07:06:12 +02:00
|
|
|
class ParallelHandleTest extends AsyncHandleTest {
|
2017-06-17 01:12:42 +02:00
|
|
|
protected function execute(callable $cb) {
|
2017-06-17 23:41:57 +02:00
|
|
|
Loop::run(function () use ($cb) {
|
2017-05-18 17:31:20 +02:00
|
|
|
$pool = new DefaultPool;
|
|
|
|
$pool->start();
|
2017-05-18 05:59:17 +02:00
|
|
|
|
2017-05-18 17:31:20 +02:00
|
|
|
File\filesystem(new File\ParallelDriver($pool));
|
|
|
|
yield call($cb);
|
2017-05-18 05:59:17 +02:00
|
|
|
|
2017-05-18 17:31:20 +02:00
|
|
|
yield $pool->shutdown();
|
2016-08-30 21:05:14 +02:00
|
|
|
});
|
|
|
|
}
|
2017-06-20 07:06:12 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException \Amp\File\PendingOperationError
|
|
|
|
*/
|
|
|
|
public function testSimultaneousSeeks() {
|
|
|
|
$this->execute(function () {
|
|
|
|
/** @var \Amp\File\Handle $handle */
|
|
|
|
$handle = yield File\open(__FILE__, "r");
|
|
|
|
|
|
|
|
$promise1 = $handle->seek(0);
|
|
|
|
$promise2 = $handle->seek(10);
|
|
|
|
|
|
|
|
$this->assertSame(0, yield $promise1);
|
|
|
|
|
|
|
|
yield $promise2;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException \Amp\File\PendingOperationError
|
|
|
|
*/
|
|
|
|
public function testReadWhileSeeking() {
|
|
|
|
$this->execute(function () {
|
|
|
|
/** @var \Amp\File\Handle $handle */
|
|
|
|
$handle = yield File\open(__FILE__, "r");
|
|
|
|
|
|
|
|
$promise1 = $handle->seek(0);
|
|
|
|
$promise2 = $handle->read();
|
|
|
|
|
|
|
|
$this->assertSame(0, yield $promise1);
|
|
|
|
|
|
|
|
yield $promise2;
|
|
|
|
});
|
|
|
|
}
|
2016-08-30 21:05:14 +02:00
|
|
|
}
|