Skip to content

Commit 5ad750f

Browse files
committed
Optimize GH-5671 tests
1 parent d14fcea commit 5ad750f

File tree

1 file changed

+19
-31
lines changed

1 file changed

+19
-31
lines changed

tests/swoole_server/single_thread/user_setting.phpt

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,44 @@
11
--TEST--
2-
swoole_server/single_thread: package_length_func
2+
swoole_server/single_thread: user setting
33
--SKIPIF--
4-
<?php require __DIR__ . '/../../include/skipif.inc';
4+
<?php
5+
require __DIR__ . '/../../include/skipif.inc';
6+
skip_if_not_root();
57
?>
68
--FILE--
79
<?php
810
require __DIR__ . '/../../include/bootstrap.php';
911

12+
$log_file = tempnam('/tmp', 'swoole_test_');
13+
chmod($log_file, 0777);
14+
file_put_contents($log_file, '');
15+
1016
$pm = new SwooleTest\ProcessManager;
11-
$pm->parentFunc = function ($pid) use ($pm) {
17+
$pm->parentFunc = function ($pid) use ($pm, $log_file) {
1218
$url = 'http://127.0.0.1:' . $pm->getFreePort() . '/';
13-
$filePath = tempnam('/tmp', 'swoole_test_');
14-
$rdata = random_bytes(1024 * 1024);
15-
file_put_contents($filePath, $rdata);
16-
$ch = curl_init();
17-
18-
curl_setopt($ch, CURLOPT_URL, $url);
19-
curl_setopt($ch, CURLOPT_POST, true);
20-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
21-
curl_setopt($ch, CURLOPT_HTTPHEADER, [
22-
'Accept: text/html',
23-
'Content-Type: multipart/form-data'
24-
]);
25-
curl_setopt($ch, CURLOPT_POSTFIELDS, [
26-
'file' => new CURLFile($filePath, 'text/html')
27-
]);
28-
$response = curl_exec($ch);
29-
if (curl_errno($ch)) {
30-
echo 'ERROR: ' . curl_error($ch);
31-
} else {
32-
Assert::eq($response, md5($rdata));
33-
}
34-
curl_close($ch);
35-
unlink($filePath);
19+
posix_kill($pid, SIGUSR1);
20+
sleep(1);
21+
$output = file_get_contents($log_file);
22+
Assert::contains($output, 'reloading all workers');
23+
Assert::contains($output, 'failed to push WORKER_STOP message');
3624
$pm->kill();
25+
unlink($log_file);
3726
};
3827

39-
$pm->childFunc = function () use ($pm) {
28+
$pm->childFunc = function () use ($pm, $log_file) {
4029
$http = new Swoole\Http\Server('0.0.0.0', $pm->getFreePort(), SWOOLE_PROCESS);
4130
$http->set([
4231
'single_thread' => true,
4332
'worker_num' => 1,
44-
'user' => 'www-data',
33+
'user' => 'www-data',
4534
'group' => 'www-data',
46-
'heartbeat_idle_time' => 600,
47-
'heartbeat_check_interval' => 30,
35+
'log_file' => $log_file,
4836
]);
4937
$http->on('WorkerStart', function (Swoole\Http\Server $serv) use ($pm) {
5038
$pm->wakeup();
5139
});
5240
$http->on('Request', function ($request, $response) {
53-
$response->end(md5_file($request->files['file']['tmp_name']));
41+
$response->end('hello');
5442
});
5543
$http->start();
5644
};

0 commit comments

Comments
 (0)