Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
MemoryUsageTest Class Reference
Inheritance diagram for MemoryUsageTest:

Public Member Functions

 testAppReinitializationNoMemoryLeak ()
 

Data Fields

const APP_REINITIALIZATION_LOOPS = 20
 

Protected Member Functions

 setUp ()
 
 _deallocateUnusedMemory ()
 
 _getAllowedMemoryUsage ()
 

Protected Attributes

 $_helper
 

Detailed Description

Definition at line 8 of file MemoryUsageTest.php.

Member Function Documentation

◆ _deallocateUnusedMemory()

_deallocateUnusedMemory ( )
protected

Force to deallocate no longer used memory

Definition at line 58 of file MemoryUsageTest.php.

59  {
60  gc_collect_cycles();
61  }

◆ _getAllowedMemoryUsage()

_getAllowedMemoryUsage ( )
protected

Retrieve the allowed memory usage in bytes, depending on the environment

Returns
int

Definition at line 68 of file MemoryUsageTest.php.

69  {
70  // Memory usage limits should not be further increased, corresponding memory leaks have to be fixed instead!
71  // @todo fix memory leak and decrease limit to 1 M (in scope of MAGETWO-47693 limit was temporary increased)
72  return \Magento\TestFramework\Helper\Memory::convertToBytes('2M');
73  }

◆ setUp()

setUp ( )
protected

Definition at line 20 of file MemoryUsageTest.php.

21  {
22  if (defined('HHVM_VERSION')) {
23  $this->markTestSkipped("Test not relevant because no gc in HHVM.");
24  }
25  $this->_helper = new \Magento\TestFramework\Helper\Memory(
26  new \Magento\Framework\Shell(new \Magento\Framework\Shell\CommandRenderer())
27  );
28  }

◆ testAppReinitializationNoMemoryLeak()

testAppReinitializationNoMemoryLeak ( )

Test that application reinitialization produces no memory leaks

Definition at line 33 of file MemoryUsageTest.php.

34  {
35  $this->markTestSkipped('Test fails at Travis. Skipped until MAGETWO-47111');
36 
37  $this->_deallocateUnusedMemory();
38  $actualMemoryUsage = $this->_helper->getRealMemoryUsage();
39  for ($i = 0; $i < self::APP_REINITIALIZATION_LOOPS; $i++) {
41  $this->_deallocateUnusedMemory();
42  }
43  $actualMemoryUsage = $this->_helper->getRealMemoryUsage() - $actualMemoryUsage;
44  $this->assertLessThanOrEqual(
45  $this->_getAllowedMemoryUsage(),
46  $actualMemoryUsage,
47  sprintf(
48  "Application reinitialization causes the memory leak of %u bytes per %u iterations.",
49  $actualMemoryUsage,
50  self::APP_REINITIALIZATION_LOOPS
51  )
52  );
53  }
$i
Definition: gallery.phtml:31

Field Documentation

◆ $_helper

$_helper
protected

Definition at line 18 of file MemoryUsageTest.php.

◆ APP_REINITIALIZATION_LOOPS

const APP_REINITIALIZATION_LOOPS = 20

Number of application reinitialization iterations to be conducted by tests

Definition at line 13 of file MemoryUsageTest.php.


The documentation for this class was generated from the following file: