Skip to content

Commit 41c7363

Browse files
committed
Account for redirected tests in parallel progress
1 parent 61a190c commit 41c7363

2 files changed

Lines changed: 126 additions & 4 deletions

File tree

run-tests.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,7 +1307,12 @@ function run_all_tests(array $test_files, array $env, ?string $redir_tested = nu
13071307
}
13081308

13091309
/* Ignore -jN if there is only one file to analyze. */
1310-
if ($workers !== null && count($test_files) > 1 && !$workerID) {
1310+
if (
1311+
$workers !== null
1312+
&& count($test_files) > 1
1313+
&& !$workerID
1314+
&& $redir_tested === null
1315+
) {
13111316
run_all_tests_parallel($test_files, $env, $redir_tested);
13121317
return;
13131318
}
@@ -1362,7 +1367,7 @@ function run_all_tests(array $test_files, array $env, ?string $redir_tested = nu
13621367

13631368
function run_all_tests_parallel(array $test_files, array $env, ?string $redir_tested): void
13641369
{
1365-
global $workers, $test_idx, $test_results, $failed_tests_file, $result_tests_file, $PHP_FAILED_TESTS, $shuffle, $valgrind, $show_progress;
1370+
global $workers, $test_cnt, $test_idx, $test_results, $failed_tests_file, $result_tests_file, $PHP_FAILED_TESTS, $shuffle, $valgrind, $show_progress;
13661371

13671372
global $junit;
13681373

@@ -1544,6 +1549,9 @@ function run_all_tests_parallel(array $test_files, array $env, ?string $redir_te
15441549
}
15451550

15461551
switch ($message["type"]) {
1552+
case "test_count_delta":
1553+
$test_cnt += $message["delta"];
1554+
break;
15471555
case "tests_finished":
15481556
$testsInProgress--;
15491557
foreach ($activeConflicts as $key => $workerId) {
@@ -1846,7 +1854,7 @@ function run_test(string $php, $file, array $env): string
18461854
global $preload, $file_cache;
18471855
global $num_repeats;
18481856
// Parallel testing
1849-
global $workerID;
1857+
global $workerID, $workerSock;
18501858
global $show_progress;
18511859

18521860
// Temporary
@@ -2255,7 +2263,14 @@ function run_test(string $php, $file, array $env): string
22552263
$test_files[] = [$f, $file];
22562264
}
22572265
}
2258-
$test_cnt += count($test_files) - 1;
2266+
$testCountDelta = count($test_files) - 1;
2267+
$test_cnt += $testCountDelta;
2268+
if ($workerID && $testCountDelta !== 0) {
2269+
send_message($workerSock, [
2270+
"type" => "test_count_delta",
2271+
"delta" => $testCountDelta,
2272+
]);
2273+
}
22592274
$test_idx--;
22602275

22612276
show_redirect_start($IN_REDIRECT['TESTS'], $tested, $tested_file);
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
--TEST--
2+
Redirected tests work in parallel runs and update the progress total
3+
--ENV--
4+
TEST_PHP_FORK_SERVER=0
5+
--FILE--
6+
<?php
7+
function writeRedirectedTest(string $file, string $name): void
8+
{
9+
file_put_contents($file, <<<PHPT
10+
--TEST--
11+
$name
12+
--FILE--
13+
<?php echo "ok\\n"; ?>
14+
--EXPECT--
15+
ok
16+
PHPT);
17+
}
18+
19+
function runRedirectedTests(array $testFiles): array
20+
{
21+
$command = [
22+
getenv('TEST_PHP_EXECUTABLE'),
23+
'-n',
24+
dirname(__DIR__, 2) . '/run-tests.php',
25+
'-n',
26+
'-q',
27+
'-j2',
28+
'--progress',
29+
...$testFiles,
30+
];
31+
$environment = [
32+
'PATH' => getenv('PATH'),
33+
'TEST_PHP_EXECUTABLE' => getenv('TEST_PHP_EXECUTABLE'),
34+
'TEST_PHP_FORK_SERVER' => '0',
35+
];
36+
foreach (['SystemRoot', 'TEMP', 'TMPDIR'] as $name) {
37+
if (($value = getenv($name)) !== false) {
38+
$environment[$name] = $value;
39+
}
40+
}
41+
42+
$process = proc_open(
43+
$command,
44+
[
45+
0 => ['pipe', 'r'],
46+
1 => ['pipe', 'w'],
47+
2 => ['redirect', 1],
48+
],
49+
$pipes,
50+
null,
51+
$environment,
52+
);
53+
fclose($pipes[0]);
54+
$output = stream_get_contents($pipes[1]);
55+
fclose($pipes[1]);
56+
return [proc_close($process), str_replace("\r", "\n", $output)];
57+
}
58+
59+
$root = __DIR__ . '/redirected_parallel_' . getmypid();
60+
$targets = $root . '/targets';
61+
mkdir($targets, recursive: true);
62+
63+
writeRedirectedTest($targets . '/one.phpt', 'redirected one');
64+
writeRedirectedTest($targets . '/two.phpt', 'redirected two');
65+
66+
$targetExpression = var_export($targets, true);
67+
$redirect = $root . '/redirect.phpt';
68+
file_put_contents($redirect, <<<PHPT
69+
--TEST--
70+
redirect wrapper
71+
--REDIRECTTEST--
72+
return ['ENV' => [], 'TESTS' => $targetExpression];
73+
PHPT);
74+
writeRedirectedTest($root . '/companion.phpt', 'companion');
75+
76+
[$singleExitCode, $singleOutput] = runRedirectedTests([$redirect]);
77+
if ($singleExitCode !== 0) {
78+
echo $singleOutput;
79+
}
80+
var_dump($singleExitCode);
81+
var_dump(str_contains($singleOutput, 'Fatal error'));
82+
83+
[$parallelExitCode, $parallelOutput] = runRedirectedTests([
84+
$redirect,
85+
$root . '/companion.phpt',
86+
]);
87+
if ($parallelExitCode !== 0) {
88+
echo $parallelOutput;
89+
}
90+
var_dump($parallelExitCode);
91+
var_dump(str_contains($parallelOutput, 'TEST 3/3'));
92+
var_dump(str_contains($parallelOutput, 'TEST 3/2'));
93+
94+
foreach (glob($targets . '/*') as $file) {
95+
unlink($file);
96+
}
97+
rmdir($targets);
98+
unlink($root . '/redirect.phpt');
99+
unlink($root . '/companion.phpt');
100+
rmdir($root);
101+
?>
102+
--EXPECT--
103+
int(0)
104+
bool(false)
105+
int(0)
106+
bool(true)
107+
bool(false)

0 commit comments

Comments
 (0)