Skip to content

Commit 3131b67

Browse files
committed
Add retrying mechanism for IO tests in run-tests.php
1 parent 90d4a1e commit 3131b67

File tree

1 file changed

+37
-15
lines changed

1 file changed

+37
-15
lines changed

run-tests.php

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1851,11 +1851,16 @@ function run_test(string $php, $file, array $env): string
18511851
$skipCache = new SkipCache($enableSkipCache, $cfg['keep']['skip']);
18521852
}
18531853

1854+
$php = escapeshellarg($php);
1855+
1856+
$retriable = true;
1857+
$retried = false;
1858+
retry:
1859+
18541860
$temp_filenames = null;
18551861
$org_file = $file;
18561862
$orig_php = $php;
18571863

1858-
$php = escapeshellarg($php);
18591864
$php_cgi = $env['TEST_PHP_CGI_EXECUTABLE'] ?? null;
18601865
$phpdbg = $env['TEST_PHPDBG_EXECUTABLE'] ?? null;
18611866

@@ -1891,8 +1896,11 @@ function run_test(string $php, $file, array $env): string
18911896

18921897
$tested = $test->getName();
18931898

1894-
if ($num_repeats > 1 && $test->hasSection('FILE_EXTERNAL')) {
1895-
return skip_test($tested, $tested_file, $shortname, 'Test with FILE_EXTERNAL might not be repeatable');
1899+
if ($test->hasSection('FILE_EXTERNAL')) {
1900+
$retriable = false;
1901+
if ($num_repeats > 1) {
1902+
return skip_test($tested, $tested_file, $shortname, 'Test with FILE_EXTERNAL might not be repeatable');
1903+
}
18961904
}
18971905

18981906
if ($test->hasSection('CAPTURE_STDIO')) {
@@ -1918,6 +1926,7 @@ function run_test(string $php, $file, array $env): string
19181926
}
19191927
$php = escapeshellarg($php_cgi) . ' -C ';
19201928
$uses_cgi = true;
1929+
$retriable = false;
19211930
if ($num_repeats > 1) {
19221931
return skip_test($tested, $tested_file, $shortname, 'CGI does not support --repeat');
19231932
}
@@ -1935,20 +1944,18 @@ function run_test(string $php, $file, array $env): string
19351944
} else {
19361945
return skip_test($tested, $tested_file, $shortname, 'phpdbg not available');
19371946
}
1947+
$retriable = false;
19381948
if ($num_repeats > 1) {
19391949
return skip_test($tested, $tested_file, $shortname, 'phpdbg does not support --repeat');
19401950
}
19411951
}
19421952

1943-
if ($num_repeats > 1) {
1944-
if ($test->hasSection('CLEAN')) {
1945-
return skip_test($tested, $tested_file, $shortname, 'Test with CLEAN might not be repeatable');
1946-
}
1947-
if ($test->hasSection('STDIN')) {
1948-
return skip_test($tested, $tested_file, $shortname, 'Test with STDIN might not be repeatable');
1949-
}
1950-
if ($test->hasSection('CAPTURE_STDIO')) {
1951-
return skip_test($tested, $tested_file, $shortname, 'Test with CAPTURE_STDIO might not be repeatable');
1953+
foreach (['CLEAN', 'STDIN', 'CAPTURE_STDIO'] as $section) {
1954+
if ($test->hasSection($section)) {
1955+
$retriable = false;
1956+
if ($num_repeats > 1) {
1957+
return skip_test($tested, $tested_file, $shortname, "Test with $section might not be repeatable");
1958+
}
19521959
}
19531960
}
19541961

@@ -2113,7 +2120,7 @@ function run_test(string $php, $file, array $env): string
21132120
// even though all the files are re-created.
21142121
$ini_settings['opcache.validate_timestamps'] = '0';
21152122
}
2116-
} else if ($num_repeats > 1) {
2123+
} else if ($num_repeats > 1 || $retried) {
21172124
// Make sure warnings still show up on the second run.
21182125
$ini_settings['opcache.record_warnings'] = '1';
21192126
}
@@ -2140,8 +2147,11 @@ function run_test(string $php, $file, array $env): string
21402147
}
21412148
settings2array(preg_split("/[\n\r]+/", $ini), $ini_settings);
21422149

2143-
if ($num_repeats > 1 && isset($ini_settings['opcache.opt_debug_level'])) {
2144-
return skip_test($tested, $tested_file, $shortname, 'opt_debug_level tests are not repeatable');
2150+
if (isset($ini_settings['opcache.opt_debug_level'])) {
2151+
$retriable = false;
2152+
if ($num_repeats > 1) {
2153+
return skip_test($tested, $tested_file, $shortname, 'opt_debug_level tests are not repeatable');
2154+
}
21452155
}
21462156
}
21472157

@@ -2672,6 +2682,10 @@ function run_test(string $php, $file, array $env): string
26722682

26732683
$wanted_re = null;
26742684
}
2685+
if (!$passed && !$retried && $retriable && error_may_be_retried($output)) {
2686+
$retried = true;
2687+
goto retry;
2688+
}
26752689

26762690
if ($passed) {
26772691
if (!$cfg['keep']['php'] && !$leaked) {
@@ -2702,6 +2716,9 @@ function run_test(string $php, $file, array $env): string
27022716
} elseif ($test->hasSection('XLEAK')) {
27032717
$warn = true;
27042718
$info = " (warn: XLEAK section but test passes)";
2719+
} elseif ($retried) {
2720+
$warn = true;
2721+
$info = " (warn: Test passed on retry attempt)";
27052722
} else {
27062723
show_result("PASS", $tested, $tested_file, '', $temp_filenames);
27072724
$junit->markTestAs('PASS', $shortname, $tested);
@@ -2845,6 +2862,11 @@ function run_test(string $php, $file, array $env): string
28452862
return $restype[0] . 'ED';
28462863
}
28472864

2865+
function error_may_be_retried(string $output): bool
2866+
{
2867+
return preg_match('((timed out)|(connection refused))i', $output) === 1;
2868+
}
2869+
28482870
/**
28492871
* Map "Zend OPcache" to "opcache" and convert all ext names to lowercase.
28502872
*/

0 commit comments

Comments
 (0)