8000 minor #17198 [Process] Clean tested process on tear down (nicolas-gre… · symfony/symfony@e9dcc04 · GitHub
[go: up one dir, main page]

Skip to content

Commit e9dcc04

Browse files
minor #17198 [Process] Clean tested process on tear down (nicolas-grekas)
This PR was merged into the 2.3 branch. Discussion ---------- [Process] Clean tested process on tear down | Q | A | ------------- | --- | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - As show on this failing test (https://travis-ci.org/symfony/symfony/jobs/99569782#L2690) and confirmed locally, some tested process objects remain in memory until the global destructor shutdown stage. This PR forces processes to be cleaned right after their test case. Commits ------- 80e1107 [Process] Clean tested process on tear down
2 parents 4512e34 + 80e1107 commit e9dcc04

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/Symfony/Component/Process/Tests/ProcessTest.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
class ProcessTest extends \PHPUnit_Framework_TestCase
2424
{
2525
private static $phpBin;
26+
private static $process;
2627
private static $sigchild;
2728
private static $notEnhancedSigchild = false;
2829

@@ -42,6 +43,14 @@ public static function setUpBeforeClass()
4243
self::$sigchild = false !== strpos(ob_get_clean(), '--enable-sigchild');
4344
}
4445

46+
protected function tearDown()
47+
{
48+
if (self::$process) {
49+
self::$process->stop(0);
50+
self::$process = null;
51+
}
52+
}
53+
4554
public function testThatProcessDoesNotThrowWarningDuringRun()
4655
{
4756
@trigger_error('Test Error', E_USER_NOTICE);
@@ -122,9 +131,9 @@ public function testAllOutputIsActuallyReadOnTermination()
122131
$h = new \ReflectionProperty($p, 'process');
123132
$h->setAccessible(true);
124133
$h = $h->getValue($p);
125-
$s = proc_get_status($h);
134+
$s = @proc_get_status($h);
126135

127-
while ($s['running']) {
136+
while (!empty($s['running'])) {
128137
usleep(1000);
129138
$s = proc_get_status($h);
130139
}
@@ -1012,7 +1021,11 @@ private function getProcess($commandline, $cwd = null, array $env = null, $stdin
10121021
}
10131022
}
10141023

1015-
return $process;
1024+
if (self::$process) {
1025+
self::$process->stop(0);
1026+
}
1027+
1028+
return self::$process = $process;
10161029
}
10171030

10181031
private function skipIfNotEnhancedSigchild($expectException = true)

0 commit comments

Comments
 (0)
0