8000 [Process] Fix process continuing after reached timeout using getIterator() by chalasr · Pull Request #20600 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Process] Fix process continuing after reached timeout using getIterator() #20600

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8000
1 change: 1 addition & 0 deletions src/Symfony/Component/Process/Process.php
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ public function getIterator($flags = 0)
yield self::OUT => '';
}

$this->checkTimeout();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be above line 560, isn't it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true! fixed

$this->readPipesForOutput(__FUNCTION__, $blocking);
}
}
Expand Down
21 changes: 21 additions & 0 deletions src/Symfony/Component/Process/Tests/ProcessTest.php
Original file line number Diff line number Diff line change
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