mirror of
https://github.com/amphp/parallel.git
synced 2025-01-17 20:58:36 +01:00
Improve parameter order in DefaultWorkerFactory
This commit is contained in:
parent
6104d15769
commit
9a67f8f272
@ -23,9 +23,9 @@ final class DefaultWorkerFactory implements WorkerFactory
|
||||
* @throws \Error If the given class name does not exist or does not implement {@see Cache}.
|
||||
*/
|
||||
public function __construct(
|
||||
private string $cacheClass = LocalCache::class,
|
||||
private ?string $bootstrapPath = null,
|
||||
?ContextFactory $contextFactory = null,
|
||||
private string $cacheClass = LocalCache::class,
|
||||
) {
|
||||
$this->contextFactory = $contextFactory ?? contextFactory();
|
||||
|
||||
|
@ -14,7 +14,13 @@ use Revolt\EventLoop;
|
||||
|
||||
abstract class AbstractPoolTest extends AbstractWorkerTest
|
||||
{
|
||||
public function testShutdownShouldReturnSameResult()
|
||||
public function testNotIdleOnSubmit(): void
|
||||
{
|
||||
// Skip, because workers ARE idle even after submitting a job
|
||||
$this->expectNotToPerformAssertions();
|
||||
}
|
||||
|
||||
public function testShutdownShouldReturnSameResult(): void
|
||||
{
|
||||
$pool = $this->createPool();
|
||||
|
||||
@ -24,7 +30,7 @@ abstract class AbstractPoolTest extends AbstractWorkerTest
|
||||
self::assertSame($result, $pool->shutdown());
|
||||
}
|
||||
|
||||
public function testPullShouldThrowStatusError()
|
||||
public function testPullShouldThrowStatusError(): void
|
||||
{
|
||||
$this->expectException(StatusError::class);
|
||||
$this->expectExceptionMessage('shut down');
|
||||
@ -44,7 +50,7 @@ abstract class AbstractPoolTest extends AbstractWorkerTest
|
||||
self::assertEquals(17, $pool->getLimit());
|
||||
}
|
||||
|
||||
public function testWorkersIdleOnStart()
|
||||
public function testWorkersIdleOnStart(): void
|
||||
{
|
||||
$pool = $this->createPool();
|
||||
|
||||
@ -53,7 +59,7 @@ abstract class AbstractPoolTest extends AbstractWorkerTest
|
||||
$pool->shutdown();
|
||||
}
|
||||
|
||||
public function testGet()
|
||||
public function testGet(): void
|
||||
{
|
||||
$pool = $this->createPool();
|
||||
|
||||
@ -70,7 +76,7 @@ abstract class AbstractPoolTest extends AbstractWorkerTest
|
||||
$worker->kill();
|
||||
}
|
||||
|
||||
public function testBusyPool()
|
||||
public function testBusyPool(): void
|
||||
{
|
||||
$pool = $this->createPool(2);
|
||||
|
||||
@ -102,7 +108,7 @@ abstract class AbstractPoolTest extends AbstractWorkerTest
|
||||
$this->createPool(-1);
|
||||
}
|
||||
|
||||
public function testCleanGarbageCollection()
|
||||
public function testCleanGarbageCollection(): void
|
||||
{
|
||||
// See https://github.com/amphp/parallel-functions/issues/5
|
||||
for ($i = 0; $i < 3; $i++) {
|
||||
@ -118,7 +124,7 @@ abstract class AbstractPoolTest extends AbstractWorkerTest
|
||||
}
|
||||
}
|
||||
|
||||
public function testPooledKill()
|
||||
public function testPooledKill(): void
|
||||
{
|
||||
EventLoop::setErrorHandler(function (\Throwable $exception): void {
|
||||
$this->assertStringContainsString("Worker in pool crashed", $exception->getMessage());
|
||||
@ -152,9 +158,9 @@ abstract class AbstractPoolTest extends AbstractWorkerTest
|
||||
?string $autoloadPath = null
|
||||
): WorkerPool {
|
||||
$factory = new DefaultWorkerFactory(
|
||||
cacheClass: $cacheClass,
|
||||
bootstrapPath: $autoloadPath,
|
||||
contextFactory: $this->createContextFactory(),
|
||||
cacheClass: $cacheClass,
|
||||
);
|
||||
|
||||
return new DefaultWorkerPool($max, $factory);
|
||||
|
@ -352,9 +352,9 @@ abstract class AbstractWorkerTest extends AsyncTestCase
|
||||
protected function createWorker(string $cacheClass = LocalCache::class, ?string $autoloadPath = null): Worker
|
||||
{
|
||||
$factory = new DefaultWorkerFactory(
|
||||
cacheClass: $cacheClass,
|
||||
bootstrapPath: $autoloadPath,
|
||||
contextFactory: $this->createContextFactory(),
|
||||
cacheClass: $cacheClass,
|
||||
);
|
||||
|
||||
return $factory->create();
|
||||
|
@ -14,7 +14,7 @@ class DefaultWorkerFactoryTest extends AsyncTestCase
|
||||
$this->expectException(\Error::class);
|
||||
$this->expectExceptionMessage("Invalid cache class name 'Invalid'");
|
||||
|
||||
$factory = new DefaultWorkerFactory("Invalid");
|
||||
new DefaultWorkerFactory(cacheClass: "Invalid");
|
||||
}
|
||||
|
||||
public function testNonCacheClassName(): void
|
||||
@ -22,7 +22,7 @@ class DefaultWorkerFactoryTest extends AsyncTestCase
|
||||
$this->expectException(\Error::class);
|
||||
$this->expectExceptionMessage(\sprintf("does not implement '%s'", Cache::class));
|
||||
|
||||
$factory = new DefaultWorkerFactory(DefaultWorkerFactory::class);
|
||||
new DefaultWorkerFactory(cacheClass: DefaultWorkerFactory::class);
|
||||
}
|
||||
|
||||
public function testCreate(): void
|
||||
@ -34,9 +34,9 @@ class DefaultWorkerFactoryTest extends AsyncTestCase
|
||||
$worker->shutdown();
|
||||
}
|
||||
|
||||
public function testAutoloading()
|
||||
public function testAutoloading(): void
|
||||
{
|
||||
$factory = new DefaultWorkerFactory(bootstrapPath: __DIR__ . '/Fixtures/custom-bootstrap.php');
|
||||
$factory = new DefaultWorkerFactory(__DIR__ . '/Fixtures/custom-bootstrap.php');
|
||||
|
||||
$worker = $factory->create();
|
||||
|
||||
@ -45,12 +45,12 @@ class DefaultWorkerFactoryTest extends AsyncTestCase
|
||||
$worker->shutdown();
|
||||
}
|
||||
|
||||
public function testInvalidAutoloaderPath()
|
||||
public function testInvalidAutoloaderPath(): void
|
||||
{
|
||||
$this->expectException(\Error::class);
|
||||
$this->expectExceptionMessage('No file found at bootstrap path given');
|
||||
|
||||
$factory = new DefaultWorkerFactory(bootstrapPath: __DIR__ . '/Fixtures/not-found.php');
|
||||
$factory = new DefaultWorkerFactory(__DIR__ . '/Fixtures/not-found.php');
|
||||
|
||||
$worker = $factory->create();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user