Files
archived-process/Tests/ErrorProcessInitiator.php
Cornel Cruceru 175925109f [Process] Fixed inconsistent test
Sometimes the process no longer appears to be running when the signal is sent which causes a LogicException to be thrown.
This doesn't appear to be consistent and I can reproduce it randomly on my local machine. To avoid having tests fail at random
I decided that it's better to send the signal only if the process is still marked as running.
2024-01-13 01:09:26 +02:00

37 lines
1.0 KiB
PHP

<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Component\Process\Tests;
use Symfony\Component\Process\Exception\ProcessTimedOutException;
use Symfony\Component\Process\Process;
require is_file(\dirname(__DIR__).'/vendor/autoload.php') ? \dirname(__DIR__).'/vendor/autoload.php' : \dirname(__DIR__, 5).'/vendor/autoload.php';
['e' => $php] = getopt('e:') + ['e' => 'php'];
try {
$process = new Process([$php, '-r', "echo 'ready'; trigger_error('error', E_USER_ERROR);"]);
$process->start();
$process->setTimeout(0.5);
while (!str_contains($process->getOutput(), 'ready')) {
usleep(1000);
}
$process->isRunning() && $process->signal(\SIGSTOP);
$process->wait();
return $process->getExitCode();
} catch (ProcessTimedOutException $t) {
echo $t->getMessage().\PHP_EOL;
return 1;
}