From c143cfe95478a2733165590246ce358bea6d3df4 Mon Sep 17 00:00:00 2001 From: Oleksandr Shmyheliuk Date: Mon, 14 Sep 2020 09:57:22 -0500 Subject: [PATCH] MCLOUD-6847: Improve functional tests execution speed (#777) --- .travis.yml | 1 + codeception.dist.yml | 1 + .../Functional/Acceptance/AbstractCest.php | 9 ++++++++ tests/travis/prepare_functional_parallel.sh | 22 +++++-------------- travis.php.ini | 1 + 5 files changed, 18 insertions(+), 16 deletions(-) create mode 100644 travis.php.ini diff --git a/.travis.yml b/.travis.yml index 74b74741d4..8aa596c185 100644 --- a/.travis.yml +++ b/.travis.yml @@ -49,6 +49,7 @@ before_install: install: + - phpenv config-add travis.php.ini - composer config http-basic.repo.magento.com ${REPO_USERNAME_CE} ${REPO_PASSWORD_CE} - composer config github-oauth.github.com ${GITHUB_TOKEN} - if [ -n "${MCC_VERSION}" ]; then composer config repositories.mcc git git@github.com:magento/magento-cloud-components.git && composer require "magento/magento-cloud-components:${MCC_VERSION}" --no-update; fi; diff --git a/codeception.dist.yml b/codeception.dist.yml index 2badeb2381..2549c69fb9 100644 --- a/codeception.dist.yml +++ b/codeception.dist.yml @@ -24,6 +24,7 @@ modules: composer_magento_username: "%REPO_USERNAME%" composer_magento_password: "%REPO_PASSWORD%" composer_github_token: "%GITHUB_TOKEN%" + use_cached_workdir: true printOutput: false Magento\CloudDocker\Test\Functional\Codeception\Docker: system_magento_dir: "%Magento.docker.settings.system.magento_dir%" diff --git a/src/Test/Functional/Acceptance/AbstractCest.php b/src/Test/Functional/Acceptance/AbstractCest.php index 2ff196e6be..a78cf452c8 100644 --- a/src/Test/Functional/Acceptance/AbstractCest.php +++ b/src/Test/Functional/Acceptance/AbstractCest.php @@ -61,6 +61,14 @@ protected function convertEnvFromArrayToJson(array $data): string protected function prepareWorkplace(\CliTester $I, string $templateVersion): void { $I->cleanupWorkDir(); + + if ($I->isCacheWorkDirExists($templateVersion)) { + $I->restoreWorkDirFromCache($templateVersion); + $this->removeESIfExists($I, $templateVersion); + + return; + } + $I->cloneTemplateToWorkDir($templateVersion); $I->createAuthJson(); $I->createArtifactsDir(); @@ -90,6 +98,7 @@ protected function prepareWorkplace(\CliTester $I, string $templateVersion): voi if ($this->runComposerUpdate) { $I->composerUpdate(); + $I->cacheWorkDir($templateVersion); } $this->removeESIfExists($I, $templateVersion); diff --git a/tests/travis/prepare_functional_parallel.sh b/tests/travis/prepare_functional_parallel.sh index a99f80e5b2..ba44c3b9e5 100755 --- a/tests/travis/prepare_functional_parallel.sh +++ b/tests/travis/prepare_functional_parallel.sh @@ -8,15 +8,9 @@ trap '>&2 echo Error: Command \`$BASH_COMMAND\` on line $LINENO failed with exit php_version="${TRAVIS_PHP_VERSION//./}" -readarray -t test_set_list <<< "$(grep -Rl php${php_version} --exclude='*AcceptanceCest.php' --exclude='*AcceptanceCeCest.php' --exclude='*AcceptanceCe71Cest.php' --exclude='*AcceptanceCe72Cest.php' --exclude='*AcceptanceCe73Cest.php' --exclude='*AbstractCest.php' src/Test/Functional/Acceptance | sort)" +test_set_list=($(grep -Rl php${php_version} --exclude='*AcceptanceCest.php' --exclude='*AcceptanceCeCest.php' --exclude='*AcceptanceCe71Cest.php' --exclude='*AcceptanceCe72Cest.php' --exclude='*AcceptanceCe73Cest.php' --exclude='*AbstractCest.php' src/Test/Functional/Acceptance | sort)) group_count=6 -if [ $(( ${#test_set_list[@]} % group_count )) -eq 0 ]; then - element_in_group=$(printf "%.0f" "$(echo "scale=2;(${#test_set_list[@]})/${group_count}" | bc)") -else - element_in_group=$(printf "%.0f" "$(echo "scale=2;(${#test_set_list[@]} + ${group_count} - 1)/${group_count}" | bc)") -fi - cp codeception.dist.yml codeception.yml echo "groups:" >> codeception.yml echo " parallel_${php_version}_*: tests/functional/_data/parallel_${php_version}_*" >> codeception.yml @@ -30,15 +24,11 @@ else start_group_id=1 fi -for((i=0, group_id=start_group_id; i < ${#test_set_list[@]}; i+=element_in_group, group_id++)) +for((i=0, group_id=start_group_id; i < ${#test_set_list[@]}; i+=1, group_id++)) do - test_file_group=( "${test_set_list[@]:i:element_in_group}" ) - echo "Batch #${group_id} = ${#test_file_group[@]}" - + if [ $group_id -gt $group_count ]; then + group_id=$start_group_id + fi group_file="tests/functional/_data/parallel_${php_version}_$group_id.yml" - - for test_file in "${test_file_group[@]}" - do - echo "$test_file" >> "$group_file" - done + echo "${test_set_list[i]}" >> "$group_file" done diff --git a/travis.php.ini b/travis.php.ini new file mode 100644 index 0000000000..0b1342670d --- /dev/null +++ b/travis.php.ini @@ -0,0 +1 @@ +memory_limit = 4G