From 036b6a99abb2d9f4332318f15854d8be9381965f Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Wed, 12 Jul 2023 13:45:09 +0200 Subject: [PATCH] [PhpUnitBridge] Kill the last concurrent process when it stales for more than 60s --- .../Bridge/PhpUnit/bin/simple-phpunit.php | 23 +++++++++++++++++++ .../Component/Process/Tests/ProcessTest.php | 16 +++++++------ 2 files changed, 32 insertions(+), 7 deletions(-) diff --git a/src/Symfony/Bridge/PhpUnit/bin/simple-phpunit.php b/src/Symfony/Bridge/PhpUnit/bin/simple-phpunit.php index 5a1ba44ef0010..bc251877d7cdf 100644 --- a/src/Symfony/Bridge/PhpUnit/bin/simple-phpunit.php +++ b/src/Symfony/Bridge/PhpUnit/bin/simple-phpunit.php @@ -398,6 +398,9 @@ class_exists(\SymfonyExcludeListSimplePhpunit::class, false) && PHPUnit\Util\Bla } } + $lastOutput = null; + $lastOutputTime = null; + while ($runningProcs) { usleep(300000); $terminatedProcs = []; @@ -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"; diff --git a/src/Symfony/Component/Process/Tests/ProcessTest.php b/src/Symfony/Component/Process/Tests/ProcessTest.php index 36acf02a7cd6b..6e6ee8a41a029 100644 --- a/src/Symfony/Component/Process/Tests/ProcessTest.php +++ b/src/Symfony/Component/Process/Tests/ProcessTest.php @@ -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(); @@ -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(); @@ -1538,6 +1537,9 @@ public function testEnvCaseInsensitiveOnWindows() } } + /** + * @group transient-on-windows + */ public function testNotTerminableInputPipe() { $process = $this->getProcess('echo foo');