Shuffle tests for a single worker

Even when tests are not run in parallel, shuffling can help discover tests that
unintentionally depend on other tests being run before them.

Closes GH-17149.
This commit is contained in:
dhuang00 2024-12-13 14:03:13 -05:00 committed by Niels Dossche
parent 23ccd06ede
commit 71dfa931eb
No known key found for this signature in database
GPG key ID: B8A8AD166DF0E2E5
2 changed files with 11 additions and 6 deletions

3
NEWS
View file

@ -93,6 +93,9 @@ PHP NEWS
. Fixed bug GH-16889 (stream_select() timeout useless for pipes on Windows).
(cmb)
- Tests:
. Allow to shuffle tests even in non-parallell mode. (dhuang00)
- Windows:
. Fixed bug GH-10992 (Improper long path support for relative paths). (cmb,
nielsdos)

View file

@ -1231,7 +1231,7 @@ function system_with_timeout(
function run_all_tests(array $test_files, array $env, ?string $redir_tested = null): void
{
global $test_results, $failed_tests_file, $result_tests_file, $php, $test_idx, $file_cache;
global $test_results, $failed_tests_file, $result_tests_file, $php, $test_idx, $file_cache, $shuffle;
global $preload;
// Parallel testing
global $PHP_FAILED_TESTS, $workers, $workerID, $workerSock;
@ -1253,6 +1253,11 @@ function run_all_tests(array $test_files, array $env, ?string $redir_tested = nu
});
}
// To discover parallelization issues and order dependent tests it is useful to randomize the test order.
if ($shuffle) {
shuffle($test_files);
}
/* Ignore -jN if there is only one file to analyze. */
if ($workers !== null && count($test_files) > 1 && !$workerID) {
run_all_tests_parallel($test_files, $env, $redir_tested);
@ -1358,11 +1363,8 @@ function run_all_tests_parallel(array $test_files, array $env, ?string $redir_te
// Some tests assume that they are executed in a certain order. We will be popping from
// $test_files, so reverse its order here. This makes sure that order is preserved at least
// for tests with a common conflict key.
if (!$shuffle) {
$test_files = array_reverse($test_files);
// To discover parallelization issues it is useful to randomize the test order.
if ($shuffle) {
shuffle($test_files);
}
// Don't start more workers than test files.