예제 #1
0
 public function test_isRunning_ShouldMarkProcessAsFinished_IfPidFileIsTooBig()
 {
     if (!Process::isSupported()) {
         $this->markTestSkipped('Not supported');
     }
     $this->process->startProcess();
     $this->assertTrue($this->process->isRunning());
     $this->assertFalse($this->process->hasFinished());
     File::setFileSize(505);
     $this->assertFalse($this->process->isRunning());
     $this->assertTrue($this->process->hasFinished());
 }
예제 #2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->recreateContainerWithWebEnvironment();
     $this->initHostAndQueryString($input);
     if ($this->isTestModeEnabled()) {
         $indexFile = '/tests/PHPUnit/proxy/';
         $this->resetDatabase();
     } else {
         $indexFile = '/';
     }
     $indexFile .= 'index.php';
     if (!empty($_GET['pid'])) {
         $process = new Process($_GET['pid']);
         if ($process->hasFinished()) {
             return;
         }
         $process->startProcess();
     }
     if ($input->getOption('superuser')) {
         StaticContainer::addDefinitions(array('observers.global' => \DI\add(array(array('Environment.bootstrapped', function () {
             Access::getInstance()->setSuperUserAccess(true);
         })))));
     }
     require_once PIWIK_INCLUDE_PATH . $indexFile;
     if (!empty($process)) {
         $process->finishProcess();
     }
 }
예제 #3
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->recreateContainerWithWebEnvironment();
     $this->initHostAndQueryString($input);
     if ($this->isTestModeEnabled()) {
         require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/TestingEnvironment.php';
         Config::unsetInstance();
         StaticContainer::clearContainer();
         \Piwik_TestingEnvironment::addHooks();
         $indexFile = '/tests/PHPUnit/proxy/';
         $this->resetDatabase();
     } else {
         $indexFile = '/';
     }
     $indexFile .= 'index.php';
     if (!empty($_GET['pid'])) {
         $process = new Process($_GET['pid']);
         if ($process->hasFinished()) {
             return;
         }
         $process->startProcess();
     }
     require_once PIWIK_INCLUDE_PATH . $indexFile;
     if (!empty($process)) {
         $process->finishProcess();
     }
 }
예제 #4
0
 public function test_startProcess_finishProcess_ShouldMarkProcessAsStarted()
 {
     $this->assertFalse($this->process->isRunning());
     $this->assertFalse($this->process->hasStarted());
     $this->assertFalse($this->process->hasFinished());
     $this->process->startProcess();
     $this->assertTrue($this->process->isRunning());
     $this->assertTrue($this->process->hasStarted());
     $this->assertTrue($this->process->isRunning());
     $this->assertTrue($this->process->hasStarted());
     $this->assertFalse($this->process->hasFinished());
     $this->process->startProcess();
     $this->assertTrue($this->process->isRunning());
     $this->assertTrue($this->process->hasStarted());
     $this->assertFalse($this->process->hasFinished());
     $this->process->finishProcess();
     $this->assertFalse($this->process->isRunning());
     $this->assertTrue($this->process->hasStarted());
     $this->assertTrue($this->process->hasFinished());
 }
예제 #5
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->initHostAndQueryString($input);
     if ($this->isTestModeEnabled()) {
         Config::getInstance()->setTestEnvironment();
         $indexFile = '/tests/PHPUnit/proxy/index.php';
     } else {
         $indexFile = '/index.php';
     }
     if (!empty($_GET['pid'])) {
         $process = new Process($_GET['pid']);
         if ($process->hasFinished()) {
             return;
         }
         $process->startProcess();
     }
     require_once PIWIK_INCLUDE_PATH . $indexFile;
     if (!empty($process)) {
         $process->finishProcess();
     }
 }
예제 #6
0
 /**
  * If there are multiple archiver running on the same node it makes sure only one of them performs an action and it
  * will wait until another one has finished. Any closure you pass here should be very fast as other processes wait
  * for this closure to finish otherwise. Currently only used for making multiple archivers at the same time work.
  * If a closure takes more than 5 seconds we assume it is dead and simply continue.
  *
  * @param \Closure $closure
  * @return mixed
  * @throws \Exception
  */
 private function runExclusive($closure)
 {
     $process = new Process('archive.sharedsiteids');
     while ($process->isRunning() && $process->getSecondsSinceCreation() < 5) {
         // wait max 5 seconds, such an operation should not take longer
         usleep(25 * 1000);
     }
     $process->startProcess();
     try {
         $result = $closure();
     } catch (Exception $e) {
         $process->finishProcess();
         throw $e;
     }
     $process->finishProcess();
     return $result;
 }