Ejemplo n.º 1
0
 public function testMain()
 {
     // First start
     ob_start();
     $app = $this->getApp();
     $app->cache->flush();
     $app->run();
     $result = ob_get_clean();
     $this->assertEquals('body0', $result, "First run, put data into cache");
     // Make sure cache works
     ob_start();
     self::$body = 1;
     $app = $this->getApp();
     $app->run();
     $result = ob_get_clean();
     $app->mutex->releaseAll();
     $this->assertEquals('body0', $result, "Second run, get data from cache");
     // Make sure dependency works
     ob_start();
     self::$tag = 1;
     $app = $this->getApp();
     $app->run();
     $app->mutex->releaseAll();
     $result = ob_get_clean();
     $this->assertEquals('body1', $result);
     $pid = pcntl_fork();
     $this->assertNotEquals(-1, $pid, "Can not fork process");
     self::$tag = 2;
     self::$body = 2;
     if ($pid) {
         // Parent starts after child and should get old data from cache, because child
         // is regenerating data right now
         usleep(1000);
         ob_start();
         $app = $this->getApp();
         $app->run();
         $result = ob_get_clean();
         $this->assertEquals('body1', $result, "Both processes have started cache rebuild ;-(");
         // Wait for child ends and now parent should get new data
         pcntl_wait($status);
         ob_start();
         $app = $this->getApp();
         $app->run();
         $result = ob_get_clean();
         $this->assertEquals('body2', $result);
     } else {
         // Child starts immediately after forking and generates new data with 100 ms delay
         self::$timeout = 2000;
         $app->run();
     }
 }
Ejemplo n.º 2
0
 public function testMain()
 {
     // First start
     ob_start();
     $app = $this->getApp();
     $app->cache->flush();
     $app->run();
     $result = ob_get_clean();
     $this->assertEquals('body0', $result, "First run, put data into cache");
     // Make sure cache works
     ob_start();
     self::$body = 1;
     $app = $this->getApp();
     $app->run();
     $result = ob_get_clean();
     $app->mutex->releaseAll();
     $this->assertEquals('body0', $result, "Second run, get data from cache");
     // Make sure dependency works
     ob_start();
     self::$tag = 1;
     $app = $this->getApp();
     $app->run();
     $app->mutex->releaseAll();
     $result = ob_get_clean();
     $this->assertEquals('body1', $result);
     $pid = pcntl_fork();
     $this->assertNotEquals(-1, $pid, "Can not fork process");
     self::$tag = 2;
     self::$body = 2;
     ob_start();
     $app = $this->getApp();
     self::$mutexState = $app->mutex->acquire('test');
     $app->run();
     $result = ob_get_clean();
     if (self::$mutexState) {
         $this->assertEquals('body2', $result);
     } else {
         $this->assertEquals('body1', $result);
     }
 }