Skip to content

Commit

Permalink
- Patch #254166 by Damien Tournoud: improved error handling of concur…
Browse files Browse the repository at this point in the history
…rency mode.
  • Loading branch information
dries committed Jul 24, 2008
1 parent 43a5704 commit afae995
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions scripts/run-tests.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
// $Id: run-tests.sh,v 1.5 2008-07-07 06:22:18 dries Exp $
// $Id: run-tests.sh,v 1.6 2008-07-24 06:46:28 dries Exp $
/**
* @file
* This script runs Drupal tests from command line.
Expand Down Expand Up @@ -115,7 +115,8 @@ All arguments are long options.
--concurrency [num]

Run tests in parallel, up to [num] tests at a time.
This is not supported under Windows.
This requires the Process Control Extension (PCNTL) to be compiled in PHP,
not supported under Windows.

--all Run all available tests.

Expand Down Expand Up @@ -198,6 +199,17 @@ function simpletest_script_parse_args() {
$args['test_names'] += explode(',', $arg);
}
}

// Validate the concurrency argument
if (!is_numeric($args['concurrency']) || $args['concurrency'] <= 0) {
simpletest_script_print_error("--concurrency must be a strictly positive integer.");
exit;
}
else if ($args['concurrency'] > 1 && !function_exists('pcntl_fork')) {
simpletest_script_print_error("Parallel test execution requires the Process Control extension to be compiled in PHP. Please see http://php.net/manual/en/intro.pcntl.php for more information.");
exit;
}

return array($args, $count);
}

Expand Down Expand Up @@ -242,7 +254,7 @@ function simpletest_script_execute_batch() {
simpletest_script_print_error("--execute-batch should not be called interactively.");
exit;
}
if ($args['concurrency'] == 1 || !function_exists('pcntl_fork')) {
if ($args['concurrency'] == 1) {
// Fallback to mono-threaded execution.
if (count($args['test_names']) > 1) {
foreach ($args['test_names'] as $test_class) {
Expand All @@ -264,7 +276,7 @@ function simpletest_script_execute_batch() {
$children = array();
while (!empty($args['test_names']) || !empty($children)) {
// Fork children safely since Drupal is not bootstrapped yet.
while (count($children) < $concurrency) {
while (count($children) < $args['concurrency']) {
if (empty($args['test_names'])) break;

$child = array();
Expand All @@ -273,7 +285,7 @@ function simpletest_script_execute_batch() {
if (!$child['pid']) {
// This is the child process, bootstrap and execute the test.
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
simpletest_script_run_one_test($test_id, $test_class);
simpletest_script_run_one_test($args['test-id'], $test_class);
exit;
}
else {
Expand Down

0 comments on commit afae995

Please sign in to comment.