1
0
mirror of https://github.com/danog/file.git synced 2024-12-04 10:17:52 +01:00
file/test/Driver/ParallelFileTest.php

55 lines
1.2 KiB
PHP
Raw Normal View History

2020-06-30 21:45:09 +02:00
<?php
namespace Amp\File\Test\Driver;
use Amp\File;
use Amp\File\Driver\ParallelDriver;
use Amp\File\Test\AsyncFileTest;
use Amp\Parallel\Worker\DefaultPool;
use Amp\Parallel\Worker\Pool;
class ParallelFileTest extends AsyncFileTest
{
2020-10-08 16:23:44 +02:00
private const DEFAULT_WORKER_LIMIT = 8;
2020-06-30 21:45:09 +02:00
2020-10-08 16:23:44 +02:00
private Pool $pool;
protected function createDriver(int $workerLimit = self::DEFAULT_WORKER_LIMIT): File\Driver
2020-06-30 21:45:09 +02:00
{
$this->pool = new DefaultPool;
2020-10-08 16:23:44 +02:00
return new ParallelDriver($this->pool, $workerLimit);
2020-06-30 21:45:09 +02:00
}
protected function tearDownAsync(): void
{
$this->pool->shutdown();
}
2020-10-08 16:23:44 +02:00
public function getWorkerLimits(): iterable
{
return \array_map(fn(int $count): array => [$count], \range(4, 16, 4));
}
/**
* @dataProvider getWorkerLimits
*/
public function testMultipleOpenFiles(int $maxCount)
{
$driver = $this->createDriver($maxCount);
$files = [];
for ($i = 0; $i < $maxCount * 2; ++$i) {
$files[] = $driver->openFile(__FILE__, 'r');
}
try {
$this->assertSame($maxCount, $this->pool->getWorkerCount());
} finally {
foreach ($files as $file) {
$file->close();
}
}
}
2020-06-30 21:45:09 +02:00
}