Skip to content

Commit

Permalink
Optimize GH-5671 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
matyhtf committed Feb 14, 2025
1 parent d14fcea commit 5ad750f
Showing 1 changed file with 19 additions and 31 deletions.
50 changes: 19 additions & 31 deletions tests/swoole_server/single_thread/user_setting.phpt
Original file line number Diff line number Diff line change
@@ -1,56 +1,44 @@
--TEST--
swoole_server/single_thread: package_length_func
swoole_server/single_thread: user setting
--SKIPIF--
<?php require __DIR__ . '/../../include/skipif.inc';
<?php
require __DIR__ . '/../../include/skipif.inc';
skip_if_not_root();
?>
--FILE--
<?php
require __DIR__ . '/../../include/bootstrap.php';

$log_file = tempnam('/tmp', 'swoole_test_');
chmod($log_file, 0777);
file_put_contents($log_file, '');

$pm = new SwooleTest\ProcessManager;
$pm->parentFunc = function ($pid) use ($pm) {
$pm->parentFunc = function ($pid) use ($pm, $log_file) {
$url = 'http://127.0.0.1:' . $pm->getFreePort() . '/';
$filePath = tempnam('/tmp', 'swoole_test_');
$rdata = random_bytes(1024 * 1024);
file_put_contents($filePath, $rdata);
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Accept: text/html',
'Content-Type: multipart/form-data'
]);
curl_setopt($ch, CURLOPT_POSTFIELDS, [
'file' => new CURLFile($filePath, 'text/html')
]);
$response = curl_exec($ch);
if (curl_errno($ch)) {
echo 'ERROR: ' . curl_error($ch);
} else {
Assert::eq($response, md5($rdata));
}
curl_close($ch);
unlink($filePath);
posix_kill($pid, SIGUSR1);
sleep(1);
$output = file_get_contents($log_file);
Assert::contains($output, 'reloading all workers');
Assert::contains($output, 'failed to push WORKER_STOP message');
$pm->kill();
unlink($log_file);
};

$pm->childFunc = function () use ($pm) {
$pm->childFunc = function () use ($pm, $log_file) {
$http = new Swoole\Http\Server('0.0.0.0', $pm->getFreePort(), SWOOLE_PROCESS);
$http->set([
'single_thread' => true,
'worker_num' => 1,
'user' => 'www-data',
'user' => 'www-data',
'group' => 'www-data',
'heartbeat_idle_time' => 600,
'heartbeat_check_interval' => 30,
'log_file' => $log_file,
]);
$http->on('WorkerStart', function (Swoole\Http\Server $serv) use ($pm) {
$pm->wakeup();
});
$http->on('Request', function ($request, $response) {
$response->end(md5_file($request->files['file']['tmp_name']));
$response->end('hello');
});
$http->start();
};
Expand Down

0 comments on commit 5ad750f

Please sign in to comment.