From 73cc1d04c9ebdd21857e1aa9acea84dd04cab4b0 Mon Sep 17 00:00:00 2001 From: Rajesh Taneja Date: Tue, 7 Apr 2015 16:39:04 +0800 Subject: [PATCH] MDL-49772 behat: Added support to updatestep file by parallel run --- admin/tool/behat/cli/util.php | 22 +++++++++++++++++++++- admin/tool/behat/cli/util_single_run.php | 7 ++++--- lib/behat/classes/behat_config_manager.php | 9 +++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/admin/tool/behat/cli/util.php b/admin/tool/behat/cli/util.php index 23a47fd6b8f..a952efce07d 100644 --- a/admin/tool/behat/cli/util.php +++ b/admin/tool/behat/cli/util.php @@ -97,7 +97,7 @@ if (!empty($options['help'])) { $cwd = getcwd(); // For drop option check if parallel site. -if ((empty($options['parallel'])) && $options['drop']) { +if ((empty($options['parallel'])) && ($options['drop']) || $options['updatesteps']) { // Get parallel run info from first run. $options['parallel'] = behat_config_manager::get_parallel_test_runs($options['fromrun']); } @@ -172,6 +172,26 @@ if ($options['diag'] || $options['enable'] || $options['disable']) { } } +} else if ($options['updatesteps']) { + // Rewrite config file to ensure we have all the features covered. + if (empty($options['parallel'])) { + behat_config_manager::update_config_file(); + } else { + // Update config file, ensuring we have up-to-date behat.yml. + for ($i = $options['fromrun']; $i <= $options['torun']; $i++) { + $CFG->behatrunprocess = $i; + behat_config_manager::update_config_file(); + } + unset($CFG->behatrunprocess); + } + + // Do it sequentially as it's fast and need to be displayed nicely. + foreach (array_chunk($cmds, 1, true) as $cmd) { + $processes = cli_execute_parallel($cmd, __DIR__); + print_sequential_output($processes); + } + exit(0); + } else { // We should never reach here. echo $help; diff --git a/admin/tool/behat/cli/util_single_run.php b/admin/tool/behat/cli/util_single_run.php index b089539958e..d523569375f 100644 --- a/admin/tool/behat/cli/util_single_run.php +++ b/admin/tool/behat/cli/util_single_run.php @@ -199,9 +199,6 @@ if ($options['install']) { exit(1); } - // Rewrite config file to ensure we have all the features covered. - behat_config_manager::update_config_file(); - // Run behat command to get steps in feature files. $featurestepscmd = behat_command::get_behat_command(true); $featurestepscmd .= ' --config ' . behat_config_manager::get_behat_cli_config_filepath(); @@ -263,6 +260,10 @@ function print_update_step_output($process, $featurestepfile) { $steps[$step[0]] = $step[1]; } } + + if ($existing = @json_decode(file_get_contents($featurestepfile), true)) { + $steps = array_merge($existing, $steps); + } arsort($steps); if (!@file_put_contents($featurestepfile, json_encode($steps, JSON_PRETTY_PRINT))) { diff --git a/lib/behat/classes/behat_config_manager.php b/lib/behat/classes/behat_config_manager.php index eaa94303b62..f9d6c5ac0a3 100644 --- a/lib/behat/classes/behat_config_manager.php +++ b/lib/behat/classes/behat_config_manager.php @@ -273,6 +273,13 @@ class behat_config_manager { * @return int */ public final static function get_parallel_test_runs($runprocess = 0) { + global $CFG; + + // Optimise reading this information from file. + if (!empty($CFG->behatparallelprocesses)) { + return $CFG->behatparallelprocesses; + } + $parallelrun = 0; // Get parallel run info from first file and last file. $parallelrunconfigfile = self::get_parallel_test_file_path($runprocess); @@ -282,6 +289,8 @@ class behat_config_manager { } } + $CFG->behatparallelprocesses = $parallelrun; + return $parallelrun; }