Skip to content

Commit

Permalink
[Process] Fix kill process on reached timeout using getIterator()
Browse files Browse the repository at this point in the history
  • Loading branch information
chalasr committed Nov 22, 2016
1 parent bd34b67 commit f96dc2e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Symfony/Component/Process/Process.php
Expand Up @@ -558,6 +558,7 @@ public function getIterator($flags = 0)
}

$this->readPipesForOutput(__FUNCTION__, $blocking);
$this->checkTimeout();
}
}

Expand Down
21 changes: 21 additions & 0 deletions src/Symfony/Component/Process/Tests/ProcessTest.php
Expand Up @@ -747,6 +747,27 @@ public function testRunProcessWithTimeout()
throw $e;
}

/**
* @expectedException \Symfony\Component\Process\Exception\ProcessTimedOutException
* @expectedExceptionMessage exceeded the timeout of 0.1 seconds.
*/
public function testIterateOverProcessWithTimeout()
{
$process = $this->getProcess(self::$phpBin.' -r "sleep(30);"');
$process->setTimeout(0.1);
$start = microtime(true);
try {
$process->start();
foreach ($process as $buffer);
$this->fail('A RuntimeException should have been raised');
} catch (RuntimeException $e) {
}

$this->assertLessThan(15, microtime(true) - $start);

throw $e;
}

public function testCheckTimeoutOnNonStartedProcess()
{
$process = $this->getProcess('echo foo');
Expand Down

0 comments on commit f96dc2e

Please sign in to comment.