From 3852a35fdbcb62f2e9248364a89ffdd452097d51 Mon Sep 17 00:00:00 2001 From: Joe Watkins Date: Sat, 15 Jun 2019 09:57:51 +0200 Subject: [PATCH] This test is flaky, and some of it doesn't make sense. I've refactored based on the original bug report, related bugs, and commits to php-src that were related to them. It is supposed to be testing windows specific behaviour related to non-blocking pipes, nevertheless the test runs everywhere. --- .../tests/streams/proc_open_bug60120.phpt | 121 +++++++++++------- 1 file changed, 74 insertions(+), 47 deletions(-) diff --git a/ext/standard/tests/streams/proc_open_bug60120.phpt b/ext/standard/tests/streams/proc_open_bug60120.phpt index d12833864a..053de2ebe0 100644 --- a/ext/standard/tests/streams/proc_open_bug60120.phpt +++ b/ext/standard/tests/streams/proc_open_bug60120.phpt @@ -1,70 +1,97 @@ --TEST-- -Bug #60120 proc_open hangs with stdin/out with 2048+ bytes +Bug #60120 proc_open hangs with stdin/out with >2048 bytes --FILE-- +TMPFILE +); -$options = array_merge(array('suppress_errors' => true, 'bypass_shell' => false)); -$process = proc_open($cmd, $descriptors, $pipes, getcwd(), array(), $options); +$command = sprintf("%s -n %s", PHP_BINARY, $file); -foreach ($pipes as $pipe) { - stream_set_blocking($pipe, false); +$process = proc_open( + $command, + [ + ['pipe', 'r'], + ['pipe', 'w'], + ['pipe', 'w'] + ], + $pipes, + getcwd(), + [], + [ + 'suppress_errors' => true, + 'bypass_shell' => false + ] +); + +if (!is_resource($process)) { + die(sprintf( + "could not open process \"%s\"", + $command)); } -$writePipes = array($pipes[0]); -$stdinLen = strlen($stdin); -$stdinOffset = 0; -unset($pipes[0]); +fwrite($pipes[0], str_repeat('*', 10000)); +fclose($pipes[0]); -while ($pipes || $writePipes) { - $r = $pipes; - $w = $writePipes; - $e = null; - $n = stream_select($r, $w, $e, 60); +stream_set_blocking($pipes[1], false); +stream_set_blocking($pipes[2], false); - if (false === $n) { - break; - } elseif ($n === 0) { - proc_terminate($process); +$buffers = [ + 1 => "", + 2 => "" +]; - } - if ($w) { - $written = fwrite($writePipes[0], substr($stdin, $stdinOffset), 8192); - if (false !== $written) { - $stdinOffset += $written; - } - if ($stdinOffset >= $stdinLen) { - fclose($writePipes[0]); - $writePipes = null; +do { + $r = [$pipes[1], $pipes[2]]; + $w = []; + $e = []; + $s = stream_select($r, $w, $e, 60); + + if (!$s) { + if ($s === false) { + proc_terminate($process); } + break; } - foreach ($r as $pipe) { - $type = array_search($pipe, $pipes); - $data = fread($pipe, 8192); - var_dump($data); - if (false === $data || feof($pipe)) { - fclose($pipe); - unset($pipes[$type]); - } + foreach ($r as $ready) { + $buffers[ + array_search($ready, $pipes) + ] .= fread($ready, 8192); } -} + if (strlen($buffers[1]) === 10000 && + strlen($buffers[2]) === 10000) { + break; + } +} while (1); + +var_dump( + $buffers[1], + $buffers[2], + fread($pipes[1], 1), + fread($pipes[2], 1)); +fclose($pipes[1]); +fclose($pipes[2]); ?> -===DONE=== --EXPECTF-- -string(2049) "%s" -string(2049) "%s" +string(10000) "%s" +string(10000) "%s" string(0) "" string(0) "" -===DONE=== +--CLEAN-- +unlink($file); -- 2.40.0