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
This commit is contained in:
commit
e9dcc04ace
|
@ -23,6 +23,7 @@ use Symfony\Component\Process\ProcessPipes;
|
|||
class ProcessTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
private static $phpBin;
|
||||
private static $process;
|
||||
private static $sigchild;
|
||||
private static $notEnhancedSigchild = false;
|
||||
|
||||
|
@ -42,6 +43,14 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
|||
self::$sigchild = false !== strpos(ob_get_clean(), '--enable-sigchild');
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
if (self::$process) {
|
||||
self::$process->stop(0);
|
||||
self::$process = null;
|
||||
}
|
||||
}
|
||||
|
||||
public function testThatProcessDoesNotThrowWarningDuringRun()
|
||||
{
|
||||
@trigger_error('Test Error', E_USER_NOTICE);
|
||||
|
@ -122,9 +131,9 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
|||
$h = new \ReflectionProperty($p, 'process');
|
||||
$h->setAccessible(true);
|
||||
$h = $h->getValue($p);
|
||||
$s = proc_get_status($h);
|
||||
$s = @proc_get_status($h);
|
||||
|
||||
while ($s['running']) {
|
||||
while (!empty($s['running'])) {
|
||||
usleep(1000);
|
||||
$s = proc_get_status($h);
|
||||
}
|
||||
|
@ -1012,7 +1021,11 @@ class ProcessTest extends \PHPUnit_Framework_TestCase
|
|||
}
|
||||
}
|
||||
|
||||
return $process;
|
||||
if (self::$process) {
|
||||
self::$process->stop(0);
|
||||
}
|
||||
|
||||
return self::$process = $process;
|
||||
}
|
||||
|
||||
private function skipIfNotEnhancedSigchild($expectException = true)
|
||||
|
|
Reference in New Issue