Skip to content

Commit c14de14

Browse files
authored
Merge pull request #435 from agentsib/master
Fix isRamAlmostOverloaded function in Consumer
2 parents d4d7226 + 068020d commit c14de14

File tree

4 files changed

+31
-5
lines changed

4 files changed

+31
-5
lines changed

Command/BaseConsumerCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ protected function configure()
4343
->addArgument('name', InputArgument::REQUIRED, 'Consumer Name')
4444
->addOption('messages', 'm', InputOption::VALUE_OPTIONAL, 'Messages to consume', 0)
4545
->addOption('route', 'r', InputOption::VALUE_OPTIONAL, 'Routing Key', '')
46-
->addOption('memory-limit', 'l', InputOption::VALUE_OPTIONAL, 'Allowed memory for this process', null)
46+
->addOption('memory-limit', 'l', InputOption::VALUE_OPTIONAL, 'Allowed memory for this process (MB)', null)
4747
->addOption('debug', 'd', InputOption::VALUE_NONE, 'Enable Debugging')
4848
->addOption('without-signals', 'w', InputOption::VALUE_NONE, 'Disable catching of system signals')
4949
;

MemoryChecker/MemoryConsumptionChecker.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function __construct(NativeMemoryUsageProvider $memoryUsageProvider) {
2727
*
2828
* @return bool
2929
*/
30-
public function isRamAlmostOverloaded($allowedConsumptionUntil, $maxConsumptionAllowed)
30+
public function isRamAlmostOverloaded($maxConsumptionAllowed, $allowedConsumptionUntil = 0)
3131
{
3232
$allowedConsumptionUntil = $this->convertHumanUnitToNumerical($allowedConsumptionUntil);
3333
$maxConsumptionAllowed = $this->convertHumanUnitToNumerical($maxConsumptionAllowed);

RabbitMq/Consumer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ protected function isRamAlmostOverloaded()
212212
{
213213
$memoryManager = new MemoryConsumptionChecker(new NativeMemoryUsageProvider());
214214

215-
return $memoryManager->isRamAlmostOverloaded($this->getMemoryLimit(), '5M');
215+
return $memoryManager->isRamAlmostOverloaded($this->getMemoryLimit().'M', '5M');
216216
}
217217

218218
/**

Tests/Manager/MemoryCheckerTest.php

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function testMemoryIsNotAlmostOverloaded()
2323

2424
$memoryManager = new MemoryConsumptionChecker($memoryUsageProvider);
2525

26-
$this->assertFalse($memoryManager->isRamAlmostOverloaded($allowedConsumptionUntil, $maxConsumptionAllowed));
26+
$this->assertFalse($memoryManager->isRamAlmostOverloaded($maxConsumptionAllowed, $allowedConsumptionUntil));
2727
}
2828

2929
public function testMemoryIsAlmostOverloaded()
@@ -37,6 +37,32 @@ public function testMemoryIsAlmostOverloaded()
3737

3838
$memoryManager = new MemoryConsumptionChecker($memoryUsageProvider);
3939

40-
$this->assertTrue($memoryManager->isRamAlmostOverloaded($allowedConsumptionUntil, $maxConsumptionAllowed));
40+
$this->assertTrue($memoryManager->isRamAlmostOverloaded($maxConsumptionAllowed, $allowedConsumptionUntil));
41+
}
42+
43+
public function testMemoryExactValueIsNotAlmostOverloaded()
44+
{
45+
$currentMemoryUsage = '7M';
46+
$maxConsumptionAllowed = '10M';
47+
48+
$memoryUsageProvider = $this->getMockBuilder('OldSound\\RabbitMqBundle\\MemoryChecker\\NativeMemoryUsageProvider')->getMock();
49+
$memoryUsageProvider->expects($this->any())->method('getMemoryUsage')->willReturn($currentMemoryUsage);
50+
51+
$memoryManager = new MemoryConsumptionChecker($memoryUsageProvider);
52+
53+
$this->assertFalse($memoryManager->isRamAlmostOverloaded($maxConsumptionAllowed));
54+
}
55+
56+
public function testMemoryExactValueIsAlmostOverloaded()
57+
{
58+
$currentMemoryUsage = '11M';
59+
$maxConsumptionAllowed = '10M';
60+
61+
$memoryUsageProvider = $this->getMockBuilder('OldSound\\RabbitMqBundle\\MemoryChecker\\NativeMemoryUsageProvider')->getMock();
62+
$memoryUsageProvider->expects($this->any())->method('getMemoryUsage')->willReturn($currentMemoryUsage);
63+
64+
$memoryManager = new MemoryConsumptionChecker($memoryUsageProvider);
65+
66+
$this->assertTrue($memoryManager->isRamAlmostOverloaded($maxConsumptionAllowed));
4167
}
4268
}

0 commit comments

Comments
 (0)