You've already forked qlg.tsgz.moe
Init Repo
This commit is contained in:
23
vendor/swoole/tests/swoole_coroutine/call_user_func_array.phpt
vendored
Executable file
23
vendor/swoole/tests/swoole_coroutine/call_user_func_array.phpt
vendored
Executable file
@ -0,0 +1,23 @@
|
||||
--TEST--
|
||||
swoole_coroutine: call_user_func_array
|
||||
--SKIPIF--
|
||||
<?php require __DIR__ . '/../include/skipif.inc'; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once __DIR__ . '/../include/bootstrap.php';
|
||||
|
||||
class A {
|
||||
public function foo() {
|
||||
call_user_func_array([$this, "bar"], []);
|
||||
echo "foo\n";
|
||||
}
|
||||
protected function bar() {
|
||||
echo "bar\n";
|
||||
}
|
||||
}
|
||||
$a = new A;
|
||||
call_user_func_array([$a, "foo"], []);
|
||||
?>
|
||||
--EXPECT--
|
||||
bar
|
||||
foo
|
24
vendor/swoole/tests/swoole_coroutine/coro_stats.phpt
vendored
Executable file
24
vendor/swoole/tests/swoole_coroutine/coro_stats.phpt
vendored
Executable file
@ -0,0 +1,24 @@
|
||||
--TEST--
|
||||
swoole_coroutine: current stats
|
||||
--SKIPIF--
|
||||
<?php require __DIR__ . '/../include/skipif.inc'; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once __DIR__ . '/../include/bootstrap.php';
|
||||
require_once __DIR__ . '/../include/swoole.inc';
|
||||
|
||||
assert(Co::stats()['coroutine_num'] === 0);
|
||||
|
||||
go(function () {
|
||||
assert(Co::stats()['coroutine_num'] === 1);
|
||||
Co::sleep(0.5);
|
||||
assert(Co::stats()['coroutine_num'] === 2);
|
||||
});
|
||||
go(function () {
|
||||
assert(Co::stats()['coroutine_num'] === 2);
|
||||
Co::sleep(0.5);
|
||||
assert(Co::stats()['coroutine_num'] === 1);
|
||||
});
|
||||
assert(Co::stats()['coroutine_num'] === 2);
|
||||
?>
|
||||
--EXPECT--
|
20
vendor/swoole/tests/swoole_coroutine/current.phpt
vendored
Executable file
20
vendor/swoole/tests/swoole_coroutine/current.phpt
vendored
Executable file
@ -0,0 +1,20 @@
|
||||
--TEST--
|
||||
swoole_coroutine: current cid
|
||||
--SKIPIF--
|
||||
<?php require __DIR__ . '/../include/skipif.inc'; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once __DIR__ . '/../include/bootstrap.php';
|
||||
require_once __DIR__ . '/../include/swoole.inc';
|
||||
assert(Co::getuid() === -1);
|
||||
go(function () {
|
||||
assert(Co::getuid() === 1);
|
||||
Co::sleep(1);
|
||||
assert(Co::getuid() === 1);
|
||||
});
|
||||
go(function () {
|
||||
assert(Co::getuid() === 2);
|
||||
});
|
||||
assert(Co::getuid() === -1);
|
||||
?>
|
||||
--EXPECT--
|
40
vendor/swoole/tests/swoole_coroutine/destruct/destruct1.phpt
vendored
Executable file
40
vendor/swoole/tests/swoole_coroutine/destruct/destruct1.phpt
vendored
Executable file
@ -0,0 +1,40 @@
|
||||
--TEST--
|
||||
swoole_coroutine: destruct1
|
||||
--SKIPIF--
|
||||
<?php require __DIR__ . '/../../include/skipif.inc'; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once __DIR__ . '/../../include/bootstrap.php';
|
||||
|
||||
use Swoole\Coroutine as co;
|
||||
class T
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
function test()
|
||||
{
|
||||
echo "call function \n";
|
||||
}
|
||||
|
||||
function __destruct()
|
||||
{
|
||||
go(function () {
|
||||
echo "coro start\n";
|
||||
co::sleep(1.0);
|
||||
echo "coro exit\n";
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
$t = new T();
|
||||
$t->test();
|
||||
unset($t);
|
||||
echo "end\n";
|
||||
?>
|
||||
--EXPECT--
|
||||
call function
|
||||
coro start
|
||||
end
|
||||
coro exit
|
39
vendor/swoole/tests/swoole_coroutine/destruct/destruct2.phpt
vendored
Executable file
39
vendor/swoole/tests/swoole_coroutine/destruct/destruct2.phpt
vendored
Executable file
@ -0,0 +1,39 @@
|
||||
--TEST--
|
||||
swoole_coroutine: destruct2
|
||||
--SKIPIF--
|
||||
<?php require __DIR__ . '/../../include/skipif.inc'; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once __DIR__ . '/../../include/bootstrap.php';
|
||||
|
||||
use Swoole\Coroutine as co;
|
||||
class T
|
||||
{
|
||||
function __construct()
|
||||
{
|
||||
|
||||
}
|
||||
function test()
|
||||
{
|
||||
echo "call function \n";
|
||||
}
|
||||
|
||||
function __destruct()
|
||||
{
|
||||
go(function () {
|
||||
echo "coro start\n";
|
||||
co::sleep(1.0);
|
||||
echo "coro exit\n";
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
$t = new T();
|
||||
$t->test();
|
||||
echo "end\n";
|
||||
?>
|
||||
--EXPECTF--
|
||||
call function
|
||||
end
|
||||
|
||||
Fatal error: go(): can not use coroutine in __destruct after php_request_shutdown %s
|
16
vendor/swoole/tests/swoole_coroutine/empty.phpt
vendored
Executable file
16
vendor/swoole/tests/swoole_coroutine/empty.phpt
vendored
Executable file
@ -0,0 +1,16 @@
|
||||
--TEST--
|
||||
swoole_coroutine: coro empty
|
||||
--SKIPIF--
|
||||
<?php require __DIR__ . '/../include/skipif.inc'; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once __DIR__ . '/../include/bootstrap.php';
|
||||
|
||||
go(function () {
|
||||
echo "co[1] start\n";
|
||||
echo "co[1] exit\n";
|
||||
});
|
||||
?>
|
||||
--EXPECT--
|
||||
co[1] start
|
||||
co[1] exit
|
26
vendor/swoole/tests/swoole_coroutine/exception/empty.phpt
vendored
Executable file
26
vendor/swoole/tests/swoole_coroutine/exception/empty.phpt
vendored
Executable file
@ -0,0 +1,26 @@
|
||||
--TEST--
|
||||
swoole_coroutine: IO empty Exception
|
||||
--SKIPIF--
|
||||
<?php require __DIR__ . '/../../include/skipif.inc'; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once __DIR__ . '/../../include/bootstrap.php';
|
||||
|
||||
go(function () {
|
||||
try {
|
||||
echo "start\n";
|
||||
throw new Exception('coro Exception');
|
||||
} catch (Exception $e) {
|
||||
echo 'Caught exception: ', $e->getMessage(), "\n";
|
||||
} finally {
|
||||
echo "finally.\n";
|
||||
}
|
||||
});
|
||||
echo "end\n";
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
start
|
||||
Caught exception: coro Exception
|
||||
finally.
|
||||
end
|
42
vendor/swoole/tests/swoole_coroutine/exception/nested.phpt
vendored
Executable file
42
vendor/swoole/tests/swoole_coroutine/exception/nested.phpt
vendored
Executable file
@ -0,0 +1,42 @@
|
||||
--TEST--
|
||||
swoole_coroutine: exception before yield
|
||||
--SKIPIF--
|
||||
<?php require __DIR__ . '/../../include/skipif.inc'; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once __DIR__ . '/../../include/bootstrap.php';
|
||||
|
||||
use Swoole\Coroutine as co;
|
||||
go(function () {
|
||||
try {
|
||||
echo "start\n";
|
||||
go(function(){
|
||||
try {
|
||||
echo "sub start\n";
|
||||
throw new Exception('sub coro Exception');
|
||||
co::sleep(0.5);
|
||||
echo "after go2 sleep\n";
|
||||
} catch (Exception $e) {
|
||||
echo 'Caught exception: ', $e->getMessage(), "\n";
|
||||
} finally {
|
||||
echo "finally 2\n";
|
||||
}
|
||||
});
|
||||
echo "after go1 sleep\n";
|
||||
} catch (Exception $e) {
|
||||
echo 'Caught exception: ', $e->getMessage(), "\n";
|
||||
} finally {
|
||||
echo "finally 1\n";
|
||||
}
|
||||
});
|
||||
echo "end\n";
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
start
|
||||
sub start
|
||||
Caught exception: sub coro Exception
|
||||
finally 2
|
||||
after go1 sleep
|
||||
finally 1
|
||||
end
|
30
vendor/swoole/tests/swoole_coroutine/exception/yield.phpt
vendored
Executable file
30
vendor/swoole/tests/swoole_coroutine/exception/yield.phpt
vendored
Executable file
@ -0,0 +1,30 @@
|
||||
--TEST--
|
||||
swoole_coroutine: exception after yield
|
||||
--SKIPIF--
|
||||
<?php require __DIR__ . '/../../include/skipif.inc'; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once __DIR__ . '/../../include/bootstrap.php';
|
||||
|
||||
use Swoole\Coroutine as co;
|
||||
go(function () {
|
||||
try {
|
||||
echo "start\n";
|
||||
co::sleep(0.5);
|
||||
echo "after sleep\n";
|
||||
throw new Exception('coro Exception');
|
||||
} catch (Exception $e) {
|
||||
echo 'Caught exception: ', $e->getMessage(), "\n";
|
||||
} finally {
|
||||
echo "finally.\n";
|
||||
}
|
||||
});
|
||||
echo "end\n";
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
start
|
||||
end
|
||||
after sleep
|
||||
Caught exception: coro Exception
|
||||
finally.
|
29
vendor/swoole/tests/swoole_coroutine/exception/yield1.phpt
vendored
Executable file
29
vendor/swoole/tests/swoole_coroutine/exception/yield1.phpt
vendored
Executable file
@ -0,0 +1,29 @@
|
||||
--TEST--
|
||||
swoole_coroutine: exception before yield
|
||||
--SKIPIF--
|
||||
<?php require __DIR__ . '/../../include/skipif.inc'; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once __DIR__ . '/../../include/bootstrap.php';
|
||||
|
||||
use Swoole\Coroutine as co;
|
||||
go(function () {
|
||||
try {
|
||||
echo "start\n";
|
||||
throw new Exception('coro Exception');
|
||||
co::sleep(0.5);
|
||||
echo "after sleep\n";
|
||||
} catch (Exception $e) {
|
||||
echo 'Caught exception: ', $e->getMessage(), "\n";
|
||||
} finally {
|
||||
echo "finally.\n";
|
||||
}
|
||||
});
|
||||
echo "end\n";
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
start
|
||||
Caught exception: coro Exception
|
||||
finally.
|
||||
end
|
25
vendor/swoole/tests/swoole_coroutine/forbidden_case/array_map.phpt
vendored
Executable file
25
vendor/swoole/tests/swoole_coroutine/forbidden_case/array_map.phpt
vendored
Executable file
@ -0,0 +1,25 @@
|
||||
--TEST--
|
||||
swoole_coroutine: coro array map
|
||||
--SKIPIF--
|
||||
<?php require __DIR__ . '/../../include/skipif.inc'; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once __DIR__ . '/../../include/bootstrap.php';
|
||||
|
||||
use Swoole\Coroutine as co;
|
||||
co::create(function() {
|
||||
array_map("test",array("func start\n"));
|
||||
echo "co end\n";
|
||||
});
|
||||
function test($p) {
|
||||
echo $p;
|
||||
co::sleep(1);
|
||||
echo "func end \n";
|
||||
}
|
||||
echo "main end\n";
|
||||
?>
|
||||
--EXPECT--
|
||||
func start
|
||||
main end
|
||||
func end
|
||||
co end
|
27
vendor/swoole/tests/swoole_coroutine/forbidden_case/call_user.phpt
vendored
Executable file
27
vendor/swoole/tests/swoole_coroutine/forbidden_case/call_user.phpt
vendored
Executable file
@ -0,0 +1,27 @@
|
||||
--TEST--
|
||||
swoole_coroutine: coro call user func
|
||||
--SKIPIF--
|
||||
<?php require __DIR__ . '/../../include/skipif.inc'; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once __DIR__ . '/../../include/bootstrap.php';
|
||||
|
||||
use Swoole\Coroutine as co;
|
||||
co::create(function() {
|
||||
$name = "call_user_func";
|
||||
$return = $name("test");
|
||||
echo "co end\n";
|
||||
});
|
||||
|
||||
function test() {
|
||||
echo "func start\n";
|
||||
co::sleep(0.5);
|
||||
echo "func end\n";
|
||||
}
|
||||
echo "main end\n";
|
||||
?>
|
||||
--EXPECT--
|
||||
func start
|
||||
main end
|
||||
func end
|
||||
co end
|
26
vendor/swoole/tests/swoole_coroutine/forbidden_case/invoke.phpt
vendored
Executable file
26
vendor/swoole/tests/swoole_coroutine/forbidden_case/invoke.phpt
vendored
Executable file
@ -0,0 +1,26 @@
|
||||
--TEST--
|
||||
swoole_coroutine: coro invoke
|
||||
--SKIPIF--
|
||||
<?php require __DIR__ . '/../../include/skipif.inc'; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once __DIR__ . '/../../include/bootstrap.php';
|
||||
|
||||
use Swoole\Coroutine as co;
|
||||
co::create(function() {
|
||||
$function = new ReflectionFunction('foo');
|
||||
$function->invoke();
|
||||
echo "co end\n";
|
||||
});
|
||||
function foo() {
|
||||
echo "func start\n";
|
||||
co::sleep(0.5);
|
||||
echo "func end\n";
|
||||
}
|
||||
echo "main end\n";
|
||||
?>
|
||||
--EXPECT--
|
||||
func start
|
||||
main end
|
||||
func end
|
||||
co end
|
26
vendor/swoole/tests/swoole_coroutine/nested1.phpt
vendored
Executable file
26
vendor/swoole/tests/swoole_coroutine/nested1.phpt
vendored
Executable file
@ -0,0 +1,26 @@
|
||||
--TEST--
|
||||
swoole_coroutine: coro channel
|
||||
--SKIPIF--
|
||||
<?php require __DIR__ . '/../include/skipif.inc'; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once __DIR__ . '/../include/bootstrap.php';
|
||||
|
||||
go(function () {
|
||||
echo "co[1] start\n";
|
||||
co::sleep(1.0);
|
||||
go(function () {
|
||||
echo "co[2] start\n";
|
||||
co::sleep(1.0);
|
||||
echo "co[2] exit\n";
|
||||
});
|
||||
echo "co[1] exit\n";
|
||||
});
|
||||
echo "end\n";
|
||||
?>
|
||||
--EXPECT--
|
||||
co[1] start
|
||||
end
|
||||
co[2] start
|
||||
co[1] exit
|
||||
co[2] exit
|
26
vendor/swoole/tests/swoole_coroutine/nested2.phpt
vendored
Executable file
26
vendor/swoole/tests/swoole_coroutine/nested2.phpt
vendored
Executable file
@ -0,0 +1,26 @@
|
||||
--TEST--
|
||||
swoole_coroutine: coro nested2
|
||||
--SKIPIF--
|
||||
<?php require __DIR__ . '/../include/skipif.inc'; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once __DIR__ . '/../include/bootstrap.php';
|
||||
|
||||
go(function () {
|
||||
echo "co[1] start\n";
|
||||
go(function () {
|
||||
echo "co[2] start\n";
|
||||
co::sleep(2.0);
|
||||
echo "co[2] exit\n";
|
||||
});
|
||||
co::sleep(1.0);
|
||||
echo "co[1] exit\n";
|
||||
});
|
||||
echo "end\n";
|
||||
?>
|
||||
--EXPECT--
|
||||
co[1] start
|
||||
co[2] start
|
||||
end
|
||||
co[1] exit
|
||||
co[2] exit
|
26
vendor/swoole/tests/swoole_coroutine/nested3.phpt
vendored
Executable file
26
vendor/swoole/tests/swoole_coroutine/nested3.phpt
vendored
Executable file
@ -0,0 +1,26 @@
|
||||
--TEST--
|
||||
swoole_coroutine: coro nested3
|
||||
--SKIPIF--
|
||||
<?php require __DIR__ . '/../include/skipif.inc'; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once __DIR__ . '/../include/bootstrap.php';
|
||||
|
||||
go(function () {
|
||||
echo "co[1] start\n";
|
||||
go(function () {
|
||||
echo "co[2] start\n";
|
||||
co::sleep(1.0);
|
||||
echo "co[2] exit\n";
|
||||
});
|
||||
co::sleep(2.0);
|
||||
echo "co[1] exit\n";
|
||||
});
|
||||
echo "end\n";
|
||||
?>
|
||||
--EXPECT--
|
||||
co[1] start
|
||||
co[2] start
|
||||
end
|
||||
co[2] exit
|
||||
co[1] exit
|
22
vendor/swoole/tests/swoole_coroutine/nested_empty.phpt
vendored
Executable file
22
vendor/swoole/tests/swoole_coroutine/nested_empty.phpt
vendored
Executable file
@ -0,0 +1,22 @@
|
||||
--TEST--
|
||||
swoole_coroutine: coro nested empty
|
||||
--SKIPIF--
|
||||
<?php require __DIR__ . '/../include/skipif.inc'; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once __DIR__ . '/../include/bootstrap.php';
|
||||
|
||||
go(function () {
|
||||
echo "co[1] start\n";
|
||||
go(function () {
|
||||
echo "co[2] start\n";
|
||||
echo "co[2] exit\n";
|
||||
});
|
||||
echo "co[1] exit\n";
|
||||
});
|
||||
?>
|
||||
--EXPECT--
|
||||
co[1] start
|
||||
co[2] start
|
||||
co[2] exit
|
||||
co[1] exit
|
36
vendor/swoole/tests/swoole_coroutine/nested_uid.phpt
vendored
Executable file
36
vendor/swoole/tests/swoole_coroutine/nested_uid.phpt
vendored
Executable file
@ -0,0 +1,36 @@
|
||||
--TEST--
|
||||
swoole_coroutine: coro nested strict
|
||||
--SKIPIF--
|
||||
<?php require __DIR__ . '/../include/skipif.inc'; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once __DIR__ . '/../include/bootstrap.php';
|
||||
|
||||
assert(Co::getuid() === -1);
|
||||
go(function () {
|
||||
assert(Co::getuid() === 1);
|
||||
Co::sleep(0.01);
|
||||
assert(Co::getuid() === 1);
|
||||
});
|
||||
assert(Co::getuid() === -1);
|
||||
go(function () {
|
||||
assert(Co::getuid() === 2);
|
||||
|
||||
go(function () {
|
||||
assert(Co::getuid() === 3);
|
||||
go(function () {
|
||||
assert(Co::getuid() === 4);
|
||||
go(function () {
|
||||
assert(Co::getuid() === 5);
|
||||
Co::sleep(0.01);
|
||||
assert(Co::getuid() === 5);
|
||||
});
|
||||
assert(Co::getuid() === 4);
|
||||
});
|
||||
assert(Co::getuid() === 3);
|
||||
});
|
||||
assert(Co::getuid() === 2);
|
||||
});
|
||||
assert(Co::getuid() === -1);
|
||||
?>
|
||||
--EXPECT--
|
31
vendor/swoole/tests/swoole_coroutine/no_inline_func.phpt
vendored
Executable file
31
vendor/swoole/tests/swoole_coroutine/no_inline_func.phpt
vendored
Executable file
@ -0,0 +1,31 @@
|
||||
--TEST--
|
||||
swoole_coroutine: coro not inline function
|
||||
--SKIPIF--
|
||||
<?php require __DIR__ . '/../include/skipif.inc'; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once __DIR__ . '/../include/bootstrap.php';
|
||||
require_once __DIR__ . '/../include/swoole.inc';
|
||||
|
||||
use Swoole\Coroutine as co;
|
||||
|
||||
echo "start\n";
|
||||
co::create(function () {
|
||||
$ret = test();
|
||||
echo $ret;
|
||||
});
|
||||
function test()
|
||||
{
|
||||
echo "start func\n";
|
||||
co::sleep(0.5);
|
||||
echo "end func\n";
|
||||
return "return func params\n";
|
||||
}
|
||||
echo "end\n";
|
||||
?>
|
||||
--EXPECT--
|
||||
start
|
||||
start func
|
||||
end
|
||||
end func
|
||||
return func params
|
28
vendor/swoole/tests/swoole_coroutine/parallel1.phpt
vendored
Executable file
28
vendor/swoole/tests/swoole_coroutine/parallel1.phpt
vendored
Executable file
@ -0,0 +1,28 @@
|
||||
--TEST--
|
||||
swoole_coroutine: coro parallel1
|
||||
--SKIPIF--
|
||||
<?php require __DIR__ . '/../include/skipif.inc'; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once __DIR__ . '/../include/bootstrap.php';
|
||||
|
||||
go(function () {
|
||||
echo "co[1] start\n";
|
||||
co::sleep(1.0);
|
||||
echo "co[1] exit\n";
|
||||
});
|
||||
|
||||
go(function () {
|
||||
echo "co[2] start\n";
|
||||
co::sleep(2.0);
|
||||
echo "co[2] exit\n";
|
||||
});
|
||||
echo "end\n";
|
||||
?>
|
||||
--EXPECT--
|
||||
co[1] start
|
||||
co[2] start
|
||||
end
|
||||
co[1] exit
|
||||
co[2] exit
|
||||
|
27
vendor/swoole/tests/swoole_coroutine/parallel2.phpt
vendored
Executable file
27
vendor/swoole/tests/swoole_coroutine/parallel2.phpt
vendored
Executable file
@ -0,0 +1,27 @@
|
||||
--TEST--
|
||||
swoole_coroutine: coro parallel2
|
||||
--SKIPIF--
|
||||
<?php require __DIR__ . '/../include/skipif.inc'; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once __DIR__ . '/../include/bootstrap.php';
|
||||
|
||||
go(function () {
|
||||
echo "co[1] start\n";
|
||||
co::sleep(2.0);
|
||||
echo "co[1] exit\n";
|
||||
});
|
||||
|
||||
go(function () {
|
||||
echo "co[2] start\n";
|
||||
co::sleep(1.0);
|
||||
echo "co[2] exit\n";
|
||||
});
|
||||
echo "end\n";
|
||||
?>
|
||||
--EXPECT--
|
||||
co[1] start
|
||||
co[2] start
|
||||
end
|
||||
co[2] exit
|
||||
co[1] exit
|
34
vendor/swoole/tests/swoole_coroutine/parallel3.phpt
vendored
Executable file
34
vendor/swoole/tests/swoole_coroutine/parallel3.phpt
vendored
Executable file
@ -0,0 +1,34 @@
|
||||
--TEST--
|
||||
swoole_coroutine: coro parallel3
|
||||
--SKIPIF--
|
||||
<?php require __DIR__ . '/../include/skipif.inc'; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once __DIR__ . '/../include/bootstrap.php';
|
||||
|
||||
go(function () {
|
||||
echo "co[1] start\n";
|
||||
co::sleep(2.0);
|
||||
echo "co[1] exit\n";
|
||||
});
|
||||
|
||||
go(function () {
|
||||
echo "co[2] start\n";
|
||||
go(function () {
|
||||
echo "co[3] start\n";
|
||||
co::sleep(3.0);
|
||||
echo "co[3] exit\n";
|
||||
});
|
||||
co::sleep(1.0);
|
||||
echo "co[2] exit\n";
|
||||
});
|
||||
echo "end\n";
|
||||
?>
|
||||
--EXPECT--
|
||||
co[1] start
|
||||
co[2] start
|
||||
co[3] start
|
||||
end
|
||||
co[2] exit
|
||||
co[1] exit
|
||||
co[3] exit
|
85
vendor/swoole/tests/swoole_coroutine/use_process.phpt
vendored
Executable file
85
vendor/swoole/tests/swoole_coroutine/use_process.phpt
vendored
Executable file
@ -0,0 +1,85 @@
|
||||
--TEST--
|
||||
swoole_server: user process
|
||||
|
||||
--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';
|
||||
require_once __DIR__ . '/../include/swoole.inc';
|
||||
|
||||
$pm = new ProcessManager();
|
||||
|
||||
const SIZE = 8192 * 5;
|
||||
const TIMES = 10;
|
||||
$pm->parentFunc = function ($pid) {
|
||||
$client = new \swoole_client(SWOOLE_SOCK_TCP, SWOOLE_SOCK_SYNC);
|
||||
$client->set([
|
||||
"open_eof_check" => true,
|
||||
"package_eof" => "\r\n\r\n"
|
||||
]);
|
||||
$r = $client->connect("127.0.0.1", 9503, - 1);
|
||||
if ($r === false) {
|
||||
echo "ERROR";
|
||||
exit();
|
||||
}
|
||||
$client->send("SUCCESS");
|
||||
for ($i = 0; $i < TIMES; $i ++) {
|
||||
$ret = $client->recv();
|
||||
assert(strlen($ret) == SIZE + 4);
|
||||
}
|
||||
$client->close();
|
||||
swoole_process::kill($pid);
|
||||
};
|
||||
|
||||
$pm->childFunc = function () use ($pm) {
|
||||
$serv = new \swoole_server("127.0.0.1", 9503);
|
||||
$serv->set([
|
||||
"worker_num" => 1,
|
||||
'log_file' => '/dev/null'
|
||||
]);
|
||||
|
||||
$proc = new swoole\process(function ($process) use ($serv) {
|
||||
$data = json_decode($process->read(), true);
|
||||
for ($i = 0; $i < TIMES/2; $i ++) {
|
||||
go (function() use ($serv,$data, $i){
|
||||
//echo "user sleep start\n";
|
||||
co::sleep(0.01);
|
||||
//echo "user sleep end\n";
|
||||
$serv->send($data['fd'], str_repeat('A', SIZE) . "\r\n\r\n");
|
||||
//echo "user process $i send ok\n";
|
||||
});
|
||||
}
|
||||
}, false, true);
|
||||
|
||||
$serv->addProcess($proc);
|
||||
$serv->on("WorkerStart", function (\swoole_server $serv) use ($pm) {
|
||||
$pm->wakeup();
|
||||
});
|
||||
$serv->on("Receive", function (\swoole_server $serv, $fd, $reactorId, $data) use ($proc) {
|
||||
$proc->write(json_encode([
|
||||
'fd' => $fd
|
||||
]));
|
||||
for ($i = 0; $i < TIMES/2; $i ++) {
|
||||
go (function() use ($serv,$fd, $i){
|
||||
//echo "worker sleep start\n";
|
||||
co::sleep(0.01);
|
||||
//echo "worker sleep end\n";
|
||||
$serv->send($fd, str_repeat('A', SIZE) . "\r\n\r\n");
|
||||
//echo "worker send $i ok\n";
|
||||
});
|
||||
}
|
||||
});
|
||||
$serv->start();
|
||||
};
|
||||
|
||||
$pm->childFirst();
|
||||
$pm->run();
|
||||
?>
|
||||
--EXPECT--
|
70
vendor/swoole/tests/swoole_coroutine/user_coroutine.phpt
vendored
Executable file
70
vendor/swoole/tests/swoole_coroutine/user_coroutine.phpt
vendored
Executable file
@ -0,0 +1,70 @@
|
||||
--TEST--
|
||||
swoole_coroutine: user coroutine
|
||||
--SKIPIF--
|
||||
<?php require __DIR__ . '/../include/skipif.inc'; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once __DIR__ . '/../include/bootstrap.php';
|
||||
require_once __DIR__ . '/../include/swoole.inc';
|
||||
require_once __DIR__ . '/../include/lib/curl.php';
|
||||
|
||||
use Swoole\Coroutine\Http\Client as HttpClient;
|
||||
|
||||
$pm = new ProcessManager;
|
||||
|
||||
$pm->parentFunc = function ($pid)
|
||||
{
|
||||
$data = curlGet("http://127.0.0.1:9501/");
|
||||
assert(strlen($data) > 1024);
|
||||
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)
|
||||
{
|
||||
Swoole\Coroutine::create(function () use ($response)
|
||||
{
|
||||
$url = 'http://news.bitauto.com/xinche/';
|
||||
$components = parse_url($url);
|
||||
|
||||
if (!isset($components['host']))
|
||||
{
|
||||
throw new \Exception("{$url} parse no host");
|
||||
}
|
||||
|
||||
$host = $components['host'];
|
||||
|
||||
$ip = swoole_async_dns_lookup_coro($host);
|
||||
$port = isset($components['port']) ? $components['port'] : 80;
|
||||
$client = new HttpClient($ip, $port);
|
||||
|
||||
$client->setHeaders([
|
||||
'Host' => $host,
|
||||
'User-Agent' => 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:28.0) Gecko/20100101 Firefox/28.0',
|
||||
]);
|
||||
$client->set(['timeout' => 10]);
|
||||
$client->get(isset($components['path']) ? $components['path'] : '/');
|
||||
$response->end($client->body);
|
||||
});
|
||||
});
|
||||
$http->start();
|
||||
};
|
||||
|
||||
$pm->childFirst();
|
||||
$pm->run();
|
||||
?>
|
||||
--EXPECT--
|
||||
|
16
vendor/swoole/tests/swoole_coroutine/user_coroutine_2.phpt
vendored
Executable file
16
vendor/swoole/tests/swoole_coroutine/user_coroutine_2.phpt
vendored
Executable file
@ -0,0 +1,16 @@
|
||||
--TEST--
|
||||
swoole_coroutine: user coroutine
|
||||
--SKIPIF--
|
||||
<?php require __DIR__ . '/../include/skipif.inc'; ?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once __DIR__ . '/../include/bootstrap.php';
|
||||
require_once __DIR__ . '/../include/swoole.inc';
|
||||
Swoole\Coroutine::create(function ()
|
||||
{
|
||||
echo "OK\n";
|
||||
});
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
OK
|
Reference in New Issue
Block a user