Skip to content

Commit 54742d5

Browse files
authored
Merge pull request #5017 from magento-engcom/memory-leak-calculation-improvement
[EngCom] Reorder memory leak test
2 parents 2635bd8 + ced306c commit 54742d5

File tree

3 files changed

+36
-24
lines changed

3 files changed

+36
-24
lines changed

dev/tests/integration/framework/Magento/TestFramework/Helper/Memory.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
*/
1111
namespace Magento\TestFramework\Helper;
1212

13+
/**
14+
* Integration Test Framework memory management logic.
15+
*/
1316
class Memory
1417
{
1518
/**
@@ -38,21 +41,21 @@ public function __construct(\Magento\Framework\Shell $shell)
3841
/**
3942
* Retrieve the effective memory usage of the current process
4043
*
41-
* memory_get_usage() cannot be used because of the bug
42-
* @link https://bugs.php.net/bug.php?id=62467
44+
* Function memory_get_usage() cannot be used because of the bug
4345
*
46+
* @link https://bugs.php.net/bug.php?id=62467
4447
* @return int Memory usage in bytes
4548
*/
4649
public function getRealMemoryUsage()
4750
{
4851
$pid = getmypid();
4952
try {
53+
// fall back to the Unix command line
54+
$result = $this->_getUnixProcessMemoryUsage($pid);
55+
} catch (\Magento\Framework\Exception\LocalizedException $e) {
5056
// try to use the Windows command line
5157
// some ports of Unix commands on Windows, such as MinGW, have limited capabilities and cannot be used
5258
$result = $this->_getWinProcessMemoryUsage($pid);
53-
} catch (\Magento\Framework\Exception\LocalizedException $e) {
54-
// fall back to the Unix command line
55-
$result = $this->_getUnixProcessMemoryUsage($pid);
5659
}
5760
return $result;
5861
}
@@ -100,9 +103,11 @@ protected function _getWinProcessMemoryUsage($pid)
100103
* @return int
101104
* @throws \InvalidArgumentException
102105
* @throws \OutOfBoundsException
106+
* phpcs:disable Magento2.Functions.StaticFunction
103107
*/
104108
public static function convertToBytes($number)
105109
{
110+
// phpcs:enable Magento2.Functions.StaticFunction
106111
if (!preg_match('/^(.*\d)\h*(\D)$/', $number, $matches)) {
107112
throw new \InvalidArgumentException("Number format '{$number}' is not recognized.");
108113
}
@@ -132,12 +137,14 @@ public static function convertToBytes($number)
132137
* - but the value has only one delimiter, such as "234,56", then it is impossible to know whether it is decimal
133138
* separator or not. Only knowing the right format would allow this.
134139
*
135-
* @param $number
140+
* @param string $number
136141
* @return string
137142
* @throws \InvalidArgumentException
143+
* phpcs:disable Magento2.Functions.StaticFunction
138144
*/
139145
protected static function _convertToNumber($number)
140146
{
147+
// phpcs:enable Magento2.Functions.StaticFunction
141148
preg_match_all('/(\D+)/', $number, $matches);
142149
if (count(array_unique($matches[0])) > 1) {
143150
throw new \InvalidArgumentException(
@@ -152,9 +159,11 @@ protected static function _convertToNumber($number)
152159
*
153160
* @link http://php.net/manual/en/function.php-uname.php
154161
* @return boolean
162+
* phpcs:disable Magento2.Functions.StaticFunction
155163
*/
156164
public static function isMacOs()
157165
{
166+
// phpcs:enable Magento2.Functions.StaticFunction
158167
return strtoupper(PHP_OS) === 'DARWIN';
159168
}
160169
}

dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/Helper/MemoryTest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,7 @@ public function testGetRealMemoryUsageUnix()
2121
{
2222
$object = new \Magento\TestFramework\Helper\Memory($this->_shell);
2323
$this->_shell->expects(
24-
$this->at(0)
25-
)->method(
26-
'execute'
27-
)->with(
28-
$this->stringStartsWith('tasklist.exe ')
29-
)->will(
30-
$this->throwException(new \Magento\Framework\Exception\LocalizedException(__('command not found')))
31-
);
32-
$this->_shell->expects(
33-
$this->at(1)
24+
$this->once()
3425
)->method(
3526
'execute'
3627
)->with(
@@ -44,7 +35,16 @@ public function testGetRealMemoryUsageUnix()
4435
public function testGetRealMemoryUsageWin()
4536
{
4637
$this->_shell->expects(
47-
$this->once()
38+
$this->at(0)
39+
)->method(
40+
'execute'
41+
)->with(
42+
$this->stringStartsWith('ps ')
43+
)->will(
44+
$this->throwException(new \Magento\Framework\Exception\LocalizedException(__('command not found')))
45+
);
46+
$this->_shell->expects(
47+
$this->at(1)
4848
)->method(
4949
'execute'
5050
)->with(

dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Product/Action/AttributeTest.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,15 @@ class AttributeTest extends \Magento\TestFramework\TestCase\AbstractBackendContr
2222

2323
protected function setUp()
2424
{
25-
$this->publisherConsumerController = Bootstrap::getObjectManager()->create(PublisherConsumerController::class, [
26-
'consumers' => $this->consumers,
27-
'logFilePath' => TESTS_TEMP_DIR . "/MessageQueueTestLog.txt",
28-
'maxMessages' => null,
29-
'appInitParams' => Bootstrap::getInstance()->getAppInitParams()
30-
]);
25+
$this->publisherConsumerController = Bootstrap::getObjectManager()->create(
26+
PublisherConsumerController::class,
27+
[
28+
'consumers' => $this->consumers,
29+
'logFilePath' => TESTS_TEMP_DIR . "/MessageQueueTestLog.txt",
30+
'maxMessages' => null,
31+
'appInitParams' => Bootstrap::getInstance()->getAppInitParams()
32+
]
33+
);
3134

3235
try {
3336
$this->publisherConsumerController->startConsumers();
@@ -124,7 +127,7 @@ public function testSaveActionChangeVisibility($attributes)
124127

125128
$this->publisherConsumerController->waitForAsynchronousResult(
126129
function () use ($repository) {
127-
sleep(3);
130+
sleep(10); // Should be refactored in the scope of MC-22947
128131
return $repository->get(
129132
'simple',
130133
false,

0 commit comments

Comments
 (0)