Skip to content

Commit

Permalink
Merge pull request #368 from magento-commerce/ACQE-5871
Browse files Browse the repository at this point in the history
ACQE-5871: Add ability to increase default MagentoCLI timeout
  • Loading branch information
jilu1 authored Dec 11, 2023
2 parents fdf77db + cfec610 commit f285fe3
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 7 deletions.
59 changes: 59 additions & 0 deletions dev/tests/verification/Resources/MagentoCliTest.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
namespace Magento\AcceptanceTest\_default\Backend;

use Magento\FunctionalTestingFramework\AcceptanceTester;
use \Codeception\Util\Locator;
use Yandex\Allure\Adapter\Annotation\Features;
use Yandex\Allure\Adapter\Annotation\Stories;
use Yandex\Allure\Adapter\Annotation\Title;
use Yandex\Allure\Adapter\Annotation\Description;
use Yandex\Allure\Adapter\Annotation\Parameter;
use Yandex\Allure\Adapter\Annotation\Severity;
use Yandex\Allure\Adapter\Model\SeverityLevel;
use Yandex\Allure\Adapter\Annotation\TestCaseId;

/**
* @Description("<h3>Test files</h3>verification/TestModule/Test/BasicFunctionalTest/MagentoCliTest.xml<br>")
*/
class MagentoCliTestCest
{
/**
* @var bool
*/
private $isSuccess = false;

/**
* @param AcceptanceTester $I
* @throws \Exception
*/
public function _after(AcceptanceTester $I)
{
if ($this->isSuccess) {
unlink(__FILE__);
}
}

/**
* @Features({"TestModule"})
* @param AcceptanceTester $I
* @return void
* @throws \Exception
*/
public function MagentoCliTest(AcceptanceTester $I)
{
$magentoCli1 = $I->magentoCLI("maintenance:enable", 45, "\"stuffHere\""); // stepKey: magentoCli1
$I->comment($magentoCli1);
$magentoCli2 = $I->magentoCLI("maintenance:enable", 120, "\"stuffHere\""); // stepKey: magentoCli2
$I->comment($magentoCli2);
$magentoCli3 = $I->magentoCLISecret("config:set somePath " . $I->getSecret("someKey"), 45); // stepKey: magentoCli3
$I->comment($magentoCli3); // stepKey: magentoCli3
$magentoCli4 = $I->magentoCLISecret("config:set somePath " . $I->getSecret("someKey"), 120); // stepKey: magentoCli4
$I->comment($magentoCli4); // stepKey: magentoCli4
}

public function _passed(AcceptanceTester $I)
{
// Test passed successfully.
$this->isSuccess = true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
<test name="MagentoCliTest">
<magentoCLI command="maintenance:enable" arguments="&quot;stuffHere&quot;" stepKey="magentoCli1"/>
<magentoCLI command="maintenance:enable" arguments="&quot;stuffHere&quot;" timeout="120" stepKey="magentoCli2"/>
<magentoCLI command="config:set somePath {{_CREDS.someKey}}" stepKey="magentoCli3"/>
<magentoCLI command="config:set somePath {{_CREDS.someKey}}" timeout="120" stepKey="magentoCli4"/>
</test>
</tests>
13 changes: 13 additions & 0 deletions dev/tests/verification/Tests/BasicCestGenerationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,17 @@ public function testWithXmlComments()
{
$this->generateAndCompareTest('XmlCommentedTest');
}

/**
* Tests magentoCLI and magentoCLISecret commands with env 'MAGENTO_CLI_WAIT_TIMEOUT' set
*
* @throws \Exception
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException
*/
public function testMagentoCli()
{
putenv("MAGENTO_CLI_WAIT_TIMEOUT=45");
$this->generateAndCompareTest('MagentoCliTest');
putenv("MAGENTO_CLI_WAIT_TIMEOUT");
}
}
3 changes: 3 additions & 0 deletions etc/config/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ MODULE_ALLOWLIST=Magento_Framework,ConfigurableProductWishlist,ConfigurableProdu
#*** Default timeout for wait actions
WAIT_TIMEOUT=60

#*** Default timeout for 'magentoCLI' and 'magentoCLISecret' command
MAGENTO_CLI_WAIT_TIMEOUT=60

#*** Uncomment and set to enable all tests, regardless of passing status, to have all their Allure artifacts.
#VERBOSE_ARTIFACTS=true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,9 +530,9 @@ public function scrollToTopOfPage()
/**
* Takes given $command and executes it against bin/magento or custom exposed entrypoint. Returns command output.
*
* @param string $command
* @param integer $timeout
* @param string $arguments
* @param string $command
* @param integer|null $timeout
* @param string|null $arguments
* @return string
*
* @throws TestFrameworkException
Expand Down Expand Up @@ -846,9 +846,9 @@ public function fillSecretField($field, $value)
* Function used to create data that contains sensitive credentials in a <createData> <field> override.
* The data is decrypted immediately prior to data creation to avoid exposure in console or log.
*
* @param string $command
* @param null $timeout
* @param null $arguments
* @param string $command
* @param integer|null $timeout
* @param string|null $arguments
* @throws TestFrameworkException
* @return string
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,17 @@ public static function getDefaultWaitTimeout()
return getenv('WAIT_TIMEOUT');
}

/**
* Retrieve default timeout for 'magentoCLI' or 'magentoCLISecret' in seconds
*
* @return integer
*/
public static function getDefaultMagentoCLIWaitTimeout()
{
$timeout = getenv('MAGENTO_CLI_WAIT_TIMEOUT');
return !empty($timeout) ? $timeout : self::DEFAULT_COMMAND_WAIT_TIMEOUT;
}

/**
* This function returns the string property stepKey.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ public function generateStepsPhp($actionObjects, $generationScope = TestGenerato
}

if (in_array($actionObject->getType(), ActionObject::COMMAND_ACTION_ATTRIBUTES)) {
$time = $time ?? ActionObject::DEFAULT_COMMAND_WAIT_TIMEOUT;
$time = $time ?? ActionObject::getDefaultMagentoCLIWaitTimeout();
} else {
$time = $time ?? ActionObject::getDefaultWaitTimeout();
}
Expand Down

0 comments on commit f285fe3

Please sign in to comment.