MDL-39752 behat: Added Fromrun and torun for running on multiple vms

https://circleci.com
This commit is contained in:
Rajesh Taneja 2015-02-26 13:40:29 +08:00
parent ef95c163e4
commit 1bff616611
4 changed files with 39 additions and 19 deletions

View File

@ -44,7 +44,9 @@ list($options, $unrecognized) = cli_get_params(
array(
'parallel' => 0,
'maxruns' => false,
'help' => false,
'help' => false,
'fromrun' => 1,
'torun' => 0,
),
array(
'j' => 'parallel',
@ -60,6 +62,8 @@ Behat utilities to initialise behat tests
Options:
-j, --parallel Number of parallel behat run to initialise
-m, --maxruns Max parallel processes to be executed at one time.
--fromrun Execute run starting from (Used for parallel runs on different vms)
--torun Execute run till (Used for parallel runs on different vms)
-h, --help Print out this help
@ -80,11 +84,11 @@ $paralleloption = "";
// If parallel run then use utilparallel.
if ($options['parallel']) {
$utilfile = 'util.php';
$paralleloption = "--parallel=" . $options['parallel'];
// If maxruns then add that option.
if ($options['maxruns']) {
$paralleloption .= " --maxruns=" . $options['maxruns'];
$paralleloption = "";
foreach ($options as $option => $value) {
if ($value) {
$paralleloption .= " --$option=\"$value\"";
}
}
}

View File

@ -50,6 +50,8 @@ list($options, $unrecognised) = cli_get_params(
'help' => false,
'tags' => '',
'profile' => '',
'fromrun' => 1,
'torun' => 0,
),
array(
'h' => 'help',
@ -67,6 +69,8 @@ Options:
--stop-on-failure Stop on failure in any parallel run.
--verbose Verbose output
--replace Replace args string with run process number, useful for output.
--fromrun Execute run starting from (Used for parallel runs on different vms)
--torun Execute run till (Used for parallel runs on different vms)
-h, --help Print out this help
@ -81,8 +85,12 @@ if (!empty($options['help'])) {
exit(0);
}
// Ensure we have parallel runs initialised and it's >= 1.
$parallelrun = behat_config_manager::get_parallel_test_runs(1);
$parallelrun = behat_config_manager::get_parallel_test_runs($options['fromrun']);
// Default torun is maximum parallel runs.
if (empty($options['torun'])) {
$options['torun'] = $parallelrun;
}
// Capture signals and ensure we clean symlinks.
if (extension_loaded('pcntl')) {
@ -107,7 +115,7 @@ if (empty($parallelrun)) {
}
// Create site symlink if necessary.
if (!behat_config_manager::create_parallel_site_links()) {
if (!behat_config_manager::create_parallel_site_links($options['fromrun'], $options['torun'])) {
echo "Check permissions. If on windows, make sure you are running this command as admin" . PHP_EOL;
exit(1);
}
@ -154,8 +162,9 @@ if ($tags) {
}
$cmds = array();
echo "Running ${parallelrun} parallel behat sites:" . PHP_EOL;
for ($i = 1; $i <= $parallelrun; $i++) {
echo "Running " . ($options['torun'] - $options['fromrun'] + 1) . " parallel behat sites:" . PHP_EOL;
for ($i = $options['fromrun']; $i <= $options['torun']; $i++) {
$CFG->behatrunprocess = $i;
// Options parameters to be added to each run.

View File

@ -50,6 +50,8 @@ list($options, $unrecognized) = cli_get_params(
'parallel' => 0,
'maxruns' => false,
'updatesteps' => false,
'fromrun' => 1,
'torun' => 0,
),
array(
'h' => 'help',
@ -101,6 +103,11 @@ if (empty($options['parallel'])) {
exit($status);
}
// Default torun is maximum parallel runs.
if (empty($options['torun'])) {
$options['torun'] = $options['parallel'];
}
$status = false;
$cmds = commands_to_execute($options);
@ -164,8 +171,9 @@ require_once(__DIR__ . '/../../../../lib/behat/classes/behat_config_manager.php'
// Show command o/p (only one per time).
if ($options['install']) {
echo "Acceptance tests site installed for sites:".PHP_EOL;
// Display all sites which are installed/drop/diabled.
for ($i = 1; $i <= $options['parallel']; $i++) {
for ($i = $options['fromrun']; $i <= $options['torun']; $i++) {
echo $CFG->behat_wwwroot . "/" . BEHAT_PARALLEL_SITE_NAME . $i . PHP_EOL;
}
} else if ($options['drop']) {
@ -193,7 +201,7 @@ exit(0);
* @return array commands to be executed.
*/
function commands_to_execute($options) {
$removeoptions = array('maxruns');
$removeoptions = array('maxruns', 'fromrun', 'torun');
$cmds = array();
$extraoptions = $options;
$extra = "";
@ -217,7 +225,7 @@ function commands_to_execute($options) {
$cmds = "php util_single_run.php " . $extra;
} else {
// Create commands which has to be executed for parallel site.
for ($i = 1; $i <= $options['parallel']; $i++) {
for ($i = $options['fromrun']; $i <= $options['torun']; $i++) {
$prefix = BEHAT_PARALLEL_SITE_NAME . $i;
$cmds[$prefix] = "php util_single_run.php " . $extra . " --run=" . $i . " 2>&1";
}

View File

@ -287,17 +287,16 @@ class behat_config_manager {
/**
* Create parallel site links.
*
* @param int $fromrun first run
* @param int $torun last run.
* @return bool true for sucess, else false.
*/
public final static function create_parallel_site_links() {
public final static function create_parallel_site_links($fromrun, $torun) {
global $CFG;
// Get parallel test runs from first run.
$parallelrun = self::get_parallel_test_runs(1);
// Create site symlink if necessary.
clearstatcache();
for ($i = 1; $i <= $parallelrun; $i++) {
for ($i = $fromrun; $i <= $torun; $i++) {
$link = $CFG->dirroot.'/'.BEHAT_PARALLEL_SITE_NAME.$i;
clearstatcache();
if (file_exists($link)) {