From 4c37a7ba72524635bec7f8b626f943829058374c Mon Sep 17 00:00:00 2001 From: Ji Lu Date: Tue, 5 Dec 2023 09:15:52 -0600 Subject: [PATCH 1/3] ACQE-5871: Add ability to increase default MFTF MagentoCLI timeout --- etc/config/.env.example | 3 +++ etc/config/command.php | 2 +- .../Test/Objects/ActionObject.php | 11 ++++++++++- .../FunctionalTestingFramework/Util/TestGenerator.php | 2 +- 4 files changed, 15 insertions(+), 3 deletions(-) diff --git a/etc/config/.env.example b/etc/config/.env.example index 3291d1082..b3ec2ad41 100644 --- a/etc/config/.env.example +++ b/etc/config/.env.example @@ -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 diff --git a/etc/config/command.php b/etc/config/command.php index 0d8fc7997..3befebc0e 100644 --- a/etc/config/command.php +++ b/etc/config/command.php @@ -14,7 +14,7 @@ $tokenPassedIn = urldecode($_POST['token'] ?? ''); $command = urldecode($_POST['command'] ?? ''); $arguments = urldecode($_POST['arguments'] ?? ''); - $timeout = floatval(urldecode($_POST['timeout'] ?? 60)); + $timeout = floatval(urldecode($_POST['timeout'] ?? getenv('MAGENTO_CLI_WAIT_TIMEOUT'))); // Token returned will be null if the token we passed in is invalid $tokenFromMagento = $tokenModel->loadByToken($tokenPassedIn)->getToken(); diff --git a/src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php b/src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php index 451b58aa0..927c1a69d 100644 --- a/src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php +++ b/src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php @@ -72,7 +72,6 @@ class ActionObject const ACTION_ATTRIBUTE_VARIABLE_REGEX_PARAMETER = '/\(.+\)/'; const ACTION_ATTRIBUTE_VARIABLE_REGEX_PATTERN = '/({{[\w]+\.[\w\[\]]+}})|({{[\w]+\.[\w]+\((?(?!}}).)+\)}})/'; const STRING_PARAMETER_REGEX = "/'[^']+'/"; - const DEFAULT_COMMAND_WAIT_TIMEOUT = 60; const ACTION_ATTRIBUTE_USERINPUT = 'userInput'; const ACTION_TYPE_COMMENT = 'comment'; const ACTION_TYPE_HELPER = 'helper'; @@ -184,6 +183,16 @@ public static function getDefaultWaitTimeout() return getenv('WAIT_TIMEOUT'); } + /** + * Retrieve default timeout for 'magentoCLI' or 'magentoCLISecret' in seconds + * + * @return integer + */ + public static function getDefaultMagentoCLIWaitTimeout() + { + return getenv('MAGENTO_CLI_WAIT_TIMEOUT'); + } + /** * This function returns the string property stepKey. * diff --git a/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php b/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php index 0dfb0f8ee..46a05c946 100644 --- a/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php +++ b/src/Magento/FunctionalTestingFramework/Util/TestGenerator.php @@ -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(); } From a8cce501be2201999990513ede6b7598079b891b Mon Sep 17 00:00:00 2001 From: Ji Lu Date: Tue, 5 Dec 2023 16:07:32 -0600 Subject: [PATCH 2/3] ACQE-5871: Add ability to increase default MagentoCLI timeout --- .../verification/Resources/MagentoCliTest.txt | 59 +++++++++++++++++++ .../BasicFunctionalTest/MagentoCliTest.xml | 16 +++++ .../Tests/BasicCestGenerationTest.php | 13 ++++ .../Test/Objects/ActionObject.php | 4 +- 4 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 dev/tests/verification/Resources/MagentoCliTest.txt create mode 100644 dev/tests/verification/TestModule/Test/BasicFunctionalTest/MagentoCliTest.xml diff --git a/dev/tests/verification/Resources/MagentoCliTest.txt b/dev/tests/verification/Resources/MagentoCliTest.txt new file mode 100644 index 000000000..3efc73c01 --- /dev/null +++ b/dev/tests/verification/Resources/MagentoCliTest.txt @@ -0,0 +1,59 @@ +Test filesverification/TestModule/Test/BasicFunctionalTest/MagentoCliTest.xml
") + */ +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; + } +} diff --git a/dev/tests/verification/TestModule/Test/BasicFunctionalTest/MagentoCliTest.xml b/dev/tests/verification/TestModule/Test/BasicFunctionalTest/MagentoCliTest.xml new file mode 100644 index 000000000..23914943a --- /dev/null +++ b/dev/tests/verification/TestModule/Test/BasicFunctionalTest/MagentoCliTest.xml @@ -0,0 +1,16 @@ + + + + + + + + + + diff --git a/dev/tests/verification/Tests/BasicCestGenerationTest.php b/dev/tests/verification/Tests/BasicCestGenerationTest.php index 39802c50d..a900edbd3 100644 --- a/dev/tests/verification/Tests/BasicCestGenerationTest.php +++ b/dev/tests/verification/Tests/BasicCestGenerationTest.php @@ -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"); + } } diff --git a/src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php b/src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php index 927c1a69d..f0ff060a6 100644 --- a/src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php +++ b/src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php @@ -72,6 +72,7 @@ class ActionObject const ACTION_ATTRIBUTE_VARIABLE_REGEX_PARAMETER = '/\(.+\)/'; const ACTION_ATTRIBUTE_VARIABLE_REGEX_PATTERN = '/({{[\w]+\.[\w\[\]]+}})|({{[\w]+\.[\w]+\((?(?!}}).)+\)}})/'; const STRING_PARAMETER_REGEX = "/'[^']+'/"; + const DEFAULT_COMMAND_WAIT_TIMEOUT = 60; const ACTION_ATTRIBUTE_USERINPUT = 'userInput'; const ACTION_TYPE_COMMENT = 'comment'; const ACTION_TYPE_HELPER = 'helper'; @@ -190,7 +191,8 @@ public static function getDefaultWaitTimeout() */ public static function getDefaultMagentoCLIWaitTimeout() { - return getenv('MAGENTO_CLI_WAIT_TIMEOUT'); + $timeout = getenv('MAGENTO_CLI_WAIT_TIMEOUT'); + return $timeout !== false ? $timeout : self::DEFAULT_COMMAND_WAIT_TIMEOUT; } /** From cfec610e9a63b04ede13323b5c67e0af8351457e Mon Sep 17 00:00:00 2001 From: Ji Lu Date: Wed, 6 Dec 2023 14:21:35 -0600 Subject: [PATCH 3/3] ACQE-5871: Add ability to increase default MagentoCLI timeout --- etc/config/command.php | 2 +- .../Module/MagentoWebDriver.php | 12 ++++++------ .../Test/Objects/ActionObject.php | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/etc/config/command.php b/etc/config/command.php index 480e9b08e..861d016e8 100644 --- a/etc/config/command.php +++ b/etc/config/command.php @@ -14,7 +14,7 @@ $tokenPassedIn = urldecode($_POST['token'] ?? ''); $command = urldecode($_POST['command'] ?? ''); $arguments = urldecode($_POST['arguments'] ?? ''); - $timeout = floatval(urldecode($_POST['timeout'] ?? getenv('MAGENTO_CLI_WAIT_TIMEOUT'))); + $timeout = floatval(urldecode($_POST['timeout'] ?? 60)); // Token returned will be null if the token we passed in is invalid $tokenFromMagento = $tokenModel->loadByToken($tokenPassedIn)->getToken(); diff --git a/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php b/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php index f2580deaf..057876659 100644 --- a/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php +++ b/src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php @@ -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 @@ -846,9 +846,9 @@ public function fillSecretField($field, $value) * Function used to create data that contains sensitive credentials in a 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 */ diff --git a/src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php b/src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php index f0ff060a6..d8ed23098 100644 --- a/src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php +++ b/src/Magento/FunctionalTestingFramework/Test/Objects/ActionObject.php @@ -192,7 +192,7 @@ public static function getDefaultWaitTimeout() public static function getDefaultMagentoCLIWaitTimeout() { $timeout = getenv('MAGENTO_CLI_WAIT_TIMEOUT'); - return $timeout !== false ? $timeout : self::DEFAULT_COMMAND_WAIT_TIMEOUT; + return !empty($timeout) ? $timeout : self::DEFAULT_COMMAND_WAIT_TIMEOUT; } /**