From 49c96499a74bd5089b70f444a1c5179a5af56eb1 Mon Sep 17 00:00:00 2001 From: Tom Reece Date: Mon, 26 Aug 2019 10:32:44 -0500 Subject: [PATCH] MQE-1055: [SPIKE] Audit performance issues with test generation in framework --- .../Test/Objects/ActionGroupObject.php | 21 +++++++++++++------ .../Test/Objects/TestObject.php | 15 +++++++++++-- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/Magento/FunctionalTestingFramework/Test/Objects/ActionGroupObject.php b/src/Magento/FunctionalTestingFramework/Test/Objects/ActionGroupObject.php index 15a5f7ba7..fc38a7fce 100644 --- a/src/Magento/FunctionalTestingFramework/Test/Objects/ActionGroupObject.php +++ b/src/Magento/FunctionalTestingFramework/Test/Objects/ActionGroupObject.php @@ -87,6 +87,13 @@ class ActionGroupObject */ private $filename; + /** + * Holds on to the result of extractStepKeys() to increase test generation performance. + * + * @var string[] + */ + private $cachedStepKeys = null; + /** * ActionGroupObject constructor. * @@ -409,16 +416,18 @@ private function replacePersistedArgument($replacement, $attributeValue, $fullVa */ public function extractStepKeys() { - $originalKeys = []; - foreach ($this->parsedActions as $action) { - //limit actions returned to list that are relevant - foreach (self::STEPKEY_REPLACEMENT_ENABLED_TYPES as $actionValue) { - if ($actionValue === $action->getType()) { + if ($this->cachedStepKeys === null) { + $originalKeys = []; + foreach ($this->parsedActions as $action) { + //limit actions returned to list that are relevant + if (in_array($action->getType(), self::STEPKEY_REPLACEMENT_ENABLED_TYPES)) { $originalKeys[] = $action->getStepKey(); } } + $this->cachedStepKeys = $originalKeys; } - return $originalKeys; + + return $this->cachedStepKeys; } /** diff --git a/src/Magento/FunctionalTestingFramework/Test/Objects/TestObject.php b/src/Magento/FunctionalTestingFramework/Test/Objects/TestObject.php index 30c3a9004..504d207b4 100644 --- a/src/Magento/FunctionalTestingFramework/Test/Objects/TestObject.php +++ b/src/Magento/FunctionalTestingFramework/Test/Objects/TestObject.php @@ -71,6 +71,13 @@ class TestObject */ private $parentTest; + /** + * Holds on to the result of getOrderedActions() to increase test generation performance. + * + * @var ActionObject[] + */ + private $cachedOrderedActions = null; + /** * TestObject constructor. * @@ -255,8 +262,12 @@ public function getCustomData() */ public function getOrderedActions() { - $mergeUtil = new ActionMergeUtil($this->getName(), "Test"); - return $mergeUtil->resolveActionSteps($this->parsedSteps); + if ($this->cachedOrderedActions === null) { + $mergeUtil = new ActionMergeUtil($this->getName(), "Test"); + $this->cachedOrderedActions = $mergeUtil->resolveActionSteps($this->parsedSteps); + } + + return $this->cachedOrderedActions; } /**