b374k
m1n1 1.01
Apache/2.4.41 (Ubuntu)
Linux vmi616275.contaboserver.net 5.4.0-84-generic #94-Ubuntu SMP Thu Aug 26 20:27:37 UTC 2021 x86_64
uid=33(www-data) gid=33(www-data) groups=33(www-data)
server ip : 62.171.164.128 | your ip : 127.0.0.1
safemode OFF
 >  / home / a / home / dev2.destoffenstraat.com / dev / tests / integration / testsuite / Magento /
Filename/home/a/home/dev2.destoffenstraat.com/dev/tests/integration/testsuite/Magento/MemoryUsageTest.php
Size2.33 kb
Permissionrw-r--r--
Ownerroot : root
Create time21-Aug-2025 12:26
Last modified28-Jan-2025 06:45
Last accessed22-Aug-2025 22:03
Actionsedit | rename | delete | download (gzip)
Viewtext | code | image
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento;

class MemoryUsageTest extends \PHPUnit\Framework\TestCase
{
/**
* Number of application reinitialization iterations to be conducted by tests
*/
const APP_REINITIALIZATION_LOOPS = 20;

/**
* @var \Magento\TestFramework\Helper\Memory
*/
protected $_helper;

protected function setUp(): void
{
if (defined('HHVM_VERSION')) {
$this->markTestSkipped("Test not relevant because no gc in HHVM.");
}
$this->_helper = new \Magento\TestFramework\Helper\Memory(
new \Magento\Framework\Shell(new \Magento\Framework\Shell\CommandRenderer())
);
}

/**
* Test that application reinitialization produces no memory leaks
*/
public function testAppReinitializationNoMemoryLeak()
{
$this->markTestSkipped('Skipped until MAGETWO-47111');

$this->_deallocateUnusedMemory();
$actualMemoryUsage = $this->_helper->getRealMemoryUsage();
for ($i = 0; $i < self::APP_REINITIALIZATION_LOOPS; $i++) {
\Magento\TestFramework\Helper\Bootstrap::getInstance()->reinitialize();
$this->_deallocateUnusedMemory();
}
$actualMemoryUsage = $this->_helper->getRealMemoryUsage() - $actualMemoryUsage;
$this->assertLessThanOrEqual(
$this->_getAllowedMemoryUsage(),
$actualMemoryUsage,
sprintf(
"Application reinitialization causes the memory leak of %u bytes per %u iterations.",
$actualMemoryUsage,
self::APP_REINITIALIZATION_LOOPS
)
);
}

/**
* Force to deallocate no longer used memory
*/
protected function _deallocateUnusedMemory()
{
gc_collect_cycles();
}

/**
* Retrieve the allowed memory usage in bytes, depending on the environment
*
* @return int
*/
protected function _getAllowedMemoryUsage()
{
// Memory usage limits should not be further increased, corresponding memory leaks have to be fixed instead!
// @todo fix memory leak and decrease limit to 1 M (in scope of MAGETWO-47693 limit was temporary increased)
return \Magento\TestFramework\Helper\Memory::convertToBytes('2M');
}
}