/** * Parent check timeout test * * @author amal * @group integrational * @group timeout * * @requires extension posix * @requires extension pcntl */ public function testParentCheckTimeout() { $debug = false; $testCase = $this; $this->processAsyncTest(function () use($testCase, $debug) { if ($debug) { echo '-------------------------', PHP_EOL, "Parent check timeout test ", PHP_EOL, '-------------------------', PHP_EOL; } $thread = new TestParentCheckTimeout(null, null, $debug); $childPid = $thread->wait()->getChildPid(); $testCase->assertNotEmpty($childPid); $childChildPid = null; $triggered = false; $thread->bind(TestParentCheckTimeout::EV_PID, function ($event_name, $e_data) use(&$childChildPid, &$triggered, $testCase) { $triggered = true; $testCase->assertSame(TestParentCheckTimeout::EV_PID, $event_name); $childChildPid = $e_data; })->run()->wait(); $testCase->assertTrue($triggered); $testCase->assertNotEmpty($childChildPid); // Child is dead $isAliveChild = Base::getProcessIsAlive($childPid); $testCase->assertFalse($isAliveChild); // Child's child can be alive in that moment, so wait a litle usleep(20000); $i = 50; do { if (!($isAliveChildChild = Base::getProcessIsAlive($childChildPid))) { break; } usleep(20000); $i--; } while ($i > 0); $testCase->assertFalse($isAliveChildChild); $thread->cleanup(); }, true); }