Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert between Message::$expire and DbalMessage::$timeToLive #396

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pkg/dbal/Client/DbalDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public function createTransportMessage(Message $message)
$transportMessage->setMessageId($message->getMessageId());
$transportMessage->setTimestamp($message->getTimestamp());
$transportMessage->setDeliveryDelay($message->getDelay());
$transportMessage->setTimeToLive($message->getExpire());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be $message->getExpire() * 1000 as clients message uses seconds where transport uses miliseconds

$transportMessage->setReplyTo($message->getReplyTo());
$transportMessage->setCorrelationId($message->getCorrelationId());
if (array_key_exists($message->getPriority(), self::$priorityMap)) {
Expand All @@ -97,6 +98,8 @@ public function createClientMessage(PsrMessage $message)
$clientMessage->setContentType($message->getHeader('content_type'));
$clientMessage->setMessageId($message->getMessageId());
$clientMessage->setTimestamp($message->getTimestamp());
$timeToLive = $message->getTimeToLive();
$clientMessage->setExpire((null === $timeToLive) ? null : (int) round($timeToLive));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be (int) round($timeToLive / 1000)

$clientMessage->setDelay($message->getDeliveryDelay());
$clientMessage->setReplyTo($message->getReplyTo());
$clientMessage->setCorrelationId($message->getCorrelationId());
Expand Down
24 changes: 22 additions & 2 deletions pkg/dbal/Tests/Client/DbalDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public function testShouldConvertTransportMessageToClientMessage()
$transportMessage->setTimestamp(1000);
$transportMessage->setPriority(2);
$transportMessage->setDeliveryDelay(12345);
$transportMessage->setTimeToLive(67890);

$driver = new DbalDriver(
$this->createPsrContextMock(),
Expand All @@ -118,11 +119,29 @@ public function testShouldConvertTransportMessageToClientMessage()
$this->assertSame('ContentType', $clientMessage->getContentType());
$this->assertSame(1000, $clientMessage->getTimestamp());
$this->assertSame(12345, $clientMessage->getDelay());

$this->assertNull($clientMessage->getExpire());
$this->assertSame(67890, $clientMessage->getExpire());
$this->assertSame(MessagePriority::NORMAL, $clientMessage->getPriority());
}

public function testShouldRoundTransportMessageTimeToLiveToNearestIntegerWhenConvertingToClientMessage()
{
$driver = new DbalDriver(
$this->createPsrContextMock(),
$this->createDummyConfig(),
$this->createDummyQueueMetaRegistry()
);

$transportMessage = new DbalMessage();

$transportMessage->setTimeToLive(1.4);
$clientMessage = $driver->createClientMessage($transportMessage);
$this->assertSame(1, $clientMessage->getExpire());

$transportMessage->setTimeToLive(1.5);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI. It is 1.5 milliseconds

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did this because the $transportMessage value can be null|int|float, but $clientMessage can only be null|int. Despite $clientMessage claiming to be in seconds, the current behavior of the DbalDriver is to not perform the conversion to milliseconds.

$clientMessage = $driver->createClientMessage($transportMessage);
$this->assertSame(2, $clientMessage->getExpire());
}

public function testShouldConvertClientMessageToTransportMessage()
{
$clientMessage = new Message();
Expand Down Expand Up @@ -163,6 +182,7 @@ public function testShouldConvertClientMessageToTransportMessage()
$this->assertSame([
'key' => 'val',
], $transportMessage->getProperties());
$this->assertSame(123, $transportMessage->getTimeToLive());
$this->assertSame('MessageId', $transportMessage->getMessageId());
$this->assertSame(1000, $transportMessage->getTimestamp());
}
Expand Down