Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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