/** * @memcheck */ public function testWatch() { $file = ION_VAR . "/iddqd"; @unlink($file); file_put_contents($file, "a1"); $expected = realpath($file); FS::watch($file)->then(function ($files) { $this->data["changed"] = $files; })->setName('test'); $this->promise(function () use($file) { (yield \ION::await(0.02)); @unlink($file); // file_put_contents('/tmp/iddqd', "a2", FILE_APPEND); (yield \ION::await(0.1)); }); $this->loop(); FS::unwatchAll(); // FS::watch($file)->forget('test'); $this->assertCount(1, $this->data["changed"]); $this->assertArrayHasKey($expected, $this->data["changed"]); }
/** * @memcheck */ public function testDisconnect() { list($one, $this->tmp) = IPC::create((string) "one1", (string) "two2"); /* @var IPC $one */ /* @var IPC $two */ $one->whenIncoming()->then(function ($data) { $this->data[] = $data; }); $one->whenDisconnected()->then(function ($ctx) { $this->data[] = $ctx; }); \ION::await(0.02)->then(function () { $this->tmp->send("test1"); }); \ION::await(0.03)->then(function () { unset($this->tmp); }); \ION::await(0.04)->then(function () { $this->stop(); }); \ION::dispatch(); $this->assertEquals([$this->message("test1", "one1"), "one1"], $this->data); }
/** * @memcheck */ public function testReinit() { $this->assertTrue(ION::reinit()); }
$request->onBody($parser)->then(function (\ION\HTTP\WebSocket\Frame $frame) { }); while (!$parser->isFinished()) { $frame = (yield $request->onBody($parser)); } $parser = new \ION\HTTP\MultiPartParser("iddqd", 1000); $request->onBody($parser)->then(function (\ION\HTTP\MultiPart\Part $part) { }); while (!$parser->isFinished()) { $part = (yield $request->onBody($parser)); } $parser = new \ION\HTTP\ChunkedParser(); $request->onBody($parser)->then(function (string $chunk) { }); while (!$parser->isFinished()) { $chunk = (yield $request->onBody($parser)); } $response = (yield \ION\HTTP::request($request)); /* @var \ION\HTTP\Response $response */ echo "Code: " . $response->getStatusCode() . " (" . $response->getReasonPhrase() . ")\n\n"; echo "Headers: \n\n"; var_dump($response->getHeaders()); echo "Content: \n\n"; var_dump($response->getBody()); echo "\n\n"; }); $init = function ($request) { throw \ION\Sequence::quit(); }; ION::dispatch();
/** * @memcheck */ public function testAwaitFailedPromise() { $promise = new ResolvablePromise(); $promise->then(function ($x) { $this->data["x1"] = $x; return \ION::await(0.1)->then(function ($result) use($x) { $this->data["await"] = $result; throw new \RuntimeException("problem description"); }); })->onDone(function ($result) { $this->data["result"] = $result; $this->stop(); })->onFail(function ($error) { /* @var \Exception $error */ $this->data["error"] = $this->exception2array($error); $this->stop(); }); $promise->done(1); $this->loop(); $this->assertEquals(['x1' => 1, 'await' => true, 'error' => ['exception' => 'RuntimeException', 'message' => 'problem description', 'code' => 0]], $this->data); }
/** * @memcheck */ public function _testSetPriority() { $prio = Process::getPriority(); $pid = pcntl_fork(); \ION::reinit(); if ($pid) { usleep(10000); $this->assertSame($prio + 10, Process::getPriority($pid)); $this->assertWaitPID($pid); } else { Process::setPriority(10); usleep(20000); exit(0); } }