/** * @runInSeparateProcess * @preserveGlobalState disabled */ public function testKillChildrenSigKill() { $loopEcho = function () { while (true) { usleep(50 * 1000); echo "hello\n"; } }; $loopEchoStayinAlive = function () { pcntl_signal(SIGTERM, function () { echo "Well, you can tell by the way I use my walk\n I'm a woman's man, no time to talk\n"; }, false); while (true) { usleep(50 * 1000); echo "hello\n"; } }; $process = CM_Process::getInstance(); $process->fork($loopEcho); $process->fork($loopEchoStayinAlive); $pidListBefore = $this->_getChildrenPidList(); $timeStart = microtime(true); $process->killChildren(0.5); $this->assertCount(2, $pidListBefore); $this->assertCount(0, $this->_getChildrenPidList()); $this->assertSameTime(0.65, microtime(true) - $timeStart, 0.15); $logError = new CM_Paging_Log([CM_Log_Logger::ERROR]); $this->assertSame(1, $logError->getCount()); $this->assertContains('killing with signal `9`', $logError->getItem(0)['message']); }
public function testAggregate() { $client = $this->getServiceManager()->getMongoDb(); $encoder = new CM_Log_Encoder_MongoDb(); $handler = new CM_Log_Handler_MongoDb($client, $encoder, CM_Paging_Log::COLLECTION_NAME); $context1 = new CM_Log_Context(); $context1->setExtra(['bar' => 'quux']); $record1 = new CM_Log_Record(CM_Log_Logger::DEBUG, 'foo', $context1); $context2 = new CM_Log_Context(); $record2 = new CM_Log_Record(CM_Log_Logger::DEBUG, 'baz', $context2); $exception = new CM_Exception_Invalid('Bad news', CM_Exception::WARN, ['baz' => 'bar']); $context3 = new CM_Log_Context(); $context3->setException($exception); $record3 = new CM_Log_Record(CM_Log_Logger::WARNING, 'bar', $context3); //they will not be found $handler->handleRecord($record1); $handler->handleRecord($record2); $handler->handleRecord($record3); CMTest_TH::timeDaysForward(2); //recreate records to correctly set up CM_Log_Record::createdAt $context1 = new CM_Log_Context(); $context1->setExtra(['bar' => 'quux']); $record1 = new CM_Log_Record(CM_Log_Logger::DEBUG, 'foo', $context1); $context3 = new CM_Log_Context(); $context3->setException($exception); $record3 = new CM_Log_Record(CM_Log_Logger::WARNING, 'bar', $context3); $handler->handleRecord($record1); $handler->handleRecord($record3); $handler->handleRecord($record3); CMTest_TH::timeDaysForward(1); $exception2 = new CM_Exception_Invalid('Some info', CM_Exception::FATAL, ['foo' => 'bar']); //recreate records to correctly set up CM_Log_Record::createdAt $context1 = new CM_Log_Context(); $context1->setExtra(['bar' => 'quux']); $record1 = new CM_Log_Record(CM_Log_Logger::DEBUG, 'foo', $context1); $context2 = new CM_Log_Context(); $record2 = new CM_Log_Record(CM_Log_Logger::DEBUG, 'baz', $context2); $context3 = new CM_Log_Context(); $context3->setException($exception); $record3 = new CM_Log_Record(CM_Log_Logger::DEBUG, 'Error bar', $context3); $context4 = new CM_Log_Context(); $context4->setException($exception2); $record4 = new CM_Log_Record(CM_Log_Logger::DEBUG, 'Error bar', $context4); $handler->handleRecord($record2); $handler->handleRecord($record2); $handler->handleRecord($record2); $handler->handleRecord($record3); $handler->handleRecord($record3); $handler->handleRecord($record4); $handler->handleRecord($record1); $handler->handleRecord($record1); $handler->handleRecord($record1); $paging = new CM_Paging_Log([CM_Log_Logger::DEBUG], null, true, 2 * 86400); $this->assertSame(4, $paging->getCount()); $foundRecord1 = $paging->getItem(0); $foundRecord2 = $paging->getItem(1); $foundRecord3 = $paging->getItem(2); $foundRecord4 = $paging->getItem(3); $this->assertSame(4, $foundRecord1['count']); $this->assertSame(3, $foundRecord2['count']); $this->assertSame(2, $foundRecord3['count']); $this->assertSame(1, $foundRecord4['count']); $this->assertSame('foo', $foundRecord1['message']); $this->assertSame('baz', $foundRecord2['message']); $this->assertSame('Error bar', $foundRecord3['message']); $this->assertSame('Bad news', $foundRecord3['exception']['message']); $this->assertSame('Error bar', $foundRecord4['message']); $this->assertSame('Some info', $foundRecord4['exception']['message']); }