From 26bf6d4ead38911bc3f071180a5130fd9f4bcdb7 Mon Sep 17 00:00:00 2001 From: Rajesh Taneja Date: Fri, 10 Feb 2017 14:55:21 +0800 Subject: [PATCH] MDL-57940 behat: Allow behat parallel run to start with delay Behat parallel run if executed together then selenium might fail to launch browser and timeout. It would be nice to have a custom delay between the start of each process --- admin/tool/behat/cli/run.php | 7 ++++++- lib/behat/lib.php | 8 +++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/admin/tool/behat/cli/run.php b/admin/tool/behat/cli/run.php index e402efa96dc..b52337b6b7e 100644 --- a/admin/tool/behat/cli/run.php +++ b/admin/tool/behat/cli/run.php @@ -262,8 +262,13 @@ if (empty($parallelrun)) { behat_config_manager::set_behat_run_config_value('lasttorun', $options['torun']); behat_config_manager::set_behat_run_config_value('lastfromrun', $options['fromrun']); + // Keep no delay by default, between each parallel, let user decide. + if (!defined('BEHAT_PARALLEL_START_DELAY')) { + define('BEHAT_PARALLEL_START_DELAY', 0); + } + // Execute all commands, relative to moodle root directory. - $processes = cli_execute_parallel($cmds, __DIR__ . "/../../../../"); + $processes = cli_execute_parallel($cmds, __DIR__ . "/../../../../", BEHAT_PARALLEL_START_DELAY); $stoponfail = empty($options['stop-on-failure']) ? false : true; // Print header. diff --git a/lib/behat/lib.php b/lib/behat/lib.php index 1ca3f098be2..6a1bef7151c 100644 --- a/lib/behat/lib.php +++ b/lib/behat/lib.php @@ -493,9 +493,10 @@ function behat_get_run_process() { * * @param array $cmds list of commands to be executed. * @param string $cwd absolute path of working directory. + * @param int $delay time in seconds to add delay between each parallel process. * @return array list of processes. */ -function cli_execute_parallel($cmds, $cwd = null) { +function cli_execute_parallel($cmds, $cwd = null, $delay = 0) { require_once(__DIR__ . "/../../vendor/autoload.php"); $processes = array(); @@ -519,6 +520,11 @@ function cli_execute_parallel($cmds, $cwd = null) { } exit(1); } + + // Sleep for specified delay. + if ($delay) { + sleep($delay); + } } return $processes; }