[Process] Avoid failure because of a slow process
See example of failure here https://travis-ci.org/symfony/symfony/jobs/20761834.
This commit is contained in:
parent
173f8c5fd2
commit
238565e93a
@ -29,6 +29,8 @@ class ProcessPipes
|
||||
/** @var Boolean */
|
||||
private $ttyMode;
|
||||
|
||||
const CHUNK_SIZE = 16384;
|
||||
|
||||
public function __construct($useFiles, $ttyMode)
|
||||
{
|
||||
$this->useFiles = (Boolean) $useFiles;
|
||||
@ -233,7 +235,7 @@ class ProcessPipes
|
||||
$data = '';
|
||||
$dataread = null;
|
||||
while (!feof($fileHandle)) {
|
||||
if (false !== $dataread = fread($fileHandle, 16392)) {
|
||||
if (false !== $dataread = fread($fileHandle, self::CHUNK_SIZE)) {
|
||||
$data .= $dataread;
|
||||
}
|
||||
}
|
||||
@ -291,7 +293,7 @@ class ProcessPipes
|
||||
$type = array_search($pipe, $this->pipes);
|
||||
|
||||
$data = '';
|
||||
while ($dataread = fread($pipe, 8192)) {
|
||||
while ($dataread = fread($pipe, self::CHUNK_SIZE)) {
|
||||
$data .= $dataread;
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,7 @@ namespace Symfony\Component\Process\Tests;
|
||||
|
||||
use Symfony\Component\Process\Process;
|
||||
use Symfony\Component\Process\Exception\RuntimeException;
|
||||
use Symfony\Component\Process\ProcessPipes;
|
||||
|
||||
/**
|
||||
* @author Robert Schönthal <seroscho@googlemail.com>
|
||||
@ -87,18 +88,20 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
|
||||
// has terminated so the internal pipes array is already empty. normally
|
||||
// the call to start() will not read any data as the process will not have
|
||||
// generated output, but this is non-deterministic so we must count it as
|
||||
// a possibility. therefore we need 2 * 8192 plus another byte which will
|
||||
// never be read.
|
||||
$expectedOutputSize = 16385;
|
||||
// a possibility. therefore we need 2 * ProcessPipes::CHUNK_SIZE plus
|
||||
// another byte which will never be read.
|
||||
$expectedOutputSize = ProcessPipes::CHUNK_SIZE * 2 + 2;
|
||||
|
||||
$code = sprintf('echo str_repeat(\'*\', %d);', $expectedOutputSize);
|
||||
$p = $this->getProcess(sprintf('php -r %s', escapeshellarg($code)));
|
||||
|
||||
$p->start();
|
||||
usleep(250000);
|
||||
// Let's wait enough time for process to finish...
|
||||
// Here we don't call Process::run or Process::wait to avoid any read of pipes
|
||||
usleep(500000);
|
||||
|
||||
if ($p->isRunning()) {
|
||||
$this->fail('Process execution did not complete in the required time frame');
|
||||
$this->markTestSkipped('Process execution did not complete in the required time frame');
|
||||
}
|
||||
|
||||
$o = $p->getOutput();
|
||||
|
Reference in New Issue
Block a user