Skip to content

Commit

Permalink
--functional: wait for wrapper to end its operations before destroi…
Browse files Browse the repository at this point in the history
…ng the chile process (#787)
  • Loading branch information
Slamdunk authored Aug 29, 2023
1 parent 4d7ad5b commit 7f372b5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 10 deletions.
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 4 additions & 4 deletions src/WrapperRunner/WrapperRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
Expand Down
16 changes: 16 additions & 0 deletions test/Unit/WrapperRunner/WrapperRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 7f372b5

Please sign in to comment.