From 4fc9a7146ba203f6c0a83da490ec65df2f388f22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Wed, 3 May 2017 17:24:30 +0200 Subject: [PATCH] Add option to acceptance test runners to set a custom timeout multiplier MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Daniel Calviño Sánchez --- tests/acceptance/run-local.sh | 31 +++++++++++++++++++++++++++++++ tests/acceptance/run.sh | 18 +++++++++++++++++- 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/tests/acceptance/run-local.sh b/tests/acceptance/run-local.sh index ee7a4e6455..93c11e810f 100755 --- a/tests/acceptance/run-local.sh +++ b/tests/acceptance/run-local.sh @@ -39,6 +39,21 @@ set -o errexit # Behat through Composer or running Behat) expect that. cd "$(dirname $0)" +# "--timeout-multiplier N" option can be provided before any other parameter to +# set the timeout multiplier to be used in ActorContext. +TIMEOUT_MULTIPLIER="" +if [ "$1" = "--timeout-multiplier" ]; then + if [[ ! "$2" =~ ^[0-9]+$ ]]; then + echo "--timeout-multiplier must be followed by a positive integer" + + exit 1 + fi + + TIMEOUT_MULTIPLIER=$2 + + shift 2 +fi + # Safety parameter to prevent executing this script by mistake and messing with # the Git repository. if [ "$1" != "allow-git-repository-modifications" ]; then @@ -49,6 +64,22 @@ fi SCENARIO_TO_RUN=$2 +if [ "$TIMEOUT_MULTIPLIER" != "" ]; then + # Although Behat documentation states that using the BEHAT_PARAMS + # environment variable "You can set any value for any option that is + # available in a behat.yml file" this is currently not true for the + # constructor parameters of contexts (see + # https://github.com/Behat/Behat/issues/983). Thus, the default "behat.yml" + # configuration file has to be adjusted to provide the appropriate + # parameters for ActorContext. + ORIGINAL="\ + - ActorContext" + REPLACEMENT="\ + - ActorContext:\n\ + actorTimeoutMultiplier: $TIMEOUT_MULTIPLIER" + sed --in-place "s/$ORIGINAL/$REPLACEMENT/" config/behat.yml +fi + composer install cd ../../ diff --git a/tests/acceptance/run.sh b/tests/acceptance/run.sh index 42a718d46e..1b68f8655a 100755 --- a/tests/acceptance/run.sh +++ b/tests/acceptance/run.sh @@ -197,6 +197,22 @@ trap cleanUp EXIT # the Git working directory to the container) expect that. cd "$(dirname $0)" +# "--timeout-multiplier N" option can be provided before the specific scenario +# to run, if any, to set the timeout multiplier to be used in the acceptance +# tests. +TIMEOUT_MULTIPLIER_OPTION="" +if [ "$1" = "--timeout-multiplier" ]; then + if [[ ! "$2" =~ ^[0-9]+$ ]]; then + echo "--timeout-multiplier must be followed by a positive integer" + + exit 1 + fi + + TIMEOUT_MULTIPLIER_OPTION="--timeout-multiplier $2" + + shift 2 +fi + # If no parameter is provided to this script all the acceptance tests are run. SCENARIO_TO_RUN=$1 @@ -206,4 +222,4 @@ prepareSelenium prepareDocker echo "Running tests" -docker exec $NEXTCLOUD_LOCAL_CONTAINER bash -c "cd nextcloud && tests/acceptance/run-local.sh allow-git-repository-modifications $SCENARIO_TO_RUN" +docker exec $NEXTCLOUD_LOCAL_CONTAINER bash -c "cd nextcloud && tests/acceptance/run-local.sh $TIMEOUT_MULTIPLIER_OPTION allow-git-repository-modifications $SCENARIO_TO_RUN"