Skip to content

Commit

Permalink
Merge pull request #1857 from magento-performance/MAGETWO-85581
Browse files Browse the repository at this point in the history
[Performance] MAGETWO-85581: Enable metrics validation and run benchmark in multithread mode for PAT
  • Loading branch information
vzabaznov authored Dec 18, 2017
2 parents 169b3eb + cb0efb3 commit 5017fda
Show file tree
Hide file tree
Showing 28 changed files with 24,220 additions and 23,283 deletions.
11 changes: 8 additions & 3 deletions app/code/Magento/Catalog/Block/Product/ImageBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace Magento\Catalog\Block\Product;

use Magento\Catalog\Helper\ImageFactory as HelperFactory;
use Magento\Catalog\Model\Product\Image\NotLoadInfoImageException;

class ImageBuilder
{
Expand Down Expand Up @@ -129,7 +130,11 @@ public function create()
? 'Magento_Catalog::product/image.phtml'
: 'Magento_Catalog::product/image_with_borders.phtml';

$imagesize = $helper->getResizedImageInfo();
try {
$imagesize = $helper->getResizedImageInfo();
} catch (NotLoadInfoImageException $exception) {
$imagesize = [$helper->getWidth(), $helper->getHeight()];
}

$data = [
'data' => [
Expand All @@ -140,8 +145,8 @@ public function create()
'label' => $helper->getLabel(),
'ratio' => $this->getRatio($helper),
'custom_attributes' => $this->getCustomAttributes(),
'resized_image_width' => !empty($imagesize[0]) ? $imagesize[0] : $helper->getWidth(),
'resized_image_height' => !empty($imagesize[1]) ? $imagesize[1] : $helper->getHeight(),
'resized_image_width' => $imagesize[0],
'resized_image_height' => $imagesize[1],
],
];

Expand Down
22 changes: 16 additions & 6 deletions app/code/Magento/Catalog/Model/Product/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
namespace Magento\Catalog\Model\Product;

use Magento\Catalog\Model\Product\Image\NotLoadInfoImageException;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Image as MagentoImage;
Expand Down Expand Up @@ -877,17 +878,26 @@ protected function _fileExists($filename)

/**
* Return resized product image information
*
* @return array
* @throws NotLoadInfoImageException
*/
public function getResizedImageInfo()
{
if ($this->isBaseFilePlaceholder() == true) {
$image = $this->imageAsset->getSourceFile();
} else {
$image = $this->imageAsset->getPath();
try {
if ($this->isBaseFilePlaceholder() == true) {
$image = $this->imageAsset->getSourceFile();
} else {
$image = $this->imageAsset->getPath();
}

$imageProperties = getimagesize($image);

return $imageProperties;
} finally {
if (empty($imageProperties)) {
throw new NotLoadInfoImageException(__('Can\'t get information about the picture: %1', $image));
}
}
return getimagesize($image);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Catalog\Model\Product\Image;

class NotLoadInfoImageException extends \Exception
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Magento\Catalog\Api\Data\ProductRender\ImageInterfaceFactory;
use Magento\Catalog\Api\Data\ProductRenderInterface;
use Magento\Catalog\Helper\ImageFactory;
use Magento\Catalog\Model\Product\Image\NotLoadInfoImageException;
use Magento\Catalog\Ui\DataProvider\Product\ProductRenderCollectorInterface;
use Magento\Framework\App\State;
use Magento\Framework\View\DesignInterface;
Expand Down Expand Up @@ -102,7 +103,12 @@ public function collect(ProductInterface $product, ProductRenderInterface $produ
[$this, "emulateImageCreating"],
[$product, $imageCode, (int) $productRender->getStoreId(), $image]
);
$resizedInfo = $helper->getResizedImageInfo();

try {
$resizedInfo = $helper->getResizedImageInfo();
} catch (NotLoadInfoImageException $exception) {
$resizedInfo = [$helper->getWidth(), $helper->getHeight()];
}

$image->setCode($imageCode);
$image->setHeight($helper->getHeight());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class Collection extends \Magento\Catalog\Model\ResourceModel\Product\Collection
/**
* @var string|null
*/
private $order = null;
private $relevanceOrderDirection = null;

/**
* @var string
Expand Down Expand Up @@ -361,9 +361,19 @@ protected function _renderFiltersBefore()
[]
);

if ($this->order && 'relevance' === $this->order['field']) {
$this->getSelect()->order('search_result.'. TemporaryStorage::FIELD_SCORE . ' ' . $this->order['dir']);
if ($this->relevanceOrderDirection) {
$this->getSelect()->order(
'search_result.'. TemporaryStorage::FIELD_SCORE . ' ' . $this->relevanceOrderDirection
);
}

/*
* This order is required to force search results be the same
* for the same requests and products with the same relevance
* NOTE: this does not replace existing orders but ADDs one more
*/
$this->setOrder('entity_id');

return parent::_renderFiltersBefore();
}

Expand All @@ -385,10 +395,12 @@ protected function _renderFilters()
*/
public function setOrder($attribute, $dir = Select::SQL_DESC)
{
$this->order = ['field' => $attribute, 'dir' => $dir];
if ($attribute !== 'relevance') {
if ($attribute === 'relevance') {
$this->relevanceOrderDirection = $dir;
} else {
parent::setOrder($attribute, $dir);
}

return $this;
}

Expand Down
11 changes: 8 additions & 3 deletions app/code/Magento/Wishlist/CustomerData/Wishlist.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
namespace Magento\Wishlist\CustomerData;

use Magento\Catalog\Model\Product\Image\NotLoadInfoImageException;
use Magento\Customer\CustomerData\SectionSourceInterface;

/**
Expand Down Expand Up @@ -154,15 +155,19 @@ protected function getImageData($product)
? 'Magento_Catalog/product/image'
: 'Magento_Catalog/product/image_with_borders';

$imagesize = $helper->getResizedImageInfo();
try {
$imagesize = $helper->getResizedImageInfo();
} catch (NotLoadInfoImageException $exception) {
$imagesize = [$helper->getWidth(), $helper->getHeight()];
}

$width = $helper->getFrame()
? $helper->getWidth()
: (!empty($imagesize[0]) ? $imagesize[0] : $helper->getWidth());
: $imagesize[0];

$height = $helper->getFrame()
? $helper->getHeight()
: (!empty($imagesize[1]) ? $imagesize[1] : $helper->getHeight());
: $imagesize[1];

return [
'template' => $template,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,45 @@ public function testLoadWithFilterSearch($request, $filters, $expectedCount)
$this->assertCount($expectedCount, $items);
}

/**
* @magentoDataFixture Magento/Framework/Search/_files/products_with_the_same_search_score.php
*/
public function testSearchResultsAreTheSameForSameRequests()
{
$howManySearchRequests = 3;
$previousResult = null;

$objManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();

foreach (range(1, $howManySearchRequests) as $i) {
/** @var \Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection $fulltextCollection */
$fulltextCollection = $objManager->create(
\Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection::class,
['searchRequestName' => 'quick_search_container']
);

$fulltextCollection->addFieldToFilter('search_term', 'shorts');
$fulltextCollection->setOrder('relevance');
$fulltextCollection->load();
$items = $fulltextCollection->getItems();
$this->assertGreaterThan(
0,
count($items),
sprintf("Search #%s result must not be empty", $i)
);

if ($previousResult) {
$this->assertEquals(
$previousResult,
array_keys($items),
"Search result must be the same for the same requests"
);
}

$previousResult = array_keys($items);
}
}

public function filtersDataProviderSearch()
{
return [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\Product\Attribute\Source\Status;
use Magento\Catalog\Model\Product\Type;
use Magento\Catalog\Model\Product\Visibility;
use Magento\TestFramework\Helper\Bootstrap;

Bootstrap::getInstance()->reinitialize();

/** @var ProductRepositoryInterface $productRepository */
$productRepository = Bootstrap::getObjectManager()
->create(ProductRepositoryInterface::class);

$howManyProducts = 5;

foreach (range(1, $howManyProducts) as $productId) {
$product = Bootstrap::getObjectManager()->create(Product::class);
$product->setTypeId(Type::TYPE_SIMPLE)
->setAttributeSetId(4)
->setWebsiteIds([1])
->setName('Cool short' . $productId)
->setSku('cool_shorts_' . $productId)
->setPrice(42)
->setShortDescription("Some description about shorts")
->setTaxClassId(0)
->setDescription('Some description about <b>shorts</b>')
->setVisibility(Visibility::VISIBILITY_BOTH)
->setStatus(Status::STATUS_ENABLED)
->setStockData(
[
'use_config_manage_stock' => 1,
'qty' => 100,
'is_qty_decimal' => 0,
'is_in_stock' => 1,
]
);

$productRepository->save($product);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/** @var \Magento\Framework\Registry $registry */
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$registry = $objectManager->get(\Magento\Framework\Registry::class);

$registry->unregister('isSecureArea');
$registry->register('isSecureArea', true);

/** @var \Magento\Catalog\Model\ResourceModel\Product\Collection $collection */
$collection = $objectManager->create(\Magento\Catalog\Model\ResourceModel\Product\Collection::class);
$collection->addAttributeToSelect('id')->load();
if ($collection->count() > 0) {
$collection->delete();
}

$registry->unregister('isSecureArea');
$registry->register('isSecureArea', false);
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function testFixtureGeneration()

foreach ($this->entityAsserts as $entityAssert) {
try {
$entityAssert->assert();
$this->assertTrue($entityAssert->assert());
} catch (\AssertionError $assertionError) {
$this->assertTrue(false, $assertionError->getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function __construct(
/**
* Asserts that generated bundled products are valid
*
* @return void
* @return bool
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @throws \AssertionError
*/
Expand All @@ -74,5 +74,7 @@ public function assert()
throw new \AssertionError('Bundle option product links amount is wrong');
}
}

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function __construct(
/**
* Asserts that generated configurable products are valid
*
* @return void
* @return bool
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @throws \Magento\Framework\Exception\InputException
* @throws \AssertionError
Expand Down Expand Up @@ -86,5 +86,7 @@ public function assert()
throw new \AssertionError('Configurable option values amount is wrong');
}
}

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public function __construct(
/**
* Performs assertions over images
*
* @return bool
* @throws \AssertionError
*/
public function assert()
Expand All @@ -82,6 +83,8 @@ public function assert()
$this->assertProductMediaAttributes($product);
$this->assertProductImageExistsInFS($product);
}

return true;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function __construct(
/**
* Asserts that generated simple products are valid
*
* @return void
* @return bool
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @throws \AssertionError
*/
Expand All @@ -52,5 +52,7 @@ public function assert()
$product = $this->productRepository->get(sprintf(SimpleProductsFixture::SKU_PATTERN, 1));
$this->productAssert->assertProductsCount(SimpleProductsFixture::SKU_PATTERN, 2);
$this->productAssert->assertProductType('simple', $product);

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
\Magento\Framework\DB\Adapter\DuplicateException
\Magento\Framework\DB\DataConverter\DataConversionException
\Magento\Framework\DB\FieldDataConversionException
\Magento\Catalog\Model\Product\Image\NotLoadInfoImageException
2 changes: 1 addition & 1 deletion setup/performance-toolkit/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ The following parameters can be passed to the `benchmark.jmx` scenario:
| admin_user | admin | Admin backend user. |
| admin_password | 123123q | Admin backend password. |
| customer_password | 123123q | Storefront customer password. |
| customers_page_size | 20 | Page size for customers grid in Magento Admin. |
| customers_page_size | 50 | Page size for customers grid in Magento Admin. |
| files_folder | ./files/ | Path to various files that are used in scenario (`setup/performance-toolkit/files`). |
| loops | 1 | Number of loops to run. |
| frontendPoolUsers | 1 | Total number of Frontend threads. |
Expand Down
Loading

0 comments on commit 5017fda

Please sign in to comment.