]> granicus.if.org Git - php/commitdiff
Make proc_open_bug64438.phpt more robust
authorNikita Popov <nikita.ppv@gmail.com>
Thu, 11 Jul 2019 10:32:57 +0000 (12:32 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Thu, 11 Jul 2019 10:46:56 +0000 (12:46 +0200)
The test currently assumes that we'll first read the data of
stdout and stderr and then see eof on stdout and stderr. However
we could also read stdout, see eof on stdout, read stderr and see
eof on stderr, depending on timing.

Avoid output ordering issues by collecting events into a per-pipe
array, so interleaving is not visible.

ext/standard/tests/streams/proc_open_bug64438.phpt

index 454d7748c4448481f0aaef5e2663fb9d48de1b88..2880865e1db2b3d0fe1c708f38cc9513cb545d5a 100644 (file)
@@ -25,6 +25,7 @@ $stdinOffset = 0;
 
 unset($pipes[0]);
 
+$pipeEvents = [];
 while ($pipes || $writePipes) {
     $r = $pipes;
     $w = $writePipes;
@@ -51,19 +52,35 @@ while ($pipes || $writePipes) {
     foreach ($r as $pipe) {
         $type = array_search($pipe, $pipes);
         $data = fread($pipe, 8192);
-        var_dump($data);
         if (false === $data || feof($pipe)) {
+            $pipeEvents[(int)$pipe][] = "Closing pipe";
             fclose($pipe);
             unset($pipes[$type]);
+        } else {
+            $pipeEvents[(int)$pipe][] = "Read " . strlen($data) . " bytes";
         }
     }
 }
 
+var_dump($pipeEvents);
+
 ?>
 ===DONE===
 --EXPECTF--
-string(4097) "%s"
-string(4097) "%s"
-string(0) ""
-string(0) ""
+array(2) {
+  [%d]=>
+  array(2) {
+    [0]=>
+    string(15) "Read 4097 bytes"
+    [1]=>
+    string(12) "Closing pipe"
+  }
+  [%d]=>
+  array(2) {
+    [0]=>
+    string(15) "Read 4097 bytes"
+    [1]=>
+    string(12) "Closing pipe"
+  }
+}
 ===DONE===