protected function _doTestStartAll($baseConfig, $useFactoryMethodToCreateKeeper = false) { $config = $baseConfig; $config['quantity'] = $quantity = 3; if (!$useFactoryMethodToCreateKeeper) { $keeper = new OneForOneKeeper(array(new Config($config))); } else { $keeper = \Comos\Qpm\Supervision\Supervisor::oneForOne($config)->getKeeper(); } $keeper->startAll(); $pids = array(); for ($i = 0; $i < $quantity; $i++) { $status = 0; $pids[\pcntl_wait($status)] = true; } $currentPid = \posix_getpid(); $r = \file_get_contents($this->_logFile); $lines = explode("\n", $r); $count = 0; foreach ($lines as $line) { if (trim($line)) { list($pid, $ppid) = explode(',', $line); $count++; $this->assertTrue($pids[$pid]); $this->assertEquals($currentPid, $ppid); } } $this->assertEquals($quantity, $count); }
public function testOneForOne_WithTimeout_WithOnTimeout() { $conf = array('worker' => array($this, 'worker'), 'quantity' => 2, 'timeout' => 1, 'maxRestartTimes' => 10, 'withIn' => 30, 'onTimeout' => array($this, 'onTimeout')); try { Supervisor::oneForOne($conf)->start(); $this->fail('expects OutOfPolicyException'); } catch (\Exception $ex) { $this->assertInstanceOf('\\Comos\\Qpm\\Supervision\\OutOfPolicyException', $ex); } $data = \file_get_contents($this->logFile); $ms = null; $this->assertEquals(1, preg_match('/^b{10,12}$/', $data, $ms)); $this->assertEquals(12, $this->onTimeoutCount); }
<?php use Comos\Qpm\Supervision\Supervisor; require __DIR__ . '/bootstrap.inc.php'; Supervisor::oneForOne(array('timeout' => 5, 'termTimeout' => 3, 'worker' => function () { declare (ticks=1); $GLOBALS['stop'] = 0; pcntl_signal(SIGTERM, function () { echo "TERM\n"; $GLOBALS['stop'] = 1; }); while (!$GLOBALS['stop']) { sleep(1); echo '.'; } echo "BYE\n"; }))->start();
/** *@expectedException InvalidArgumentException */ public function testOneForOne_InvalidArgument() { Supervisor::oneForOne(array()); }