From 7f372b5bb59b4271adedc67d3129df29b84c4173 Mon Sep 17 00:00:00 2001 From: Filippo Tessarotto Date: Tue, 29 Aug 2023 09:47:39 +0200 Subject: [PATCH] `--functional`: wait for wrapper to end its operations before destroing the chile process (#787) --- composer.json | 12 ++++++------ src/WrapperRunner/WrapperRunner.php | 8 ++++---- test/Unit/WrapperRunner/WrapperRunnerTest.php | 16 ++++++++++++++++ 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/composer.json b/composer.json index 9e7946ae..dd803d70 100644 --- a/composer.json +++ b/composer.json @@ -43,19 +43,19 @@ "phpunit/php-code-coverage": "^10.1.3", "phpunit/php-file-iterator": "^4.0.2", "phpunit/php-timer": "^6.0", - "phpunit/phpunit": "^10.3.1", + "phpunit/phpunit": "^10.3.2", "sebastian/environment": "^6.0.1", - "symfony/console": "^6.3.2", - "symfony/process": "^6.3.2" + "symfony/console": "^6.3.4", + "symfony/process": "^6.3.4" }, "require-dev": { "ext-pcov": "*", "ext-posix": "*", "doctrine/coding-standard": "^12.0.0", "infection/infection": "^0.27.0", - "phpstan/phpstan": "^1.10.26", - "phpstan/phpstan-deprecation-rules": "^1.1.3", - "phpstan/phpstan-phpunit": "^1.3.13", + "phpstan/phpstan": "^1.10.32", + "phpstan/phpstan-deprecation-rules": "^1.1.4", + "phpstan/phpstan-phpunit": "^1.3.14", "phpstan/phpstan-strict-rules": "^1.5.1", "squizlabs/php_codesniffer": "^3.7.2", "symfony/filesystem": "^6.3.1" diff --git a/src/WrapperRunner/WrapperRunner.php b/src/WrapperRunner/WrapperRunner.php index 310e200a..3de6e498 100644 --- a/src/WrapperRunner/WrapperRunner.php +++ b/src/WrapperRunner/WrapperRunner.php @@ -237,11 +237,11 @@ private function startWorker(int $token): WrapperWorker private function destroyWorker(int $token): void { - // Mutation Testing tells us that the following `unset()` already destroys - // the `WrapperWorker`, which destroys the Symfony's `Process`, which - // automatically calls `Process::stop` within `Process::__destruct()`. - // But we prefer to have an explicit stops. $this->workers[$token]->stop(); + // We need to wait for ApplicationForWrapperWorker::end to end + while ($this->workers[$token]->isRunning()) { + usleep(self::CYCLE_SLEEP); + } unset($this->workers[$token]); } diff --git a/test/Unit/WrapperRunner/WrapperRunnerTest.php b/test/Unit/WrapperRunner/WrapperRunnerTest.php index 402ae7f2..5b740256 100644 --- a/test/Unit/WrapperRunner/WrapperRunnerTest.php +++ b/test/Unit/WrapperRunner/WrapperRunnerTest.php @@ -611,6 +611,22 @@ public function testFunctionalParallelization(): void self::assertSame(RunnerInterface::SUCCESS_EXIT, $runnerResult->exitCode); } + #[RequiresPhp('8.2')] + public function testFunctionalParallelizationWithJunitLogging(): void + { + $outputFile = $this->tmpDir . DIRECTORY_SEPARATOR . 'test-output.xml'; + + $this->bareOptions['path'] = $this->fixture('function_parallelization_tests'); + $this->bareOptions['--processes'] = '1'; + $this->bareOptions['--functional'] = true; + $this->bareOptions['--max-batch-size'] = 1; + $this->bareOptions['--log-junit'] = $outputFile; + + $runnerResult = $this->runRunner(); + self::assertStringContainsString('.......', $runnerResult->output); + self::assertSame(RunnerInterface::SUCCESS_EXIT, $runnerResult->exitCode); + } + public function testProcessIsolation(): void { $this->bareOptions['path'] = $this->fixture('process_isolation' . DIRECTORY_SEPARATOR . 'FooTest.php');