Skip to content

Commit

Permalink
Optimize tests
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed Sep 11, 2024
1 parent 5f6d0e2 commit fa56140
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion core-tests/src/os/async.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ TEST(async, schedule) {
break;
} else if (count == N - 1) {
ASSERT_EQ(SwooleTG.async_threads->get_worker_num(), 4);
ASSERT_EQ(SwooleTG.async_threads->get_queue_size(), 1);
ASSERT_LE(SwooleTG.async_threads->get_queue_size(), 1);
ASSERT_EQ(SwooleTG.async_threads->get_task_num(), 1);
} else if (count < N / 2) {
ASSERT_GT(SwooleTG.async_threads->get_worker_num(), 4);
Expand Down
19 changes: 14 additions & 5 deletions tests/swoole_server/task/task_ipc_mode_2.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,40 @@ swoole_server/task: task_ipc_mode = 2
--FILE--
<?php
require __DIR__ . '/../../include/bootstrap.php';

use Swoole\Atomic;
use Swoole\Http\Request;
use Swoole\Http\Response;

$pm = new SwooleTest\ProcessManager;
$atomic = new Atomic;
$pm->parentFunc = function ($pid) use ($pm) {
go(function () use ($pm) {
echo httpGetBody("http://127.0.0.1:{$pm->getFreePort()}/");
$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,
'task_worker_num' => 4,
'worker_num' => 2,
'task_ipc_mode' => 2,
'dispatch_mode' => 2
]);
$server->on('workerStart', function () use ($pm) {
$pm->wakeup();
$server->on('workerStart', function () use ($pm, $atomic) {
if ($atomic->add() == 6) {
$pm->wakeup();
}
});
$server->on('request', function (Swoole\Http\Request $request, Swoole\Http\Response $response) use ($server) {
$server->on('request', function (Request $request, Response $response) use ($server) {
$response->detach();
$server->task($response->fd);
});
$server->on('task', function ($server, $task_id, $worker_id, string $fd) {
$response = Swoole\Http\Response::create($fd);
$response = Response::create($fd);
$response->end("Hello Swoole!\n");
});
$server->on('finish', function () { });
Expand Down

0 comments on commit fa56140

Please sign in to comment.