You've already forked qlg.tsgz.moe
Init Repo
This commit is contained in:
50
vendor/swoole/tests/swoole_channel/basic.phpt
vendored
Executable file
50
vendor/swoole/tests/swoole_channel/basic.phpt
vendored
Executable file
@ -0,0 +1,50 @@
|
||||
--TEST--
|
||||
swoole_coroutine: coro channel
|
||||
--SKIPIF--
|
||||
<?php require __DIR__ . '/../include/skipif.inc'; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once __DIR__ . '/../include/bootstrap.php';
|
||||
|
||||
$pm = new ProcessManager;
|
||||
$pm->parentFunc = function ($pid)
|
||||
{
|
||||
$data = curlGet("http://127.0.0.1:9501/");
|
||||
echo $data;
|
||||
swoole_process::kill($pid);
|
||||
};
|
||||
|
||||
$pm->childFunc = function () use ($pm)
|
||||
{
|
||||
$http = new swoole_http_server("127.0.0.1", 9501, SWOOLE_BASE);
|
||||
$http->set(array(
|
||||
'log_file' => '/dev/null'
|
||||
));
|
||||
$http->on("WorkerStart", function (\swoole_server $serv)
|
||||
{
|
||||
/**
|
||||
* @var $pm ProcessManager
|
||||
*/
|
||||
global $pm;
|
||||
$pm->wakeup();
|
||||
});
|
||||
$http->on('request', function (swoole_http_request $request, swoole_http_response $response)
|
||||
{
|
||||
$ch = new \Swoole\Channel(1);
|
||||
$out = new \Swoole\Channel(1);
|
||||
Swoole\Coroutine::create(function() use ($ch, $out) {
|
||||
$tmp = $ch->pop();
|
||||
$out->push("OK");
|
||||
});
|
||||
$ch->push("test");
|
||||
$ret = $out->pop();
|
||||
$response->end("$ret\n");
|
||||
});
|
||||
$http->start();
|
||||
};
|
||||
|
||||
$pm->childFirst();
|
||||
$pm->run();
|
||||
?>
|
||||
--EXPECT--
|
||||
OK
|
41
vendor/swoole/tests/swoole_channel/pusu_pop_stats.phpt
vendored
Executable file
41
vendor/swoole/tests/swoole_channel/pusu_pop_stats.phpt
vendored
Executable file
@ -0,0 +1,41 @@
|
||||
--TEST--
|
||||
swoole_channel: push & pop & stats
|
||||
|
||||
--SKIPIF--
|
||||
<?php require __DIR__ . '/../include/skipif.inc'; ?>
|
||||
--INI--
|
||||
assert.active=1
|
||||
assert.warning=1
|
||||
assert.bail=0
|
||||
assert.quiet_eval=0
|
||||
|
||||
|
||||
--FILE--
|
||||
<?php
|
||||
require_once __DIR__ . '/../include/bootstrap.php';
|
||||
|
||||
use Swoole\Channel;
|
||||
|
||||
const N = 100;
|
||||
$chan = new Channel(1024 * 256);
|
||||
|
||||
$worker_num = 4;
|
||||
$workers = array();
|
||||
|
||||
for ($i = 0; $i < N; $i++)
|
||||
{
|
||||
$n = rand(100, 200);
|
||||
$chan->push(['value' => str_repeat('A', $n), 'len' => $n]);
|
||||
}
|
||||
|
||||
$stats = $chan->stats();
|
||||
assert($stats['queue_num'] == N);
|
||||
|
||||
for ($i = 0; $i < N; $i++)
|
||||
{
|
||||
$ret = $chan->pop();
|
||||
assert(is_array($ret));
|
||||
}
|
||||
?>
|
||||
|
||||
--EXPECT--
|
Reference in New Issue
Block a user