bug #10456 [Process] Handle idle timeout and disabled output conflict (romainneutron)

This PR was merged into the 2.5-dev branch.

Discussion
----------

[Process] Handle idle timeout and disabled output conflict

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #10453
| License       | MIT
| Doc PR        | WIP (a note should be added in the doc)

Commits
-------

ae84810 [Process] Increase tests speed
40c08c6 [Process] Handle idle timeout and disable output conflict
This commit is contained in:
Fabien Potencier 2014-03-15 09:40:48 +01:00
commit a635c4f9a3
2 changed files with 38 additions and 8 deletions

View File

@ -418,6 +418,9 @@ class Process
if ($this->isRunning()) {
throw new RuntimeException('Disabling output while the process is running is not possible.');
}
if (null !== $this->idleTimeout) {
throw new LogicException('Output can not be disabled while an idle timeout is set.');
}
$this->outputDisabled = true;
@ -870,6 +873,10 @@ class Process
*/
public function setIdleTimeout($timeout)
{
if (null !== $timeout && $this->outputDisabled) {
throw new LogicException('Idle timeout can not be set while the output is disabled.');
}
$this->idleTimeout = $this->validateTimeout($timeout);
return $this;

View File

@ -550,7 +550,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
{
$process = $this->getProcess('sleep 3');
$process->setTimeout(10);
$process->setIdleTimeout(1);
$process->setIdleTimeout(0.5);
try {
$process->run();
@ -559,7 +559,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
} catch (ProcessTimedOutException $ex) {
$this->assertTrue($ex->isIdleTimeout());
$this->assertFalse($ex->isGeneralTimeout());
$this->assertEquals(1.0, $ex->getExceededTimeout());
$this->assertEquals(0.5, $ex->getExceededTimeout());
}
}
@ -568,9 +568,9 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
*/
public function testIdleTimeoutNotExceededWhenOutputIsSent()
{
$process = $this->getProcess('echo "foo" && sleep 1 && echo "foo" && sleep 1 && echo "foo" && sleep 1 && echo "foo" && sleep 5');
$process->setTimeout(5);
$process->setIdleTimeout(3);
$process = $this->getProcess('echo "foo" && sleep 1 && echo "foo" && sleep 1 && echo "foo" && sleep 1');
$process->setTimeout(2);
$process->setIdleTimeout(1.5);
try {
$process->run();
@ -578,14 +578,14 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
} catch (ProcessTimedOutException $ex) {
$this->assertTrue($ex->isGeneralTimeout());
$this->assertFalse($ex->isIdleTimeout());
$this->assertEquals(5.0, $ex->getExceededTimeout());
$this->assertEquals(2, $ex->getExceededTimeout());
}
}
public function testStartAfterATimeout()
{
$process = $this->getProcess('php -r "while (true) {echo \'\'; usleep(1000); }"');
$process->setTimeout(0.1);
$process->setTimeout(0.2);
try {
$process->run();
$this->fail('An exception should have been raised.');
@ -593,7 +593,7 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
}
$process->start();
usleep(10000);
usleep(1000);
$process->stop();
}
@ -737,6 +737,29 @@ abstract class AbstractProcessTest extends \PHPUnit_Framework_TestCase
$p->disableOutput();
}
public function testDisableOutputWhileIdleTimeoutIsSet()
{
$process = $this->getProcess('sleep 3');
$process->setIdleTimeout(1);
$this->setExpectedException('Symfony\Component\Process\Exception\LogicException', 'Output can not be disabled while an idle timeout is set.');
$process->disableOutput();
}
public function testSetIdleTimeoutWhileOutputIsDisabled()
{
$process = $this->getProcess('sleep 3');
$process->disableOutput();
$this->setExpectedException('Symfony\Component\Process\Exception\LogicException', 'Idle timeout can not be set while the output is disabled.');
$process->setIdleTimeout(1);
}
public function testSetNullIdleTimeoutWhileOutputIsDisabled()
{
$process = $this->getProcess('sleep 3');
$process->disableOutput();
$process->setIdleTimeout(null);
}
/**
* @dataProvider provideStartMethods
*/