Skip to content

Commit c4532b0

Browse files
committed
Fix negative delays with AMQP messenger transport
1 parent 5b0ce48 commit c4532b0

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/Symfony/Component/Messenger/Bridge/Amqp/Tests/Transport/ConnectionTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,36 @@ public function testItDelaysTheMessage()
501501
$connection->publish('{}', ['x-some-headers' => 'foo'], 5000);
502502
}
503503

504+
public function testItPublishesImmediatelyWithNegativeDelay()
505+
{
506+
$factory = new TestAmqpFactory(
507+
$amqpConnection = $this->createMock(\AMQPConnection::class),
508+
$amqpChannel = $this->createMock(\AMQPChannel::class),
509+
$amqpQueue = $this->createMock(\AMQPQueue::class),
510+
$amqpExchange = $this->createMock(\AMQPExchange::class)
511+
);
512+
513+
$amqpQueue->expects($this->once())->method('setName')->with('messages');
514+
$amqpQueue->expects($this->never())->method('setArguments');
515+
516+
$amqpQueue->expects($this->once())->method('declareQueue');
517+
$amqpQueue->expects($this->once())->method('bind')->with('messages');
518+
519+
$amqpExchange->expects($this->once())
520+
->method('publish')
521+
->with('{}', null, \AMQP_NOPARAM, [
522+
'headers' => [
523+
'x-some-headers' => 'foo',
524+
],
525+
'delivery_mode' => 2,
526+
'timestamp' => time(),
527+
]);
528+
529+
$connection = Connection::fromDsn('amqp://localhost', [], $factory);
530+
531+
$connection->publish('{}', ['x-some-headers' => 'foo'], -5000);
532+
}
533+
504534
public function testItRetriesTheMessage()
505535
{
506536
$delayExchange = $this->createMock(\AMQPExchange::class);

src/Symfony/Component/Messenger/Bridge/Amqp/Transport/Connection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ public function publish(string $body, array $headers = [], int $delayInMs = 0, ?
289289
}
290290

291291
$this->withConnectionExceptionRetry(function () use ($body, $headers, $delayInMs, $amqpStamp) {
292-
if (0 !== $delayInMs) {
292+
if (0 < $delayInMs) {
293293
$this->publishWithDelay($body, $headers, $delayInMs, $amqpStamp);
294294

295295
return;

0 commit comments

Comments
 (0)