From 10992cd3bfe9b184987b7a06d462e69119917c7c Mon Sep 17 00:00:00 2001 From: Robin Chalas Date: Tue, 22 Nov 2016 21:44:12 +0100 Subject: [PATCH] [Process] Fix kill process on reached timeout using getIterator() --- src/Symfony/Component/Process/Process.php | 1 + .../Component/Process/Tests/ProcessTest.php | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/Symfony/Component/Process/Process.php b/src/Symfony/Component/Process/Process.php index f95b34a312673..fd6ffe3573351 100644 --- a/src/Symfony/Component/Process/Process.php +++ b/src/Symfony/Component/Process/Process.php @@ -557,6 +557,7 @@ public function getIterator($flags = 0) yield self::OUT => ''; } + $this->checkTimeout(); $this->readPipesForOutput(__FUNCTION__, $blocking); } } diff --git a/src/Symfony/Component/Process/Tests/ProcessTest.php b/src/Symfony/Component/Process/Tests/ProcessTest.php index cd57f3a8c32df..f317fc7d72938 100644 --- a/src/Symfony/Component/Process/Tests/ProcessTest.php +++ b/src/Symfony/Component/Process/Tests/ProcessTest.php @@ -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');