-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
122 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
--TEST-- | ||
swoole_server: kill user process [SWOOLE_PROCESS] | ||
--SKIPIF-- | ||
<?php require __DIR__ . "/../include/skipif.inc"; ?> | ||
--FILE-- | ||
<?php | ||
require __DIR__ . "/../include/bootstrap.php"; | ||
|
||
const WORKER_PROC_NAME = 'swoole_unittest_server_user_process'; | ||
$pm = new ProcessManager; | ||
|
||
$pm->parentFunc = function ($pid) use ($pm) { | ||
for ($i = 0; $i < 1; $i++) | ||
{ | ||
//杀死进程 | ||
shell_exec("ps aux | grep \"" . WORKER_PROC_NAME . "\" |grep -v grep| awk '{ print $2}' | xargs kill"); | ||
usleep(10000); | ||
//判断进程是否存在 | ||
assert(intval(shell_exec("ps aux | grep \"" . WORKER_PROC_NAME . "\" |grep -v grep| awk '{ print $2}'")) > 0); | ||
} | ||
$pm->kill(); | ||
}; | ||
|
||
$pm->childFunc = function () use ($pm) | ||
{ | ||
$serv = new \swoole_server('127.0.0.1', $pm->getFreePort(), SWOOLE_PROCESS); | ||
// $serv->set( | ||
// ['log_file' => TEST_LOG_FILE,] | ||
// ); | ||
$process2 = new swoole_process(function ($worker) use ($serv) { | ||
global $argv; | ||
swoole_set_process_name(WORKER_PROC_NAME); | ||
swoole_timer_after(200000, function ($interval) use ($worker, $serv) { | ||
echo "OK\n"; | ||
}); | ||
}, false); | ||
$serv->addProcess($process2); | ||
$serv->set(["worker_num" => 2, 'log_file' => '/dev/null',]); | ||
$serv->on("WorkerStart", function (\swoole_server $serv, $worker_id) use ($pm) { | ||
|
||
}); | ||
$serv->on("Receive", function (\swoole_server $serv, $fd, $reactorId, $data) | ||
{ | ||
}); | ||
$serv->start(); | ||
}; | ||
|
||
$pm->childFirst(); | ||
$pm->run(); | ||
|
||
?> | ||
--EXPECT-- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
--TEST-- | ||
swoole_server: kill user process [SWOOLE_BASE] | ||
--SKIPIF-- | ||
<?php require __DIR__ . "/../include/skipif.inc"; ?> | ||
--FILE-- | ||
<?php | ||
require __DIR__ . "/../include/bootstrap.php"; | ||
|
||
const WORKER_PROC_NAME = 'swoole_unittest_server_user_process'; | ||
$pm = new ProcessManager; | ||
|
||
$pm->parentFunc = function ($pid) use ($pm) { | ||
for ($i = 0; $i < 1; $i++) | ||
{ | ||
//杀死进程 | ||
shell_exec("ps aux | grep \"" . WORKER_PROC_NAME . "\" |grep -v grep| awk '{ print $2}' | xargs kill"); | ||
usleep(10000); | ||
//判断进程是否存在 | ||
assert(intval(shell_exec("ps aux | grep \"" . WORKER_PROC_NAME . "\" |grep -v grep| awk '{ print $2}'")) > 0); | ||
} | ||
$pm->kill(); | ||
}; | ||
|
||
$pm->childFunc = function () use ($pm) | ||
{ | ||
$serv = new \swoole_server('127.0.0.1', $pm->getFreePort(), SWOOLE_BASE); | ||
// $serv->set( | ||
// ['log_file' => TEST_LOG_FILE,] | ||
// ); | ||
$process2 = new swoole_process(function ($worker) use ($serv) { | ||
global $argv; | ||
swoole_set_process_name(WORKER_PROC_NAME); | ||
swoole_timer_after(200000, function ($interval) use ($worker, $serv) { | ||
echo "OK\n"; | ||
}); | ||
}, false); | ||
$serv->addProcess($process2); | ||
$serv->set(["worker_num" => 2, 'log_file' => '/dev/null',]); | ||
$serv->on("WorkerStart", function (\swoole_server $serv, $worker_id) use ($pm) { | ||
|
||
}); | ||
$serv->on("Receive", function (\swoole_server $serv, $fd, $reactorId, $data) | ||
{ | ||
}); | ||
$serv->start(); | ||
}; | ||
|
||
$pm->childFirst(); | ||
$pm->run(); | ||
|
||
?> | ||
--EXPECT-- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters