Skip to content

Commit

Permalink
bug #50954 [PhpUnitBridge] Kill the last concurrent process when it s…
Browse files Browse the repository at this point in the history
…tales for more than 60s (nicolas-grekas)

This PR was merged into the 5.4 branch.

Discussion
----------

[PhpUnitBridge] Kill the last concurrent process when it stales for more than 60s

| Q             | A
| ------------- | ---
| Branch?       | 5.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

Update PhpUnitBridge so that it kills the last phpunit process when it's stuck. Apparently this happens sometimes, for an undetermined reason (Windows). This also skips a blocking test on Windows.

Commits
-------

036b6a9 [PhpUnitBridge] Kill the last concurrent process when it stales for more than 60s
  • Loading branch information
nicolas-grekas committed Jul 12, 2023
2 parents 99ced16 + 036b6a9 commit de7ab4d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
23 changes: 23 additions & 0 deletions src/Symfony/Bridge/PhpUnit/bin/simple-phpunit.php
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,9 @@ class_exists(\SymfonyExcludeListSimplePhpunit::class, false) && PHPUnit\Util\Bla
}
}

$lastOutput = null;
$lastOutputTime = null;

while ($runningProcs) {
usleep(300000);
$terminatedProcs = [];
Expand All @@ -410,6 +413,26 @@ class_exists(\SymfonyExcludeListSimplePhpunit::class, false) && PHPUnit\Util\Bla
}
}

if (!$terminatedProcs && 1 === count($runningProcs)) {
$component = key($runningProcs);

$output = file_get_contents("$component/phpunit.stdout");
$output .= file_get_contents("$component/phpunit.stderr");

if ($lastOutput !== $output) {
$lastOutput = $output;
$lastOutputTime = microtime(true);
} elseif (microtime(true) - $lastOutputTime > 60) {
echo "\033[41mTimeout\033[0m $component\n\n";

if ('\\' === \DIRECTORY_SEPARATOR) {
exec(sprintf('taskkill /F /T /PID %d 2>&1', $procStatus['pid']), $output, $exitCode);
} else {
proc_terminate(current($runningProcs));
}
}
}

foreach ($terminatedProcs as $component => $procStatus) {
foreach (['out', 'err'] as $file) {
$file = "$component/phpunit.std$file";
Expand Down
16 changes: 9 additions & 7 deletions src/Symfony/Component/Process/Tests/ProcessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ public function testInvalidCwd()
$cmd->run();
}

/**
* @group transient-on-windows
*/
public function testThatProcessDoesNotThrowWarningDuringRun()
{
if ('\\' === \DIRECTORY_SEPARATOR) {
$this->markTestSkipped('This test is transient on Windows');
}
@trigger_error('Test Error', \E_USER_NOTICE);
$process = $this->getProcessForCode('sleep(3)');
$process->run();
Expand Down Expand Up @@ -130,12 +130,11 @@ public function testStopWithTimeoutIsActuallyWorking()
$this->assertLessThan(15, microtime(true) - $start);
}

/**
* @group transient-on-windows
*/
public function testWaitUntilSpecificOutput()
{
if ('\\' === \DIRECTORY_SEPARATOR) {
$this->markTestIncomplete('This test is too transient on Windows, help wanted to improve it');
}

$p = $this->getProcess([self::$phpBin, __DIR__.'/KillableProcessWithOutput.php']);
$p->start();

Expand Down Expand Up @@ -1538,6 +1537,9 @@ public function testEnvCaseInsensitiveOnWindows()
}
}

/**
* @group transient-on-windows
*/
public function testNotTerminableInputPipe()
{
$process = $this->getProcess('echo foo');
Expand Down

0 comments on commit de7ab4d

Please sign in to comment.