Skip to content

Commit

Permalink
Merge pull request #581 from magento-performance/ACPT-1688_2
Browse files Browse the repository at this point in the history
ACPT-1688: Fix Static Tests failures on Application-Server branch
  • Loading branch information
andimov authored Nov 29, 2023
2 parents 3cf454d + dca3621 commit ee0548e
Show file tree
Hide file tree
Showing 14 changed files with 65 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
*/
class MetricType
{
public const Other = "Other";
public const SecondsElapsedFloat = "SecondsElapsedFloat";
public const UnixTimestampFloat = "UnixTimestampFloat";
public const MemorySizeInt = "MemorySizeInt";
public const OTHER = "Other";
public const SECONDS_ELAPSED_FLOAT = "SecondsElapsedFloat";
public const UNIX_TIMESTAMP_FLOAT = "UnixTimestampFloat";
public const MEMORY_SIZE_INT = "MemorySizeInt";
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,103 +32,103 @@ public function compareMetrics(Metrics $beforeMetrics, Metrics $afterMetrics, ?M
{
$metrics = [];
$metrics['memoryUsageBefore'] = $this->metricFactory->create([
'type' => MetricType::MemorySizeInt,
'type' => MetricType::MEMORY_SIZE_INT,
'name' => 'memoryUsageBefore',
'value' => $beforeMetrics->getMemoryUsage(),
'verbose' => true,
]);
$metrics['memoryUsageAfter'] = $this->metricFactory->create([
'type' => MetricType::MemorySizeInt,
'type' => MetricType::MEMORY_SIZE_INT,
'name' => 'memoryUsageAfter',
'value' => $afterMetrics->getMemoryUsage(),
'verbose' => false,
]);
if ($previousAfterMetrics) {
$metrics['memoryUsageAfterComparedToPrevious'] = $this->metricFactory->create([
'type' => MetricType::MemorySizeInt,
'type' => MetricType::MEMORY_SIZE_INT,
'name' => 'memoryUsageAfterComparedToPrevious',
'value' => $afterMetrics->getMemoryUsage() - $previousAfterMetrics->getMemoryUsage(),
'verbose' => false,
]);
}
$metrics['memoryUsageDelta'] = $this->metricFactory->create([
'type' => MetricType::MemorySizeInt,
'type' => MetricType::MEMORY_SIZE_INT,
'name' => 'memoryUsageDelta',
'value' => $afterMetrics->getMemoryUsage() - $beforeMetrics->getMemoryUsage(),
'verbose' => false,
]);
$metrics['peakMemoryUsageBefore'] = $this->metricFactory->create([
'type' => MetricType::MemorySizeInt,
'type' => MetricType::MEMORY_SIZE_INT,
'name' => 'peakMemoryUsageBefore',
'value' => $beforeMetrics->getPeakMemoryUsage(),
'verbose' => true,
]);
$metrics['peakMemoryUsageAfter'] = $this->metricFactory->create([
'type' => MetricType::MemorySizeInt,
'type' => MetricType::MEMORY_SIZE_INT,
'name' => 'peakMemoryUsageAfter',
'value' => $afterMetrics->getPeakMemoryUsage(),
'verbose' => false,
]);
$metrics['peakMemoryUsageDelta'] = $this->metricFactory->create([
'type' => MetricType::MemorySizeInt,
'type' => MetricType::MEMORY_SIZE_INT,
'name' => 'peakMemoryUsageDelta',
'value' => $afterMetrics->getPeakMemoryUsage() - $beforeMetrics->getPeakMemoryUsage(),
'verbose' => false,
]);
$metrics['wallTimeBefore'] = $this->metricFactory->create([
'type' => MetricType::UnixTimestampFloat,
'type' => MetricType::UNIX_TIMESTAMP_FLOAT,
'name' => 'wallTimeBefore',
'value' => $beforeMetrics->getMicrotime(),
'verbose' => true,
]);
$metrics['wallTimeAfter'] = $this->metricFactory->create([
'type' => MetricType::UnixTimestampFloat,
'type' => MetricType::UNIX_TIMESTAMP_FLOAT,
'name' => 'wallTimeAfter',
'value' => $afterMetrics->getMicrotime(),
'verbose' => true,
]);
$metrics['wallTimeElapsed'] = $this->metricFactory->create([
'type' => MetricType::SecondsElapsedFloat,
'type' => MetricType::SECONDS_ELAPSED_FLOAT,
'name' => 'wallTimeElapsed',
'value' => $afterMetrics->getMicrotime() - $beforeMetrics->getMicrotime(),
'verbose' => false,
]);
$metrics['userTimeBefore'] = $this->metricFactory->create([
'type' => MetricType::SecondsElapsedFloat,
'type' => MetricType::SECONDS_ELAPSED_FLOAT,
'name' => 'userTimeBefore',
'value' => $beforeMetrics->getRusage()['ru_utime.tv_sec']
+ 0.000001 * $beforeMetrics->getRusage()['ru_utime.tv_usec'],
'verbose' => true,
]);
$metrics['userTimeAfter'] = $this->metricFactory->create([
'type' => MetricType::SecondsElapsedFloat,
'type' => MetricType::SECONDS_ELAPSED_FLOAT,
'name' => 'userTimeAfter',
'value' => $afterMetrics->getRusage()['ru_utime.tv_sec']
+ 0.000001 * $afterMetrics->getRusage()['ru_utime.tv_usec'],
'verbose' => true,
]);
$metrics['userTimeElapsed'] = $this->metricFactory->create([
'type' => MetricType::SecondsElapsedFloat,
'type' => MetricType::SECONDS_ELAPSED_FLOAT,
'name' => 'userTimeElapsed',
'value' => $metrics['userTimeAfter']->getValue() - $metrics['userTimeBefore']->getValue(),
'verbose' => true,
]);
$metrics['systemTimeBefore'] = $this->metricFactory->create([
'type' => MetricType::SecondsElapsedFloat,
'type' => MetricType::SECONDS_ELAPSED_FLOAT,
'name' => 'systemTimeBefore',
'value' => $beforeMetrics->getRusage()['ru_stime.tv_sec']
+ 0.000001 * $beforeMetrics->getRusage()['ru_stime.tv_usec'],
'verbose' => true,
]);
$metrics['systemTimeAfter'] = $this->metricFactory->create([
'type' => MetricType::SecondsElapsedFloat,
'type' => MetricType::SECONDS_ELAPSED_FLOAT,
'name' => 'systemTimeAfter',
'value' => $afterMetrics->getRusage()['ru_stime.tv_sec']
+ 0.000001 * $afterMetrics->getRusage()['ru_stime.tv_usec'],
'verbose' => true,
]);
$metrics['systemTimeElapsed'] = $this->metricFactory->create([
'type' => MetricType::SecondsElapsedFloat,
'type' => MetricType::SECONDS_ELAPSED_FLOAT,
'name' => 'systemTimeElapsed',
'value' => $metrics['systemTimeAfter']->getValue() - $metrics['systemTimeBefore']->getValue(),
'verbose' => true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@ private function doOutputMetrics(array $metrics, bool $verbose)
continue;
}
switch ($metric->getType()) {
case MetricType::SecondsElapsedFloat:
case MetricType::SECONDS_ELAPSED_FLOAT:
$prettyMetrics[$metric->getName()] = $this->prettyElapsedTime($metric->getValue());
break;
case MetricType::UnixTimestampFloat:
case MetricType::UNIX_TIMESTAMP_FLOAT:
$prettyMetrics[$metric->getName()] = $this->prettyUnixTime($metric->getValue());
break;
case MetricType::MemorySizeInt:
case MetricType::MEMORY_SIZE_INT:
$prettyMetrics[$metric->getName()] = $this->prettyMemorySize($metric->getValue());
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\CatalogGraphQl\DataProvider\Product;

use Magento\Framework\ObjectManager\ResetAfterRequestInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@ public function testCacheIsInvalidatedOnProductDeletion()
* @param ProductInterface $product
* @return void
* @throws \Zend_Cache_Exception
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
*/
private function assertCacheIdIsNotOrphanedInTagsForProduct(ProductInterface $product)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
/* These classes are skipped completely during comparison. */
return [
'*' => [
// phpcs:disable Generic.Files.LineLength.TooLong
// list of the latest failures started
Magento\Sales\Api\Data\ShippingAssignmentInterfaceFactory::class => null,
Magento\Sales\Model\Order\ShippingBuilderFactory::class => null,
Expand Down Expand Up @@ -358,8 +359,10 @@
'QuoteRelationsComposite' => null,
Magento\GraphQlCache\Model\Plugin\Auth\TokenIssuer::class => null,
Magento\StoreGraphQl\Plugin\LocalizeEmail::class => null,
// phpcs:enable Generic.Files.LineLength.TooLong
],
'*-fromConstructed' => [
// phpcs:disable Generic.Files.LineLength.TooLong
Magento\Sales\Model\ResourceModel\Grid::class => null,
Magento\Sales\Model\ResourceModel\GridPool::class => null,
Magento\Sales\Api\Data\OrderExtension::class => null,
Expand Down Expand Up @@ -714,6 +717,7 @@
Magento\Staging\Model\Update\Flag::class => null,
Magento\Catalog\Model\Category\Attribute\Source\Sortby::class => null,
Magento\Config\App\Config\Source\EnvironmentConfigSource::class => null,
// phpcs:enable Generic.Files.LineLength.TooLong
],
'' => [
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,15 @@ public function testResetAfterRequestClasses(string $className)
}
try {
/** @var ResetAfterRequestInterface $object */
$beforeProperties = $this->collector->getPropertiesFromObject($object, CompareType::CompareBetweenRequests);
$beforeProperties = $this->collector->getPropertiesFromObject(
$object,
CompareType::COMPARE_BETWEEN_REQUESTS
);
$object->_resetState();
$afterProperties = $this->collector->getPropertiesFromObject($object, CompareType::CompareBetweenRequests);
$afterProperties = $this->collector->getPropertiesFromObject(
$object,
CompareType::COMPARE_BETWEEN_REQUESTS
);
$differences = [];
foreach ($afterProperties as $propertyName => $propertyValue) {
if ($propertyValue instanceof ObjectManagerInterface) {
Expand All @@ -193,7 +199,11 @@ public function testResetAfterRequestClasses(string $className)
// TODO: Can we convert _regionModels to member variable,
// or move to a dependency injected service class instead?
}
$result = $this->comparator->checkValues($beforeProperties[$propertyName] ?? null, $propertyValue, 3);
$result = $this->comparator->checkValues(
$beforeProperties[$propertyName] ?? null,
$propertyValue,
3
);
if ($result) {
$differences[$propertyName] = $result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public function __construct(
SkipListAndFilterList $skipListAndFilterList
) {
$this->skipListFromConstructed =
$skipListAndFilterList->getSkipList('', CompareType::CompareConstructedAgainstCurrent);
$this->skipListBetweenRequests = $skipListAndFilterList->getSkipList('', CompareType::CompareBetweenRequests);
$skipListAndFilterList->getSkipList('', CompareType::COMPARE_CONSTRUCTED_AGAINST_CURRENT);
$this->skipListBetweenRequests = $skipListAndFilterList->getSkipList('', CompareType::COMPARE_BETWEEN_REQUESTS);
}

/**
Expand Down Expand Up @@ -109,15 +109,15 @@ public function getSharedObjects(string $shouldResetState): array
if (array_key_exists($serviceName, $sharedObjects)) {
continue;
}
if (ShouldResetState::DoResetState == $shouldResetState &&
if (ShouldResetState::DO_RESET_STATE == $shouldResetState &&
($object instanceof ResetAfterRequestInterface)) {
$object->_resetState();
}
if ($object instanceof \Magento\Framework\ObjectManagerInterface) {
continue;
}
$sharedObjects[$serviceName] =
$this->getPropertiesFromObject($object, CompareType::CompareBetweenRequests);
$this->getPropertiesFromObject($object, CompareType::COMPARE_BETWEEN_REQUESTS);
}
return $sharedObjects;
}
Expand Down Expand Up @@ -145,7 +145,7 @@ public function getPropertiesConstructedAndCurrent(): array
$objects[] = new CollectedObjectConstructedAndCurrent(
$object,
$propertiesBefore,
$this->getPropertiesFromObject($object, CompareType::CompareConstructedAgainstCurrent),
$this->getPropertiesFromObject($object, CompareType::COMPARE_CONSTRUCTED_AGAINST_CURRENT),
);
}
return $objects;
Expand All @@ -167,7 +167,7 @@ public function getPropertiesFromObject(
int $recursionLevel = 0,
): CollectedObject {
$className = get_class($object);
$skipList = $compareType == CompareType::CompareBetweenRequests ?
$skipList = $compareType == CompareType::COMPARE_BETWEEN_REQUESTS ?
$this->skipListBetweenRequests : $this->skipListFromConstructed ;
if (array_key_exists($className, $skipList)) {
return CollectedObject::getSkippedObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function __construct(
public function rememberObjectsStateBefore(bool $firstRequest): void
{
if ($firstRequest) {
$this->objectsStateBefore = $this->collector->getSharedObjects(ShouldResetState::DoNotResetState);
$this->objectsStateBefore = $this->collector->getSharedObjects(ShouldResetState::DO_NOT_RESET_STATE);
}
}

Expand All @@ -53,7 +53,7 @@ public function rememberObjectsStateBefore(bool $firstRequest): void
*/
public function rememberObjectsStateAfter(bool $firstRequest): void
{
$this->objectsStateAfter = $this->collector->getSharedObjects(ShouldResetState::DoResetState);
$this->objectsStateAfter = $this->collector->getSharedObjects(ShouldResetState::DO_RESET_STATE);
if ($firstRequest) {
// on the end of first request add objects to init object state pool
$this->objectsStateBefore = array_merge($this->objectsStateAfter, $this->objectsStateBefore);
Expand All @@ -71,7 +71,7 @@ public function rememberObjectsStateAfter(bool $firstRequest): void
public function compareBetweenRequests(string $operationName): array
{
$compareResults = [];
$skipList = $this->skipListAndFilterList->getSkipList($operationName, CompareType::CompareBetweenRequests);
$skipList = $this->skipListAndFilterList->getSkipList($operationName, CompareType::COMPARE_BETWEEN_REQUESTS);
foreach ($this->objectsStateAfter as $serviceName => $afterCollectedObject) {
if (array_key_exists($serviceName, $skipList)) {
continue;
Expand Down Expand Up @@ -101,7 +101,7 @@ public function compareConstructedAgainstCurrent(string $operationName): array
{
$compareResults = [];
$skipList = $this->skipListAndFilterList
->getSkipList($operationName, CompareType::CompareConstructedAgainstCurrent);
->getSkipList($operationName, CompareType::COMPARE_CONSTRUCTED_AGAINST_CURRENT);
foreach ($this->collector->getPropertiesConstructedAndCurrent() as $objectAndProperties) {
$object = $objectAndProperties->getObject();
$constructedObject = $objectAndProperties->getConstructedCollected();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
*/
class CompareType
{
public const CompareBetweenRequests = "CompareBetweenRequests";
public const CompareConstructedAgainstCurrent = "CompareConstructedAgainstCurrent";
public const COMPARE_BETWEEN_REQUESTS = "CompareBetweenRequests";
public const COMPARE_CONSTRUCTED_AGAINST_CURRENT = "CompareConstructedAgainstCurrent";
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function __construct(Developer $developer, ObjectManager $objectManager)
$this->objectManager = $objectManager;
$this->weakMap = new WeakMap();
$skipListAndFilterList = new SkipListAndFilterList;
$this->skipList = $skipListAndFilterList->getSkipList('', CompareType::CompareConstructedAgainstCurrent);
$this->skipList = $skipListAndFilterList->getSkipList('', CompareType::COMPARE_CONSTRUCTED_AGAINST_CURRENT);
$this->collector = new Collector($this->objectManager, $skipListAndFilterList);
$this->objectManager->addSharedInstance($skipListAndFilterList, SkipListAndFilterList::class);
$this->objectManager->addSharedInstance($this->collector, Collector::class);
Expand All @@ -57,7 +57,7 @@ public function create($type, array $arguments = [])
$object = parent::create($type, $arguments);
if (!array_key_exists(get_class($object), $this->skipList)) {
$this->weakMap[$object] =
$this->collector->getPropertiesFromObject($object, CompareType::CompareConstructedAgainstCurrent);
$this->collector->getPropertiesFromObject($object, CompareType::COMPARE_CONSTRUCTED_AGAINST_CURRENT);
}
return $object;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@

class ShouldResetState
{
public const DoResetState = "DoResetState";
public const DoNotResetState = "DoNotResetState";
public const DO_RESET_STATE = "DoResetState";
public const DO_NOT_RESET_STATE = "DoNotResetState";
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class SkipListAndFilterList
*/
private ?array $filterList = null;

private readonly $fixturePath =
'/dev/tests/integration/framework/Magento/TestFramework/ApplicationStateComparator/_files';
private const FIXTURE_PATH =
"/dev/tests/integration/framework/Magento/TestFramework/ApplicationStateComparator/_files";

/**
* Filters properties by the list of property filters
Expand All @@ -53,7 +53,7 @@ public function getSkipList(string $operationName, string $compareType): array
{
if ($this->skipList === null) {
$skipListList = [];
foreach (glob(BP . $fixturePath . '/state-skip-list*.php') as $skipListFile) {
foreach (glob(BP . self::FIXTURE_PATH . '/state-skip-list*.php') as $skipListFile) {
$skipListList[] = include($skipListFile);
}
$this->skipList = array_merge_recursive(...$skipListList);
Expand All @@ -65,7 +65,7 @@ public function getSkipList(string $operationName, string $compareType): array
if (array_key_exists($operationName, $this->skipList)) {
$skipLists[] = $this->skipList[$operationName];
}
if (CompareType::CompareConstructedAgainstCurrent == $compareType) {
if (CompareType::COMPARE_CONSTRUCTED_AGAINST_CURRENT == $compareType) {
if (array_key_exists($operationName . '-fromConstructed', $this->skipList)) {
$skipLists[] = $this->skipList[$operationName . '-fromConstructed'];
}
Expand All @@ -85,7 +85,7 @@ public function getFilterList(): array
{
if ($this->filterList === null) {
$filterListList = [];
foreach (glob(BP . $fixturePath . '/state-filter-list*.php') as $filterListFile) {
foreach (glob(BP . self::FIXTURE_PATH . '/state-filter-list*.php') as $filterListFile) {
$filterListList[] = include($filterListFile);
}
$this->filterList = array_merge_recursive(...$filterListList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ private function extract(): string
} elseif ($triggerClass && !$tokenIsArray) {
$triggerClass = false;
// `class` token was used as a string; not to define class
// phpstan:ignore
} elseif ($triggerClass && empty($class) && $token[0] === T_DOUBLE_ARROW) {
$triggerClass = false;
continue;
Expand Down

0 comments on commit ee0548e

Please sign in to comment.