diff options
-rw-r--r-- | core/CliMulti/Process.php | 11 | ||||
-rw-r--r-- | tests/PHPUnit/Integration/CliMulti/ProcessTest.php | 11 |
2 files changed, 21 insertions, 1 deletions
diff --git a/core/CliMulti/Process.php b/core/CliMulti/Process.php index bb0583c4ad..ad1d30cd56 100644 --- a/core/CliMulti/Process.php +++ b/core/CliMulti/Process.php @@ -26,6 +26,7 @@ class Process private $timeCreation = null; private $isSupported = null; private $pid = null; + private $started = null; public function __construct($pid) { @@ -62,6 +63,16 @@ class Process public function hasStarted($content = null) { + if (!$this->started) { + $this->started = $this->checkPidIfHasStarted($content); + } + // PID will be deleted when process has finished so we want to remember this process started at some point. Otherwise we might return false here once the process finished. + // therefore we want to "cache" a successful start + return $this->started; + } + + private function checkPidIfHasStarted($content = null) + { if (is_null($content)) { $content = $this->getPidFileContent(); } diff --git a/tests/PHPUnit/Integration/CliMulti/ProcessTest.php b/tests/PHPUnit/Integration/CliMulti/ProcessTest.php index 383733de53..229a687587 100644 --- a/tests/PHPUnit/Integration/CliMulti/ProcessTest.php +++ b/tests/PHPUnit/Integration/CliMulti/ProcessTest.php @@ -121,11 +121,20 @@ class ProcessTest extends \PHPUnit\Framework\TestCase $this->assertTrue($this->process->hasFinished()); } - public function test_hasStarted() + public function test_hasStarted_startedWhenContentFalse() { $this->assertTrue($this->process->hasStarted(false)); + } + + public function test_hasStarted_startedWhenPidGiven() + { $this->assertTrue($this->process->hasStarted('6341')); + // remembers the process was started at some point + $this->assertTrue($this->process->hasStarted('')); + } + public function test_hasStarted_notStartedYetEmptyContentInPid() + { $this->assertFalse($this->process->hasStarted('')); } |