From 1ce0a5c7a35ec6af698ad2a424b6231c90631c67 Mon Sep 17 00:00:00 2001 From: matyhtf Date: Wed, 23 Oct 2024 19:39:40 +0800 Subject: [PATCH] fix tests [2], --filter=[unit] --- tests/include/api/exit.php | 38 ++++++++++------- tests/swoole_coroutine/check.phpt | 17 +++++--- tests/swoole_coroutine/exit.phpt | 4 +- tests/swoole_coroutine/exit_84.phpt | 15 +++++++ .../exit_exception_backtrace.phpt | 4 +- .../exit_exception_backtrace_84.phpt | 42 +++++++++++++++++++ tests/swoole_server/task/task_ipc_mode_3.phpt | 10 +++-- 7 files changed, 106 insertions(+), 24 deletions(-) create mode 100644 tests/swoole_coroutine/exit_84.phpt create mode 100644 tests/swoole_coroutine/exit_exception_backtrace_84.phpt diff --git a/tests/include/api/exit.php b/tests/include/api/exit.php index 0993c3488b6..6641293b9f0 100644 --- a/tests/include/api/exit.php +++ b/tests/include/api/exit.php @@ -1,18 +1,26 @@ '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() { @@ -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 diff --git a/tests/swoole_coroutine/check.phpt b/tests/swoole_coroutine/check.phpt index d858f279b12..ab166aaee93 100644 --- a/tests/swoole_coroutine/check.phpt +++ b/tests/swoole_coroutine/check.phpt @@ -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]); @@ -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 diff --git a/tests/swoole_coroutine/exit.phpt b/tests/swoole_coroutine/exit.phpt index e378879d837..50d710f449b 100644 --- a/tests/swoole_coroutine/exit.phpt +++ b/tests/swoole_coroutine/exit.phpt @@ -1,7 +1,9 @@ --TEST-- swoole_coroutine: exit --SKIPIF-- - + --FILE-- +--FILE-- + +--EXPECTF-- +int(1) +string(4) "exit" +int(0) diff --git a/tests/swoole_coroutine/exit_exception_backtrace.phpt b/tests/swoole_coroutine/exit_exception_backtrace.phpt index 486ccabe913..66007ed34dd 100644 --- a/tests/swoole_coroutine/exit_exception_backtrace.phpt +++ b/tests/swoole_coroutine/exit_exception_backtrace.phpt @@ -1,7 +1,9 @@ --TEST-- swoole_coroutine: exit exception backtrace --SKIPIF-- - + --FILE-- +--FILE-- + +--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 + diff --git a/tests/swoole_server/task/task_ipc_mode_3.phpt b/tests/swoole_server/task/task_ipc_mode_3.phpt index 438a98d9200..c4179e4e5a4 100644 --- a/tests/swoole_server/task/task_ipc_mode_3.phpt +++ b/tests/swoole_server/task/task_ipc_mode_3.phpt @@ -5,6 +5,7 @@ swoole_server/task: task_ipc_mode = 3 --FILE-- parentFunc = function ($pid) use ($pm) { go(function () use ($pm) { @@ -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();