com php-src: OpenSSL: Improve non-blocking eof test: ext/openssl/tests/ServerClientTestCase.inc ext/openssl/tests/bug77390.phpt

From: Date: Wed, 20 Feb 2019 11:11:30 +0000
Subject: com php-src: OpenSSL: Improve non-blocking eof test: ext/openssl/tests/ServerClientTestCase.inc ext/openssl/tests/bug77390.phpt
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-104776@lists.php.net to get a copy of this message
Commit: 74888bede8cb62c31959bb13d92295a79b5abe2e Author: Abyr Valg <valga@abyrga.ru> Sat, 9 Feb 2019 12:15:55 +0300 Committer: Nikita Popov <nikita.ppv@gmail.com> Wed, 20 Feb 2019 12:11:30 +0100 Parents: 7a9c20f3fd9152ddf1e55aef9120ecfcf4f87613 Branches: PHP-7.2 PHP-7.3 PHP-7.4 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=74888bede8cb62c31959bb13d92295a79b5abe2e Log: OpenSSL: Improve non-blocking eof test Changed paths: M ext/openssl/tests/ServerClientTestCase.inc M ext/openssl/tests/bug77390.phpt Diff: diff --git a/ext/openssl/tests/ServerClientTestCase.inc b/ext/openssl/tests/ServerClientTestCase.inc index 4bad3c2..7576764 100644 --- a/ext/openssl/tests/ServerClientTestCase.inc +++ b/ext/openssl/tests/ServerClientTestCase.inc @@ -9,9 +9,9 @@ function phpt_notify($worker = WORKER_DEFAULT_NAME) ServerClientTestCase::getInstance()->notify($worker); } -function phpt_wait($worker = WORKER_DEFAULT_NAME) +function phpt_wait($worker = WORKER_DEFAULT_NAME, $timeout = null) { - ServerClientTestCase::getInstance()->wait($worker); + ServerClientTestCase::getInstance()->wait($worker, $timeout); } /** @@ -121,9 +121,24 @@ class ServerClientTestCase } } - public function wait($worker) + public function wait($worker, $timeout = null) { - fgets($this->isWorker ? STDIN : $this->workerStdOut[$worker]); + $handle = $this->isWorker ? STDIN : $this->workerStdOut[$worker]; + if ($timeout === null) { + fgets($handle); + return true; + } + + stream_set_blocking($handle, false); + $read = [$handle]; + $result = stream_select($read, $write, $except, $timeout); + if (!$result) { + return false; + } + + fgets($handle); + stream_set_blocking($handle, true); + return true; } public function notify($worker) diff --git a/ext/openssl/tests/bug77390.phpt b/ext/openssl/tests/bug77390.phpt index 7f15329..a71275e 100644 --- a/ext/openssl/tests/bug77390.phpt +++ b/ext/openssl/tests/bug77390.phpt @@ -23,16 +23,21 @@ $clientCode = <<<'CODE' $read = [$fp]; $buf = ''; - $printed = false; + $warmedUp = false; while (stream_select($read, $write, $except, 1000)) { $chunk = stream_get_contents($fp, 4096); - if ($chunk !== "") { - var_dump($chunk); - $buf .= $chunk; - } elseif (!$printed) { - $printed = true; - var_dump($chunk); + $buf .= $chunk; + phpt_notify('proxy'); + if (!$warmedUp) { + if ($buf !== 'warmup') { + continue; + } + $warmedUp = true; + $buf = ''; + phpt_notify('server'); + continue; } + var_dump($chunk); if ($buf === 'hello, world') { break; } @@ -51,6 +56,8 @@ $serverCode = <<<'CODE' phpt_notify(); $conn = stream_socket_accept($fp); + fwrite($conn, 'warmup'); + phpt_wait(); fwrite($conn, 'hello, world'); phpt_wait(); @@ -82,7 +89,7 @@ $proxyCode = <<<'CODE' $parts = str_split($data, (int) ceil(strlen($data) / 3)); foreach ($parts as $part) { fwrite($conn, $part); - usleep(1000); + phpt_wait(null, 1); } } else { fwrite($conn, $data); @@ -116,4 +123,5 @@ ServerClientTestCase::getInstance()->run($clientCode, [ ?> --EXPECT-- string(0) "" +string(0) "" string(12) "hello, world"

« previous php.cvs (#104776) next »