|
1 | 1 | --TEST--
|
2 |
| -swoole_server/single_thread: package_length_func |
| 2 | +swoole_server/single_thread: user setting |
3 | 3 | --SKIPIF--
|
4 |
| -<?php require __DIR__ . '/../../include/skipif.inc'; |
| 4 | +<?php |
| 5 | +require __DIR__ . '/../../include/skipif.inc'; |
| 6 | +skip_if_not_root(); |
5 | 7 | ?>
|
6 | 8 | --FILE--
|
7 | 9 | <?php
|
8 | 10 | require __DIR__ . '/../../include/bootstrap.php';
|
9 | 11 |
|
| 12 | +$log_file = tempnam('/tmp', 'swoole_test_'); |
| 13 | +chmod($log_file, 0777); |
| 14 | +file_put_contents($log_file, ''); |
| 15 | + |
10 | 16 | $pm = new SwooleTest\ProcessManager;
|
11 |
| -$pm->parentFunc = function ($pid) use ($pm) { |
| 17 | +$pm->parentFunc = function ($pid) use ($pm, $log_file) { |
12 | 18 | $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'); |
36 | 24 | $pm->kill();
|
| 25 | + unlink($log_file); |
37 | 26 | };
|
38 | 27 |
|
39 |
| -$pm->childFunc = function () use ($pm) { |
| 28 | +$pm->childFunc = function () use ($pm, $log_file) { |
40 | 29 | $http = new Swoole\Http\Server('0.0.0.0', $pm->getFreePort(), SWOOLE_PROCESS);
|
41 | 30 | $http->set([
|
42 | 31 | 'single_thread' => true,
|
43 | 32 | 'worker_num' => 1,
|
44 |
| - 'user' => 'www-data', |
| 33 | + 'user' => 'www-data', |
45 | 34 | 'group' => 'www-data',
|
46 |
| - 'heartbeat_idle_time' => 600, |
47 |
| - 'heartbeat_check_interval' => 30, |
| 35 | + 'log_file' => $log_file, |
48 | 36 | ]);
|
49 | 37 | $http->on('WorkerStart', function (Swoole\Http\Server $serv) use ($pm) {
|
50 | 38 | $pm->wakeup();
|
51 | 39 | });
|
52 | 40 | $http->on('Request', function ($request, $response) {
|
53 |
| - $response->end(md5_file($request->files['file']['tmp_name'])); |
| 41 | + $response->end('hello'); |
54 | 42 | });
|
55 | 43 | $http->start();
|
56 | 44 | };
|
|
0 commit comments