diff --git a/src/Worker/DefaultWorkerFactory.php b/src/Worker/DefaultWorkerFactory.php index 1d56db5..2e7fae1 100644 --- a/src/Worker/DefaultWorkerFactory.php +++ b/src/Worker/DefaultWorkerFactory.php @@ -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(); diff --git a/test/Worker/AbstractPoolTest.php b/test/Worker/AbstractPoolTest.php index fb9cebc..f20d6b1 100644 --- a/test/Worker/AbstractPoolTest.php +++ b/test/Worker/AbstractPoolTest.php @@ -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); diff --git a/test/Worker/AbstractWorkerTest.php b/test/Worker/AbstractWorkerTest.php index d1e2f4c..b5eed23 100644 --- a/test/Worker/AbstractWorkerTest.php +++ b/test/Worker/AbstractWorkerTest.php @@ -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(); diff --git a/test/Worker/DefaultWorkerFactoryTest.php b/test/Worker/DefaultWorkerFactoryTest.php index 7d9add1..80109fa 100644 --- a/test/Worker/DefaultWorkerFactoryTest.php +++ b/test/Worker/DefaultWorkerFactoryTest.php @@ -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();