From 2a359d1f2f6174bdbb5a582b137c6312928ebe2c Mon Sep 17 00:00:00 2001 From: Bruce Dou Date: Fri, 8 Dec 2023 16:34:21 +0000 Subject: [PATCH] added test for #343 (#346) --- tests/swoole_coroutine/file_get_content.phpt | 54 ++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 tests/swoole_coroutine/file_get_content.phpt diff --git a/tests/swoole_coroutine/file_get_content.phpt b/tests/swoole_coroutine/file_get_content.phpt new file mode 100644 index 000000000..e40864b17 --- /dev/null +++ b/tests/swoole_coroutine/file_get_content.phpt @@ -0,0 +1,54 @@ +--TEST-- +swoole_coroutine: file_get_content +--SKIPIF-- + +--FILE-- +useConstantPorts = true; +$pm->initFreePorts(); + +use OpenSwoole\Constant; +use OpenSwoole\Http\Request; +use OpenSwoole\Http\Response; +use OpenSwoole\Http\Server; +use OpenSwoole\Runtime; +use OpenSwoole\Util; + +$pm->parentFunc = function (int $pid) use ($pm) { + co::run(function () use ($pm) { + $data = httpGetBody("http://127.0.0.1:{$pm->getFreePort()}/"); + echo $data; + }); + echo "DONE\n"; + unlink('FILENAME'); + $pm->kill(); +}; +$pm->childFunc = function () use ($pm) { + $Server = new Server('127.0.0.1', $pm->getFreePort()); + $Server->set([ + 'reactor_num' => Util::getCPUNum() * 1, + 'hook_flags' => Runtime::HOOK_ALL, + 'log_level' => Constant::LOG_DEBUG, + 'log_file' => '/proc/1/fd/1', + 'tcp_fastopen' => true, + 'open_tcp_keepalive' => true, + 'http_compression' => true, + 'http_compression_level' => 6, + 'open_http2_protocol' => true, + 'compression_min_length' => 128, + 'backlog' => 100000, + 'reload_async' => false, + ]); + $Server->on('Request', static function (Request $Request, Response $Response): void { + file_put_contents('FILENAME', 'CONTENTS'); + $Response->end(file_get_contents('FILENAME')); + }); + $Server->start(); +}; +$pm->childFirst(); +$pm->run(); +?> +--EXPECTF-- +CONTENTSDONE \ No newline at end of file