Skip to content

Commit 7ff7375

Browse files
authored
MCLOUD-6814: [Backport] Improve functional tests execution speed (#286)
1 parent b79150d commit 7ff7375

File tree

6 files changed

+83
-5
lines changed

6 files changed

+83
-5
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ jobs:
8989
env:
9090
- TEST_SUITE=functional
9191

92-
install: if [[ $TEST_SUITE != "build-images" ]]; then composer update; fi;
92+
install: if [[ $TEST_SUITE != "build-images" ]]; then phpenv config-add travis.php.ini && composer update; fi;
9393

9494
before_script:
9595
- if [ $TRAVIS_SECURE_ENV_VARS == "true" ] && [ $TEST_SUITE == "build-images" ]; then echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin; fi;

codeception.dist.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ modules:
2626
composer_magento_password: "%REPO_PASSWORD%"
2727
composer_github_token: "%GITHUB_TOKEN%"
2828
use_generated_images: false
29+
use_cached_workdir: true
2930
version_generated_images: "%TRAVIS_BUILD_NUMBER%"
3031
printOutput: false
3132
Magento\CloudDocker\Test\Functional\Codeception\Docker:

src/Test/Functional/Acceptance/AbstractCest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ abstract class AbstractCest
2323
public function _before(\CliTester $I): void
2424
{
2525
$I->cleanupWorkDir();
26+
27+
if ($I->isCacheWorkDirExists(static::TEMPLATE_VERSION)) {
28+
$I->restoreWorkDirFromCache(static::TEMPLATE_VERSION);
29+
30+
return;
31+
}
32+
2633
$I->cloneTemplateToWorkDir(static::TEMPLATE_VERSION);
2734
$I->createAuthJson();
2835
$I->createArtifactsDir();
@@ -33,7 +40,8 @@ public function _before(\CliTester $I): void
3340
$I->addEceToolsGitRepoToComposer();
3441
$I->addDependencyToComposer('magento/ece-tools', 'dev-develop as 2002.1.99');
3542

36-
$I->composerUpdate();
43+
$I->assertTrue($I->composerUpdate());
44+
$I->cacheWorkDir(static::TEMPLATE_VERSION);
3745
}
3846

3947
/**

tests/functional/Codeception/BaseModule.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ class BaseModule extends Module implements BuilderAwareInterface, ContainerAware
3737
*/
3838
const WORK_DIR = '_workdir';
3939

40+
/**
41+
* Cached work directory name
42+
*/
43+
const WORK_DIR_CACHE = '_workdir_cache';
44+
4045
/**
4146
* The artifact directory name
4247
*/
@@ -96,6 +101,17 @@ public function getWorkDirPath(): string
96101
return codecept_root_dir(self::WORK_DIR);
97102
}
98103

104+
/**
105+
* Returns the path to cached work directory
106+
*
107+
* @param string $version
108+
* @return string
109+
*/
110+
public function getCachedWorkDirPath(string $version): string
111+
{
112+
return codecept_root_dir(self::WORK_DIR_CACHE) . '/' . $version;
113+
}
114+
99115
/**
100116
* Returns the path to directory that contains artifacts
101117
*

tests/functional/Codeception/TestInfrastructure.php

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
*/
1515
class TestInfrastructure extends BaseModule
1616
{
17+
private const USE_CACHED_WORKDIR_OPTION = 'use_cached_workdir';
18+
1719
/**
1820
* Creates the work directory
1921
*
@@ -69,6 +71,57 @@ public function cleanupWorkDir(): bool
6971
return $this->createWorkDir();
7072
}
7173

74+
/**
75+
* @param string $version
76+
* @return bool
77+
*/
78+
public function isCacheWorkDirExists(string $version): bool
79+
{
80+
return $this->_getConfig(self::USE_CACHED_WORKDIR_OPTION) && is_dir($this->getCachedWorkDirPath($version));
81+
}
82+
83+
/**
84+
* @param string $version
85+
* @return void
86+
*/
87+
public function cacheWorkDir(string $version): void
88+
{
89+
if (!$this->_getConfig(self::USE_CACHED_WORKDIR_OPTION)) {
90+
return;
91+
}
92+
93+
$this->copyDir($this->getWorkDirPath(), $this->getCachedWorkDirPath($version));
94+
}
95+
96+
/**
97+
* @param string $version
98+
*/
99+
public function restoreWorkDirFromCache(string $version): void
100+
{
101+
$this->copyDir($this->getCachedWorkDirPath($version), $this->getWorkDirPath());
102+
}
103+
104+
/**
105+
* Copy directory recursively.
106+
*
107+
* @param string $source The path of source folder
108+
* @param string $destination The path of destination folder
109+
* @return void
110+
*/
111+
public function copyDir($source, $destination): void
112+
{
113+
if (!is_dir(dirname($destination))) {
114+
mkdir(dirname($destination));
115+
}
116+
117+
$this->taskRsync()
118+
->arg('-l')
119+
->recursive()
120+
->fromPath($source . '/')
121+
->toPath($destination . '/')
122+
->excludeVcs()
123+
->run();
124+
}
72125

73126
/**
74127
* Clones cloud template to the work directory
@@ -82,7 +135,7 @@ public function cloneTemplateToWorkDir(string $branch = 'master'): bool
82135
->printOutput($this->_getConfig('printOutput'))
83136
->interactive(false)
84137
->stopOnFail()
85-
->cloneRepo($this->_getConfig('template_repo'), '.', $branch)
138+
->cloneShallow($this->_getConfig('template_repo'), '.', $branch)
86139
->dir($this->getWorkDirPath())
87140
->run()
88141
->wasSuccessful();
@@ -407,9 +460,8 @@ public function runEceDockerCommand(string $command): bool
407460
*/
408461
public function replaceImagesWithGenerated(): bool
409462
{
410-
411463
if (true === $this->_getConfig('use_generated_images')) {
412-
$this->debug('Tests use new generatedx Docker images');
464+
$this->debug('Tests use new generated Docker images');
413465
$path = $this->getWorkDirPath() . DIRECTORY_SEPARATOR . 'docker-compose.yml';
414466

415467
return (bool)file_put_contents(

travis.php.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
memory_limit = 4G

0 commit comments

Comments
 (0)