Skip to content

Commit

Permalink
fix tests [2], --filter=[unit]
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed Oct 23, 2024
1 parent fde8105 commit 1ce0a5c
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 24 deletions.
38 changes: 24 additions & 14 deletions tests/include/api/exit.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
<?php
declare(strict_types=1);
$exit_status_list = [
'undef',
null,
true,
false,
1,
1.1,
'exit',
['exit' => 'ok'],
(object)['exit' => 'ok'],
STDIN,
0
];
if (PHP_VERSION_ID>= 80400) {
$exit_status_list = [
1,
'exit',
0,
];
} else {
$exit_status_list = [
'undef',
null,
true,
false,
1,
1.1,
'exit',
['exit' => 'ok'],
(object)['exit' => 'ok'],
STDIN,
0
];
}

function route()
{
Expand Down Expand Up @@ -52,7 +60,9 @@ function your_code()
} catch (\Swoole\ExitException $e) {
Assert::assert($e->getFlags() & SWOOLE_EXIT_IN_COROUTINE);
$exit_status = $chan->pop();
$exit_status = $exit_status === 'undef' ? null : $exit_status;
if (PHP_VERSION_ID < 80400) {
$exit_status = $exit_status === 'undef' ? null : $exit_status;
}
Assert::same($e->getStatus(), $exit_status);
var_dump($e->getStatus());
// exit coroutine
Expand Down
17 changes: 12 additions & 5 deletions tests/swoole_coroutine/check.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,16 @@ foreach ($map as $i => $f) {
$process::wait();
if (Assert::contains($info, 'Swoole\\Error')) {
$_info = trim($info);
$_info = preg_replace('/(\#0.+?: )[^\n]+/', '$1%s', $_info, 1);
$_info = preg_replace('/(: )[^\n]+( in )/', '$1%s$2', $_info, 1);
$_info = preg_replace('/\/[^(:]+:?\(?\d+\)?/', '%s:%d', $_info);
if (PHP_VERSION_ID >= 80400) {
$_info = preg_replace('/(\#0.+?: )[^\n]+/', '$1%s', $_info, 1);
$_info = preg_replace('/(: )[^\n]+( in )/', '$1%s$2', $_info, 1);
$_info = preg_replace('/closure:[^(:]+:?\(?\d+\)?/', 'closure', $_info);
$_info = preg_replace('/\/[^(:]+:?\(?\d+\)?/', '%s:%d', $_info);
} else {
$_info = preg_replace('/(\#0.+?: )[^\n]+/', '$1%s', $_info, 1);
$_info = preg_replace('/(: )[^\n]+( in )/', '$1%s$2', $_info, 1);
$_info = preg_replace('/\/[^(:]+:?\(?\d+\)?/', '%s:%d', $_info);
}
$info_list[] = $_info;
if (!Assert::assert($info_list[0] === $_info)) {
var_dump($map[$i]);
Expand All @@ -129,11 +136,11 @@ Swoole\Event::wait();
Fatal error: %s in %s:%d
Stack trace:
#0 %s:%d: %s
#1 %s:%d: {closure%S}()
#1 %s:%d: {closure}()
#2 %s:%d: c()
#3 %s:%d: b()
#4 %s:%d: a()
#5 [internal function]: {closure%S}(Object(Swoole\Process))
#5 [internal function]: {closure}(Object(Swoole\Process))
#6 %s:%d: Swoole\Process->start()
#7 {main}
thrown in %s:%d
4 changes: 3 additions & 1 deletion tests/swoole_coroutine/exit.phpt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
--TEST--
swoole_coroutine: exit
--SKIPIF--
<?php require __DIR__ . '/../include/skipif.inc'; ?>
<?php require __DIR__ . '/../include/skipif.inc';
skip_if_php_version_ge('8.4');
?>
--FILE--
<?php
require __DIR__ . '/../include/bootstrap.php';
Expand Down
15 changes: 15 additions & 0 deletions tests/swoole_coroutine/exit_84.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--TEST--
swoole_coroutine: exit
--SKIPIF--
<?php require __DIR__ . '/../include/skipif.inc';
skip_if_php_version_lower_than('8.4');
?>
--FILE--
<?php
require __DIR__ . '/../include/bootstrap.php';
require TESTS_API_PATH . '/exit.php';
?>
--EXPECTF--
int(1)
string(4) "exit"
int(0)
4 changes: 3 additions & 1 deletion tests/swoole_coroutine/exit_exception_backtrace.phpt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
--TEST--
swoole_coroutine: exit exception backtrace
--SKIPIF--
<?php require __DIR__ . '/../include/skipif.inc'; ?>
<?php require __DIR__ . '/../include/skipif.inc';
skip_if_php_version_ge('8.4');
?>
--FILE--
<?php
require __DIR__ . '/../include/bootstrap.php';
Expand Down
42 changes: 42 additions & 0 deletions tests/swoole_coroutine/exit_exception_backtrace_84.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
--TEST--
swoole_coroutine: exit exception backtrace
--SKIPIF--
<?php require __DIR__ . '/../include/skipif.inc';
skip_if_php_version_lower_than('8.4');
?>
--FILE--
<?php
require __DIR__ . '/../include/bootstrap.php';
function foo()
{
bar(get_safe_random());
}

function bar(string $random)
{
char(mt_rand(0, PHP_INT_MAX));
}

function char(int $random)
{
exit;
}

go(function () {
co::sleep(0.001);
});
go(function () {
foo();
});
?>
--EXPECTF--
Fatal error: Uncaught Swoole\ExitException: swoole exit in %s:%d
Stack trace:
#0 %s(%d): exit()
#1 %s(%d): char(%d)
#2 %s(%d): bar('%s')
#3 %s(%d): foo()
#4 [internal function]: {closure:%s:%d}()
#5 {main}
thrown in %s on line %d

10 changes: 7 additions & 3 deletions tests/swoole_server/task/task_ipc_mode_3.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ swoole_server/task: task_ipc_mode = 3
--FILE--
<?php
require __DIR__ . '/../../include/bootstrap.php';
$atomic = new Swoole\Atomic;
$pm = new SwooleTest\ProcessManager;
$pm->parentFunc = function ($pid) use ($pm) {
go(function () use ($pm) {
Expand All @@ -13,17 +14,20 @@ $pm->parentFunc = function ($pid) use ($pm) {
Swoole\Event::wait();
$pm->kill();
};
$pm->childFunc = function () use ($pm) {
$pm->childFunc = function () use ($pm, $atomic) {
$server = new Swoole\Http\Server('127.0.0.1', $pm->getFreePort(), SERVER_MODE_RANDOM);
$server->set([
'log_file' => '/dev/null',
'open_tcp_nodelay' => true,
'worker_num' => 3,
'task_worker_num' => 4,
'task_ipc_mode' => 3,
'dispatch_mode' => 2
]);
$server->on('workerStart', function () use ($pm) {
$pm->wakeup();
$server->on('workerStart', function () use ($pm, $atomic) {
if ($atomic->add() == 7) {
$pm->wakeup();
}
});
$server->on('request', function (Swoole\Http\Request $request, Swoole\Http\Response $response) use ($server) {
$response->detach();
Expand Down

0 comments on commit 1ce0a5c

Please sign in to comment.