Skip to content

Commit 238565e

Browse files
committed
[Process] Avoid failure because of a slow process
See example of failure here https://travis-ci.org/symfony/symfony/jobs/20761834.
1 parent 173f8c5 commit 238565e

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/Symfony/Component/Process/ProcessPipes.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ class ProcessPipes
2929
/** @var Boolean */
3030
private $ttyMode;
3131

32+
const CHUNK_SIZE = 16384;
33+
3234
public function __construct($useFiles, $ttyMode)
3335
{
3436
$this->useFiles = (Boolean) $useFiles;
@@ -233,7 +235,7 @@ private function readFileHandles($close = false)
233235
$data = '';
234236
$dataread = null;
235237
while (!feof($fileHandle)) {
236-
if (false !== $dataread = fread($fileHandle, 16392)) {
238+
if (false !== $dataread = fread($fileHandle, self::CHUNK_SIZE)) {
237239
$data .= $dataread;
238240
}
239241
}
@@ -291,7 +293,7 @@ private function readStreams($blocking, $close = false)
291293
$type = array_search($pipe, $this->pipes);
292294

293295
$data = '';
294-
while ($dataread = fread($pipe, 8192)) {
296+
while ($dataread = fread($pipe, self::CHUNK_SIZE)) {
295297
$data .= $dataread;
296298
}
297299

src/Symfony/Component/Process/Tests/AbstractProcessTest.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\Process\Process;
1515
use Symfony\Component\Process\Exception\RuntimeException;
16+
use Symfony\Component\Process\ProcessPipes;
1617

1718
/**
1819
* @author Robert Schönthal <[email protected]>
@@ -87,18 +88,20 @@ public function testAllOutputIsActuallyReadOnTermination()
8788
// has terminated so the internal pipes array is already empty. normally
8889
// the call to start() will not read any data as the process will not have
8990
// generated output, but this is non-deterministic so we must count it as
90-
// a possibility. therefore we need 2 * 8192 plus another byte which will
91-
// never be read.
92-
$expectedOutputSize = 16385;
91+
// a possibility. therefore we need 2 * ProcessPipes::CHUNK_SIZE plus
92+
// another byte which will never be read.
93+
$expectedOutputSize = ProcessPipes::CHUNK_SIZE * 2 + 2;
9394

9495
$code = sprintf('echo str_repeat(\'*\', %d);', $expectedOutputSize);
9596
$p = $this->getProcess(sprintf('php -r %s', escapeshellarg($code)));
9697

9798
$p->start();
98-
usleep(250000);
99+
// Let's wait enough time for process to finish...
100+
// Here we don't call Process::run or Process::wait to avoid any read of pipes
101+
usleep(500000);
99102

100103
if ($p->isRunning()) {
101-
$this->fail('Process execution did not complete in the required time frame');
104+
$this->markTestSkipped('Process execution did not complete in the required time frame');
102105
}
103106

104107
$o = $p->getOutput();

0 commit comments

Comments
 (0)