From 534c5a691b24af8785b58ea92bfc8ee67277d1ee Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Tue, 17 Dec 2024 13:57:24 +0100 Subject: [PATCH 1/2] Reintroduce proc_open_multiplex.phpt The main intent of the test was to show the changed behavior on Windows; previously, `stream_select()` would return immediately there, reporting all pipes as ready; now, it only returns if at least one pipe is actually ready. The original test case was overspecified; of course, we cannot assume that the pipes are ready one after the other; depending on the concrete `select(2)` implementation and the system scheduler, minor differences are to be expected. Thus we relax the test expectations, and now require that not all pipes are reported ready after a single `stream_select()` call, and that the output contains all strings. We also ensure that `stream_select()` doesn't fail (for whatever reason). And in case of the test expectations not being met, we also output some diagnostics (most notably the output that has already been read). --- .../proc_open_multiplex.phpt | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 ext/standard/tests/general_functions/proc_open_multiplex.phpt diff --git a/ext/standard/tests/general_functions/proc_open_multiplex.phpt b/ext/standard/tests/general_functions/proc_open_multiplex.phpt new file mode 100644 index 0000000000000..faf36c00af1c8 --- /dev/null +++ b/ext/standard/tests/general_functions/proc_open_multiplex.phpt @@ -0,0 +1,51 @@ +--TEST-- +Multiplexing of child output +--FILE-- + 0) { + foreach ($rset as $pipe) { + if ($selected === 10) { + echo "stream_select() reported all pipes as ready\n"; + echo "Read:\n", implode("\n", $out); + exit; + } + $out[] = fread($pipe, 6); + unset($read_pipes[array_search($pipe, $read_pipes)]); + } + $rset = $read_pipes; +} +if ($selected === false) { + echo "stream_select() failed\n"; + echo "Read:\n", implode("\n", $out); + exit; +} +sort($out); +echo "Read:\n", implode("\n", $out); +?> +--EXPECT-- +Read: +hello0 +hello1 +hello2 +hello3 +hello4 +hello5 +hello6 +hello7 +hello8 +hello9 From 0ad91dc8006b0ff7b7682e156288bddd68f3a9ac Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Sun, 22 Dec 2024 16:35:57 +0100 Subject: [PATCH 2/2] Reduce sleep time --- ext/standard/tests/general_functions/proc_open_multiplex.phpt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/standard/tests/general_functions/proc_open_multiplex.phpt b/ext/standard/tests/general_functions/proc_open_multiplex.phpt index faf36c00af1c8..63e856b29c31e 100644 --- a/ext/standard/tests/general_functions/proc_open_multiplex.phpt +++ b/ext/standard/tests/general_functions/proc_open_multiplex.phpt @@ -10,14 +10,14 @@ $desc = [ ]; $read_pipes = []; for ($i = 0; $i < 10; $i++) { - $procs[] = proc_open([$php, "-r", "usleep(100000 * (10 - $i)); echo 'hello$i';"], $desc, $pipes); + $procs[] = proc_open([$php, "-r", "usleep(10000 * (10 - $i)); echo 'hello$i';"], $desc, $pipes); $read_pipes[] = $pipes[1]; } $out = []; $rset = $read_pipes; $wset = null; $eset = null; -while (!empty($read_pipes) && ($selected = stream_select($rset, $wset, $eset, 2)) > 0) { +while (!empty($read_pipes) && ($selected = stream_select($rset, $wset, $eset, 1)) > 0) { foreach ($rset as $pipe) { if ($selected === 10) { echo "stream_select() reported all pipes as ready\n";