Skip to content

Commit e5304bb

Browse files
committed
Add a --shuffle mode to run-tests
Makes it easier to find paralellization issues. Of course only works if the tests aren't order-dependent...
1 parent 4f2ad75 commit e5304bb

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

run-tests.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ function main()
5353
$repeat, $result_tests_file, $slow_min_ms, $start_time, $switch,
5454
$temp_source, $temp_target, $temp_urlbase, $test_cnt, $test_dirs,
5555
$test_files, $test_idx, $test_list, $test_results, $testfile,
56-
$user_tests, $valgrind, $sum_results;
56+
$user_tests, $valgrind, $sum_results, $shuffle;
5757
// Parallel testing
5858
global $workers, $workerID;
5959

@@ -320,6 +320,7 @@ function main()
320320
$no_clean = false;
321321
$slow_min_ms = INF;
322322
$preload = false;
323+
$shuffle = false;
323324
$workers = null;
324325

325326
$cfgtypes = array('show', 'keep');
@@ -502,6 +503,9 @@ function main()
502503
case '--offline':
503504
$environment['SKIP_ONLINE_TESTS'] = 1;
504505
break;
506+
case '--shuffle':
507+
$shuffle = true;
508+
break;
505509
//case 'w'
506510
case '-':
507511
// repeat check with full switch
@@ -1333,7 +1337,7 @@ function run_all_tests($test_files, $env, $redir_tested = null)
13331337

13341338
/** The heart of parallel testing. */
13351339
function run_all_tests_parallel($test_files, $env, $redir_tested) {
1336-
global $workers, $test_idx, $test_cnt, $test_results, $failed_tests_file, $result_tests_file, $PHP_FAILED_TESTS;
1340+
global $workers, $test_idx, $test_cnt, $test_results, $failed_tests_file, $result_tests_file, $PHP_FAILED_TESTS, $shuffle;
13371341

13381342
// The PHP binary running run-tests.php, and run-tests.php itself
13391343
// This PHP executable is *not* necessarily the same as the tested version
@@ -1378,6 +1382,11 @@ function run_all_tests_parallel($test_files, $env, $redir_tested) {
13781382
// for tests with a common conflict key.
13791383
$test_files = array_reverse($test_files);
13801384

1385+
// To discover parallelization issues it is useful to randomize the test order.
1386+
if ($shuffle) {
1387+
shuffle($test_files);
1388+
}
1389+
13811390
echo "Spawning workers… ";
13821391

13831392
// We use sockets rather than STDIN/STDOUT for comms because on Windows,
@@ -1518,7 +1527,7 @@ function run_all_tests_parallel($test_files, $env, $redir_tested) {
15181527
case "ready":
15191528
// Batch multiple tests to reduce communication overhead.
15201529
$files = [];
1521-
$batchSize = 32;
1530+
$batchSize = $shuffle ? 4 : 32;
15221531
while (count($files) <= $batchSize && $file = array_pop($test_files)) {
15231532
foreach ($fileConflictsWith[$file] as $conflictKey) {
15241533
if (isset($activeConflicts[$conflictKey])) {

0 commit comments

Comments
 (0)