-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Run-Tests Cleanup / Modernization #5707
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -31,7 +31,7 @@ | |||||
* Minimum required PHP version: 7.0.0 | ||||||
*/ | ||||||
|
||||||
function show_usage() | ||||||
function show_usage(): void | ||||||
{ | ||||||
echo <<<HELP | ||||||
Synopsis: | ||||||
|
@@ -146,10 +146,9 @@ function main() | |||||
|
||||||
define('IS_WINDOWS', substr(PHP_OS, 0, 3) == "WIN"); | ||||||
|
||||||
$workerID = 0; | ||||||
if (getenv("TEST_PHP_WORKER")) { | ||||||
$workerID = intval(getenv("TEST_PHP_WORKER")); | ||||||
run_worker(); | ||||||
$workerID = get_worker_id(); | ||||||
if($workerID) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
run_worker($workerID); | ||||||
return; | ||||||
} | ||||||
|
||||||
|
@@ -443,18 +442,11 @@ function main() | |||||
|
||||||
switch ($switch) { | ||||||
case 'j': | ||||||
$workers = substr($argv[$i], 2); | ||||||
if (!preg_match('/^\d+$/', $workers) || $workers == 0) { | ||||||
error("'$workers' is not a valid number of workers, try e.g. -j16 for 16 workers"); | ||||||
} | ||||||
$workers = intval($workers, 10); | ||||||
// Don't use parallel testing infrastructure if there is only one worker. | ||||||
if ($workers === 1) { | ||||||
$workers = null; | ||||||
} | ||||||
$workers = get_number_of_workers($argv[$i]); | ||||||
break; | ||||||
case 'r': | ||||||
case 'l': | ||||||
// @Dragoonis | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Leftover? |
||||||
$test_list = file($argv[++$i]); | ||||||
if ($test_list) { | ||||||
foreach ($test_list as $test) { | ||||||
|
@@ -1080,7 +1072,7 @@ function test_sort($a, $b) | |||||
// Send Email to QA Team | ||||||
// | ||||||
|
||||||
function mail_qa_team($data, $status = false) | ||||||
function mail_qa_team($data, $status = false): bool | ||||||
{ | ||||||
$url_bits = parse_url(QA_SUBMISSION_PAGE); | ||||||
|
||||||
|
@@ -1119,7 +1111,7 @@ function mail_qa_team($data, $status = false) | |||||
fwrite($fs, "\r\n\r\n"); | ||||||
fclose($fs); | ||||||
|
||||||
return 1; | ||||||
return true; | ||||||
} | ||||||
|
||||||
// | ||||||
|
@@ -1381,7 +1373,7 @@ function run_all_tests_parallel($test_files, $env, $redir_tested) | |||||
} | ||||||
|
||||||
// Don't start more workers than test files. | ||||||
$workers = max(1, min($workers, count($test_files))); | ||||||
$workers = get_max_workers_from_test_files($workers, $test_files); | ||||||
|
||||||
echo "Spawning $workers workers... "; | ||||||
|
||||||
|
@@ -1643,15 +1635,15 @@ function run_all_tests_parallel($test_files, $env, $redir_tested) | |||||
} | ||||||
} | ||||||
|
||||||
function send_message($stream, array $message) | ||||||
function send_message($stream, array $message): void | ||||||
{ | ||||||
$blocking = stream_get_meta_data($stream)["blocked"]; | ||||||
stream_set_blocking($stream, true); | ||||||
fwrite($stream, base64_encode(serialize($message)) . "\n"); | ||||||
stream_set_blocking($stream, $blocking); | ||||||
} | ||||||
|
||||||
function kill_children(array $children) | ||||||
function kill_children(array $children): void | ||||||
{ | ||||||
foreach ($children as $child) { | ||||||
if ($child) { | ||||||
|
@@ -1660,9 +1652,9 @@ function kill_children(array $children) | |||||
} | ||||||
} | ||||||
|
||||||
function run_worker() | ||||||
function run_worker($workerID): void | ||||||
{ | ||||||
global $workerID, $workerSock; | ||||||
global $workerSock; | ||||||
|
||||||
$sockUri = getenv("TEST_PHP_URI"); | ||||||
|
||||||
|
@@ -1819,15 +1811,7 @@ function run_test($php, $file, $env) | |||||
} | ||||||
|
||||||
// check for unknown sections | ||||||
if (!in_array($section, array( | ||||||
'EXPECT', 'EXPECTF', 'EXPECTREGEX', 'EXPECTREGEX_EXTERNAL', 'EXPECT_EXTERNAL', 'EXPECTF_EXTERNAL', 'EXPECTHEADERS', | ||||||
'POST', 'POST_RAW', 'GZIP_POST', 'DEFLATE_POST', 'PUT', 'GET', 'COOKIE', 'ARGS', | ||||||
'FILE', 'FILEEOF', 'FILE_EXTERNAL', 'REDIRECTTEST', | ||||||
'CAPTURE_STDIO', 'STDIN', 'CGI', 'PHPDBG', | ||||||
'INI', 'ENV', 'EXTENSIONS', | ||||||
'SKIPIF', 'XFAIL', 'XLEAK', 'CLEAN', | ||||||
'CREDITS', 'DESCRIPTION', 'CONFLICTS', 'WHITESPACE_SENSITIVE', | ||||||
))) { | ||||||
if (is_section_unknown($section)) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: I would prefer if this was |
||||||
$bork_info = 'Unknown section "' . $section . '"'; | ||||||
} | ||||||
|
||||||
|
@@ -3613,4 +3597,49 @@ function check_proc_open_function_exists() | |||||
} | ||||||
} | ||||||
|
||||||
|
||||||
|
||||||
|
||||||
function get_number_of_workers($workers): int | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
maybe |
||||||
{ | ||||||
$cleanWorkers = substr($workers, 2); | ||||||
if (!preg_match('/^\d+$/', $cleanWorkers) || $cleanWorkers == 0) { | ||||||
error("'$workers' is not a valid number of workers, try e.g. -j16 for 16 workers"); | ||||||
} | ||||||
$cleanWorkers = intval($cleanWorkers, 10); | ||||||
// Don't use parallel testing infrastructure if there is only one worker. | ||||||
if ($cleanWorkers === 1) { | ||||||
$cleanWorkers = null; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be either 0, or the return type should be |
||||||
} | ||||||
|
||||||
return $cleanWorkers; | ||||||
} | ||||||
|
||||||
function get_max_workers_from_test_files($workers, $test_files): int | ||||||
{ | ||||||
return max(1, min($workers, count($test_files))); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code seems easier to understand if left inlined. |
||||||
} | ||||||
|
||||||
function get_worker_id(): int | ||||||
{ | ||||||
if (!getenv("TEST_PHP_WORKER")) { | ||||||
return 0; | ||||||
} | ||||||
|
||||||
return intval(getenv("TEST_PHP_WORKER")); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function can be simplified to |
||||||
} | ||||||
|
||||||
function is_section_unknown(string $section): bool | ||||||
{ | ||||||
return !in_array($section, array( | ||||||
'EXPECT', 'EXPECTF', 'EXPECTREGEX', 'EXPECTREGEX_EXTERNAL', 'EXPECT_EXTERNAL', 'EXPECTF_EXTERNAL', 'EXPECTHEADERS', | ||||||
'POST', 'POST_RAW', 'GZIP_POST', 'DEFLATE_POST', 'PUT', 'GET', 'COOKIE', 'ARGS', | ||||||
'FILE', 'FILEEOF', 'FILE_EXTERNAL', 'REDIRECTTEST', | ||||||
'CAPTURE_STDIO', 'STDIN', 'CGI', 'PHPDBG', | ||||||
'INI', 'ENV', 'EXTENSIONS', | ||||||
'SKIPIF', 'XFAIL', 'XLEAK', 'CLEAN', | ||||||
'CREDITS', 'DESCRIPTION', 'CONFLICTS', 'WHITESPACE_SENSITIVE', | ||||||
)); | ||||||
} | ||||||
|
||||||
main(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you are using void, update this comment to say 7.1.0.