Skip to content

Commit 656f786

Browse files
bug #60759 [Messenger] Fix float value for worker memory limit (ro0NL)
This PR was squashed before being merged into the 6.4 branch. Discussion ---------- [Messenger] Fix float value for worker memory limit | Q | A | ------------- | --- | Branch? | 6.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #60752 | License | MIT Commits ------- 451926b [Messenger] Fix float value for worker memory limit
2 parents 333978b + 451926b commit 656f786

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

src/Symfony/Component/Messenger/Command/ConsumeMessagesCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ private function convertToBytes(string $memoryLimit): int
289289
} elseif (str_starts_with($max, '0')) {
290290
$max = \intval($max, 8);
291291
} else {
292-
$max = (int) $max;
292+
$max = (float) $max;
293293
}
294294

295295
switch (substr(rtrim($memoryLimit, 'b'), -1)) {
@@ -302,6 +302,6 @@ private function convertToBytes(string $memoryLimit): int
302302
case 'k': $max *= 1024;
303303
}
304304

305-
return $max;
305+
return (int) $max;
306306
}
307307
}

src/Symfony/Component/Messenger/Tests/Command/ConsumeMessagesCommandTest.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
namespace Symfony\Component\Messenger\Tests\Command;
1313

1414
use PHPUnit\Framework\TestCase;
15+
use Psr\Log\LoggerInterface;
16+
use Psr\Log\LoggerTrait;
1517
use Symfony\Component\Console\Application;
1618
use Symfony\Component\Console\Exception\InvalidOptionException;
1719
use Symfony\Component\Console\Tester\CommandCompletionTester;
@@ -214,6 +216,50 @@ public function testRunWithTimeLimit()
214216
$this->assertStringContainsString('[OK] Consuming messages from transport "dummy-receiver"', $tester->getDisplay());
215217
}
216218

219+
public function testRunWithMemoryLimit()
220+
{
221+
$envelope = new Envelope(new \stdClass(), [new BusNameStamp('dummy-bus')]);
222+
223+
$receiver = $this->createMock(ReceiverInterface::class);
224+
$receiver->method('get')->willReturn([$envelope]);
225+
226+
$receiverLocator = $this->createMock(ContainerInterface::class);
227+
$receiverLocator->method('has')->with('dummy-receiver')->willReturn(true);
228+
$receiverLocator->method('get')->with('dummy-receiver')->willReturn($receiver);
229+
230+
$bus = $this->createMock(MessageBusInterface::class);
231+
232+
$busLocator = $this->createMock(ContainerInterface::class);
233+
$busLocator->method('has')->with('dummy-bus')->willReturn(true);
234+
$busLocator->method('get')->with('dummy-bus')->willReturn($bus);
235+
236+
$logger = new class() implements LoggerInterface {
237+
use LoggerTrait;
238+
239+
public array $logs = [];
240+
241+
public function log(...$args): void
242+
{
243+
$this->logs[] = $args;
244+
}
245+
};
246+
$command = new ConsumeMessagesCommand(new RoutableMessageBus($busLocator), $receiverLocator, new EventDispatcher(), $logger);
247+
248+
$application = new Application();
249+
$application->add($command);
250+
$tester = new CommandTester($application->get('messenger:consume'));
251+
$tester->execute([
252+
'receivers' => ['dummy-receiver'],
253+
'--memory-limit' => '1.5M',
254+
]);
255+
256+
$this->assertSame(0, $tester->getStatusCode());
257+
$this->assertStringContainsString('[OK] Consuming messages from transport "dummy-receiver"', $tester->getDisplay());
258+
$this->assertStringContainsString('The worker will automatically exit once it has exceeded 1.5M of memory', $tester->getDisplay());
259+
260+
$this->assertSame(1572864, $logger->logs[1][2]['limit']);
261+
}
262+
217263
/**
218264
* @dataProvider provideCompletionSuggestions
219265
*/

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy