Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a635c4f

Browse filesBrowse files
committed
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
2 parents 1e973b2 + ae84810 commit a635c4f
Copy full SHA for a635c4f

File tree

Expand file treeCollapse file tree

2 files changed

+38
-8
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+38
-8
lines changed

‎src/Symfony/Component/Process/Process.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Process/Process.php
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,9 @@ public function disableOutput()
418418
if ($this->isRunning()) {
419419
throw new RuntimeException('Disabling output while the process is running is not possible.');
420420
}
421+
if (null !== $this->idleTimeout) {
422+
throw new LogicException('Output can not be disabled while an idle timeout is set.');
423+
}
421424

422425
$this->outputDisabled = true;
423426

@@ -870,6 +873,10 @@ public function setTimeout($timeout)
870873
*/
871874
public function setIdleTimeout($timeout)
872875
{
876+
if (null !== $timeout && $this->outputDisabled) {
877+
throw new LogicException('Idle timeout can not be set while the output is disabled.');
878+
}
879+
873880
$this->idleTimeout = $this->validateTimeout($timeout);
874881

875882
return $this;

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Process/Tests/AbstractProcessTest.php
+31-8Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ public function testIdleTimeout()
550550
{
551551
$process = $this->getProcess('sleep 3');
552552
$process->setTimeout(10);
553-
$process->setIdleTimeout(1);
553+
$process->setIdleTimeout(0.5);
554554

555555
try {
556556
$process->run();
@@ -559,7 +559,7 @@ public function testIdleTimeout()
559559
} catch (ProcessTimedOutException $ex) {
560560
$this->assertTrue($ex->isIdleTimeout());
561561
$this->assertFalse($ex->isGeneralTimeout());
562-
$this->assertEquals(1.0, $ex->getExceededTimeout());
562+
$this->assertEquals(0.5, $ex->getExceededTimeout());
563563
}
564564
}
565565

@@ -568,32 +568,32 @@ public function testIdleTimeout()
568568
*/
569569
public function testIdleTimeoutNotExceededWhenOutputIsSent()
570570
{
571-
$process = $this->getProcess('echo "foo" && sleep 1 && echo "foo" && sleep 1 && echo "foo" && sleep 1 && echo "foo" && sleep 5');
572-
$process->setTimeout(5);
573-
$process->setIdleTimeout(3);
571+
$process = $this->getProcess('echo "foo" && sleep 1 && echo "foo" && sleep 1 && echo "foo" && sleep 1');
572+
$process->setTimeout(2);
573+
$process->setIdleTimeout(1.5);
574574

575575
try {
576576
$process->run();
577577
$this->fail('A timeout exception was expected.');
578578
} catch (ProcessTimedOutException $ex) {
579579
$this->assertTrue($ex->isGeneralTimeout());
580580
$this->assertFalse($ex->isIdleTimeout());
581-
$this->assertEquals(5.0, $ex->getExceededTimeout());
581+
$this->assertEquals(2, $ex->getExceededTimeout());
582582
}
583583
}
584584

585585
public function testStartAfterATimeout()
586586
{
587587
$process = $this->getProcess('php -r "while (true) {echo \'\'; usleep(1000); }"');
588-
$process->setTimeout(0.1);
588+
$process->setTimeout(0.2);
589589
try {
590590
$process->run();
591591
$this->fail('An exception should have been raised.');
592592
} catch (\Exception $e) {
593593

594594
}
595595
$process->start();
596-
usleep(10000);
596+
usleep(1000);
597597
$process->stop();
598598
}
599599

@@ -737,6 +737,29 @@ public function testEnableOrDisableOutputAfterRunDoesNotThrowException()
737737
$p->disableOutput();
738738
}
739739

740+
public function testDisableOutputWhileIdleTimeoutIsSet()
741+
{
742+
$process = $this->getProcess('sleep 3');
743+
$process->setIdleTimeout(1);
744+
$this->setExpectedException('Symfony\Component\Process\Exception\LogicException', 'Output can not be disabled while an idle timeout is set.');
745+
$process->disableOutput();
746+
}
747+
748+
public function testSetIdleTimeoutWhileOutputIsDisabled()
749+
{
750+
$process = $this->getProcess('sleep 3');
751+
$process->disableOutput();
752+
$this->setExpectedException('Symfony\Component\Process\Exception\LogicException', 'Idle timeout can not be set while the output is disabled.');
753+
$process->setIdleTimeout(1);
754+
}
755+
756+
public function testSetNullIdleTimeoutWhileOutputIsDisabled()
757+
{
758+
$process = $this->getProcess('sleep 3');
759+
$process->disableOutput();
760+
$process->setIdleTimeout(null);
761+
}
762+
740763
/**
741764
* @dataProvider provideStartMethods
742765
*/

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.